{"name":"rollup-plugin-external-globals","version":"0.12.1","keywords":["rollup-plugin","es","transform","external","globals"],"author":{"name":"eight04","email":"eight04@gmail.com"},"license":"MIT","_id":"rollup-plugin-external-globals@0.12.1","maintainers":[{"name":"eight04","email":"eight04@gmail.com"}],"homepage":"https://github.com/eight04/rollup-plugin-external-globals#readme","bugs":{"url":"https://github.com/eight04/rollup-plugin-external-globals/issues"},"dist":{"shasum":"4887f20bdfa1ce4c3ce1206443a7a02b508643be","tarball":"http://registry-npm.ywwl.com/rollup-plugin-external-globals/download/rollup-plugin-external-globals-0.12.1.tgz","fileCount":6,"integrity":"sha512-v+63p8mSbGzDoZgK8QJmxkGvktEvBtSlPbrkRvxCKeVahiyMAa0gYjh/tzXGfOpA244rFUF1XYkAuk/Ta2dp7A==","signatures":[{"sig":"MEYCIQCo1/Q1D9xc8Df3RvgvtEbBgtD2iL1OUqaIKUf+qAHLRgIhAN92kUoMI+MtFXQlrsb2umoEzcYaOBHHh3XHJeJf/vzi","keyid":"SHA256:jl3bwswu80PjjokCgh0o2w5c2U4LhQAE57gj9cz1kzA"}],"unpackedSize":17485,"size":5933,"noattachment":false,"key":"/rollup-plugin-external-globals/-/rollup-plugin-external-globals-0.12.1.tgz"},"main":"index.js","exports":{".":{"types":"./index.d.ts","default":"./index.js"}},"gitHead":"beacc81e254d5bdef08931f23dc634e17458ad6a","scripts":{"test":"eslint . --cache && c8 --reporter lcov mocha","preversion":"npm test","postversion":"git push --follow-tags && npm publish"},"typings":"index.d.ts","_npmUser":{"name":"eight04","email":"eight04@gmail.com"},"repository":{"url":"git+https://github.com/eight04/rollup-plugin-external-globals.git","type":"git"},"_npmVersion":"10.9.0","description":"Transform external imports into global variables like output.globals.","directories":{},"_nodeVersion":"22.9.0","dependencies":{"is-reference":"^3.0.2","magic-string":"^0.30.10","estree-walker":"^3.0.3","@rollup/pluginutils":"^5.1.0"},"eslintIgnore":["coverage"],"_hasShrinkwrap":false,"devDependencies":{"c8":"^10.1.2","mocha":"^10.5.2","endent":"^2.1.0","eslint":"^9.5.0","rollup":"^4.18.0","globals":"^15.9.0","rollup2":"npm:rollup@^2.79.2","@eslint/js":"^9.9.0","tempdir-yaml":"^0.3.0","@rollup/plugin-commonjs":"^28.0.1"},"peerDependencies":{"rollup":"^2.25.0 || ^3.3.0 || ^4.1.4"},"_npmOperationalInternal":{"tmp":"tmp/rollup-plugin-external-globals_0.12.1_1731686406538_0.9886173631869395","host":"s3://npm-registry-packages"},"readme":"rollup-plugin-external-globals\n==============================\n\n[![test](https://github.com/eight04/rollup-plugin-external-globals/actions/workflows/test.yml/badge.svg)](https://github.com/eight04/rollup-plugin-external-globals/actions/workflows/test.yml)\n[![codecov](https://codecov.io/gh/eight04/rollup-plugin-external-globals/branch/master/graph/badge.svg)](https://codecov.io/gh/eight04/rollup-plugin-external-globals)\n[![install size](https://packagephobia.now.sh/badge?p=rollup-plugin-external-globals)](https://packagephobia.now.sh/result?p=rollup-plugin-external-globals)\n\nTransform external imports into global variables like Rollup's `output.globals` option. See [rollup/rollup#2374](https://github.com/rollup/rollup/issues/2374)\n\nInstallation\n------------\n\n```\nnpm install -D rollup-plugin-external-globals\n```\n\nUsage\n-----\n\n```js\nimport externalGlobals from \"rollup-plugin-external-globals\";\n\nexport default {\n  input: [\"entry.js\"],\n  output: {\n    dir: \"dist\",\n    format: \"es\"\n  },\n  plugins: [\n    externalGlobals({\n      jquery: \"$\"\n    })\n  ]\n};\n```\n\nThe above config transforms\n\n```js\nimport jq from \"jquery\";\n\nconsole.log(jq(\".test\"));\n```\n\ninto\n\n```js\nconsole.log($(\".test\"));\n```\n\nIt also transforms dynamic import:\n\n```js\nimport(\"jquery\")\n  .then($ => {\n    $ = $.default || $;\n    console.log($(\".test\"));\n  });\n\n// transformed\nPromise.resolve($)\n  .then($ => {\n    $ = $.default || $;\n    console.log($(\".test\"));\n  });\n```\n\n> **Note:** when using dynamic import, you should notice that in ES module, the resolved object is aways a module namespace, but the global variable might be not.\n\n> **Note:** this plugin only works with import/export syntax. If you are using a module loader transformer e.g. `rollup-plugin-commonjs`, you have to put this plugin *after* the transformer plugin.\n\nAPI\n----\n\nThis module exports a single function.\n\n### createPlugin\n\n```js\nconst plugin = createPlugin(\n  globals: Object | Function,\n  {\n    include?: ReadonlyArray<string | RegExp> | string | RegExp | null,\n    exclude?: ReadonlyArray<string | RegExp> | string | RegExp | null,\n    dynamicWrapper?: Function,\n    constBindings?: Boolean\n  } = {}\n);\n```\n\n`globals` is a `moduleId`/`variableName` map. For example, to map `jquery` module to `$`:\n\n```js\nconst globals = {\n  jquery: \"$\"\n}\n```\n\nor provide a function that takes the `moduleId` and returns the `variableName`.\n\n```js\nconst globals = (id) => {\n  if (id === \"jquery\") {\n    return \"$\";\n  }\n}\n```\n\n`include` is a valid `picomatch` glob pattern, or array of patterns. If defined, only matched files would be transformed.\n\n`exclude` is a valid `picomatch` glob pattern, or array of patterns. Matched files would not be transformed.\n\n`dynamicWrapper` is used to specify dynamic imports. Below is the default.\n\n```js\nconst dynamicWrapper = (id) => {\n  return `Promise.resolve(${id})`;\n}\n```\n\nVirtual modules are always transformed.\n\n`constBindings` is a boolean. If true, the plugin will use `const` instead of `var` to declare the variable. This usually happens when you try to re-export the global variable. Default is false.\n\nChangelog\n---------\n\n* 0.13.0 (Nov 20, 2024)\n\n  - Change: update include/exclude signature\n\n* 0.12.1 (Nov 15, 2024)\n\n  - Fix: there is no debug hook in rollup 2.\n\n* 0.12.0 (Aug 11, 2024)\n\n  - Change: throw on export all declaration.\n  - Change: define variables with `var`, add `constBindings` option to use `const` instead.\n  - Change: resolve identifiers as external.\n\n* 0.11.0 (Jun 27, 2024)\n\n  - Fix: local variable conflict in export declaration.\n  - Change: don't throw on parse error.\n\n* 0.10.0 (Apr 5, 2024)\n\n  - Add: `exports` field in package.json to export typescript declaration.\n\n* 0.9.2 (Jan 21, 2024)\n\n  - Fix: support rollup 4.9.6.\n\n* 0.9.1 (Nov 19, 2023)\n\n  - Fix: type declaration.\n\n* 0.9.0 (Oct 28, 2023)\n\n  - **Breaking: bump to rollup@4.**\n\n* 0.8.0 (May 12, 2023)\n\n  - Bump dependencies. Update to magic-string@0.30\n\n* 0.7.2 (mar 9, 2023)\n\n  - Add: typescript declaration.\n\n* 0.7.0 (Nov 21, 2022)\n\n  - **Breaking: bump to rollup@3.**\n\n* 0.6.1 (Oct 21, 2020)\n\n  - Fix: add an extra assignment when exporting globals.\n\n* 0.6.0 (Aug 14, 2020)\n\n  - **Breaking: bump to rollup@2.**\n\n* 0.5.0 (Dec 8, 2019)\n\n  - Add: `dynamicWrapper` option.\n  - Add: now `globals` can be a function.\n  - Bump dependencies/peer dependencies.\n\n* 0.4.0 (Sep 24, 2019)\n\n  - Add: transform dynamic imports i.e. `import(\"foo\")` => `Promise.resolve(FOO)`.\n\n* 0.3.1 (Jun 6, 2019)\n\n  - Fix: all export-from statements are incorrectly transformed.\n  - Bump dependencies.\n\n* 0.3.0 (Mar 25, 2019)\n\n  - Fix: temporary variable name conflicts.\n  - **Breaking: transform virtual modules.** Now the plugin transforms proxy modules generated by commonjs plugin.\n  - Bump dependencies.\n\n* 0.2.1 (Oct 2, 2018)\n\n  - Fix: don't skip export statement.\n\n* 0.2.0 (Sep 12, 2018)\n\n  - Change: use `transform` hook.\n  - Add: rewrite conflicted variable names.\n  - Add: handle export from.\n\n* 0.1.0 (Aug 5, 2018)\n\n  - Initial release.\n","publish_time":1731686406724,"_cnpm_publish_time":1731686406724,"dist-tags":{"latest":"0.13.0"}}