{"id":13563016,"url":"https://github.com/eight04/rollup-plugin-external-globals","last_synced_at":"2025-04-05T22:09:15.635Z","repository":{"id":39674201,"uuid":"143599502","full_name":"eight04/rollup-plugin-external-globals","owner":"eight04","description":"Transform external imports into global variables like output.globals.","archived":false,"fork":false,"pushed_at":"2024-04-05T05:42:58.000Z","size":271,"stargazers_count":93,"open_issues_count":3,"forks_count":15,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-05-10T07:02:07.221Z","etag":null,"topics":["rollup","rollup-plugin"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/eight04.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2018-08-05T09:24:57.000Z","updated_at":"2024-06-18T13:44:21.572Z","dependencies_parsed_at":"2024-01-13T11:57:53.075Z","dependency_job_id":"25b38974-88f4-42b4-a6be-1e093b24510f","html_url":"https://github.com/eight04/rollup-plugin-external-globals","commit_stats":{"total_commits":48,"total_committers":3,"mean_commits":16.0,"dds":0.04166666666666663,"last_synced_commit":"e9219b2f247d3360504e8c10055e789108e2b3c4"},"previous_names":[],"tags_count":18,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eight04%2Frollup-plugin-external-globals","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eight04%2Frollup-plugin-external-globals/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eight04%2Frollup-plugin-external-globals/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/eight04%2Frollup-plugin-external-globals/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/eight04","download_url":"https://codeload.github.com/eight04/rollup-plugin-external-globals/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247406091,"owners_count":20933803,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["rollup","rollup-plugin"],"created_at":"2024-08-01T13:01:14.328Z","updated_at":"2025-04-05T22:09:15.613Z","avatar_url":"https://github.com/eight04.png","language":"JavaScript","funding_links":[],"categories":["JavaScript","Plugins"],"sub_categories":["Modules"],"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($ =\u003e {\n    $ = $.default || $;\n    console.log($(\".test\"));\n  });\n\n// transformed\nPromise.resolve($)\n  .then($ =\u003e {\n    $ = $.default || $;\n    console.log($(\".test\"));\n  });\n```\n\n\u003e **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\u003e **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\u003cstring | RegExp\u003e | string | RegExp | null,\n    exclude?: ReadonlyArray\u003cstring | RegExp\u003e | 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) =\u003e {\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) =\u003e {\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\")` =\u003e `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","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feight04%2Frollup-plugin-external-globals","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Feight04%2Frollup-plugin-external-globals","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Feight04%2Frollup-plugin-external-globals/lists"}