rollup-globals-regex

raw JSON →
0.0.3 verified Mon Apr 27 auth: no javascript

A Rollup plugin utility to define globals using RegExp patterns, reducing boilerplate for Angular, RxJS, and other scoped packages. Versions 0.0.x, no recent releases, single maintainer. Converts simple globals object from explicit mappings to regex-based pattern matching with optional transformers like kebab-to-camelCase. Ships TypeScript definitions. Not actively maintained but stable for basic usage.

error Cannot find module 'rollup-globals-regex'
cause Package not installed or npm install failed.
fix
npm install rollup-globals-regex --save-dev
error Module 'rollup-globals-regex' has no exported member 'GLOBAL'
cause Using incorrect import path or TypeScript version mismatch.
fix
Ensure import is correct: import { GLOBAL } from 'rollup-globals-regex'. If using TS <3.8, use import GLOBAL = require('rollup-globals-regex').GLOBAL
error TypeError: globalsRegex is not a function
cause CommonJS require used incorrectly; package is ESM only.
fix
Use ES module import: import { globalsRegex } from 'rollup-globals-regex' or if using CommonJS, try dynamic import: const { globalsRegex } = await import('rollup-globals-regex')
error The requested module 'rollup-globals-regex' does not provide an export named 'GLOBAL' (in Node ESM)
cause Node.js ESM requires explicit .mjs extension or package.json 'type':'module'.
fix
Add 'type':'module' to your package.json or rename file to .mjs. Alternatively use --experimental-modules flag.
deprecated Package is not actively maintained; last release 6+ years ago. Consider alternatives like @rollup/plugin-commonjs or custom globals functions.
fix Migrate to manual globals mapping or use Rollup's built-in globals option with a function.
gotcha GLOBAL.NG2.TPL applies kebab-to-camelCase transformer; ensure your Angular package names use kebab-case (e.g., '@angular/platform-browser').
fix Double-check transformer behavior or define custom regex patterns without transformers.
gotcha Using computed property keys with GLOBAL symbols may cause TypeScript errors if no index signature is defined; cast to 'any' if needed.
fix // @ts-ignore or (globalsRegex as any)({ ... })
gotcha The package does not export types for GLOBAL properly; TypeScript users may need to declare module augmentations.
fix Install @types/rollup-globals-regex manually (if available) or declare module 'rollup-globals-regex' { ... } in a .d.ts file.
npm install rollup-globals-regex
yarn add rollup-globals-regex
pnpm add rollup-globals-regex

Shows how to configure Rollup globals using regex patterns for Angular and RxJS packages.

import { globalsRegex, GLOBAL } from 'rollup-globals-regex';

export default {
  input: 'src/index.js',
  output: {
    file: 'dist/bundle.js',
    format: 'iife',
    name: 'MyBundle',
    globals: globalsRegex({
      'jquery': '$',
      'lodash': '_',
      [GLOBAL.NG2]: GLOBAL.NG2.TPL,
      [GLOBAL.RX]: GLOBAL.RX.TPL,
    })
  },
  external: ['jquery', 'lodash', '@angular/core', '@angular/common', 'rxjs']
};