Installations
npm install rollup-plugin-external-globals
Developer Guide
Typescript
No
Module System
CommonJS, ESM
Node Version
22.9.0
NPM Version
10.9.0
Score
52.4
Supply Chain
98.5
Quality
83.9
Maintenance
100
Vulnerability
99.6
License
Releases
Unable to fetch releases
Contributors
Unable to fetch Contributors
Languages
JavaScript (100%)
Developer
eight04
Download Statistics
Total Downloads
3,694,515
Last Day
1,518
Last Week
20,138
Last Month
123,075
Last Year
1,317,165
GitHub Statistics
108 Stars
82 Commits
22 Forks
3 Watching
1 Branches
8 Contributors
Package Meta Information
Latest Version
0.13.0
Package Id
rollup-plugin-external-globals@0.13.0
Unpacked Size
17.41 kB
Size
5.88 kB
File Count
6
NPM Version
10.9.0
Node Version
22.9.0
Publised On
20 Nov 2024
Total Downloads
Cumulative downloads
Total Downloads
3,694,515
Last day
-72.6%
1,518
Compared to previous day
Last week
-33.4%
20,138
Compared to previous week
Last month
-9.9%
123,075
Compared to previous month
Last year
10.9%
1,317,165
Compared to previous year
Daily Downloads
Weekly Downloads
Monthly Downloads
Yearly Downloads
Peer Dependencies
1
rollup-plugin-external-globals
Transform external imports into global variables like Rollup's output.globals
option. See rollup/rollup#2374
Installation
npm install -D rollup-plugin-external-globals
Usage
1import externalGlobals from "rollup-plugin-external-globals"; 2 3export default { 4 input: ["entry.js"], 5 output: { 6 dir: "dist", 7 format: "es" 8 }, 9 plugins: [ 10 externalGlobals({ 11 jquery: "$" 12 }) 13 ] 14};
The above config transforms
1import jq from "jquery"; 2 3console.log(jq(".test"));
into
1console.log($(".test"));
It also transforms dynamic import:
1import("jquery") 2 .then($ => { 3 $ = $.default || $; 4 console.log($(".test")); 5 }); 6 7// transformed 8Promise.resolve($) 9 .then($ => { 10 $ = $.default || $; 11 console.log($(".test")); 12 });
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.
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.
API
This module exports a single function.
createPlugin
1const plugin = createPlugin( 2 globals: Object | Function, 3 { 4 include?: ReadonlyArray<string | RegExp> | string | RegExp | null, 5 exclude?: ReadonlyArray<string | RegExp> | string | RegExp | null, 6 dynamicWrapper?: Function, 7 constBindings?: Boolean 8 } = {} 9);
globals
is a moduleId
/variableName
map. For example, to map jquery
module to $
:
1const globals = { 2 jquery: "$" 3}
or provide a function that takes the moduleId
and returns the variableName
.
1const globals = (id) => { 2 if (id === "jquery") { 3 return "$"; 4 } 5}
include
is a valid picomatch
glob pattern, or array of patterns. If defined, only matched files would be transformed.
exclude
is a valid picomatch
glob pattern, or array of patterns. Matched files would not be transformed.
dynamicWrapper
is used to specify dynamic imports. Below is the default.
1const dynamicWrapper = (id) => { 2 return `Promise.resolve(${id})`; 3}
Virtual modules are always transformed.
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.
Changelog
-
0.13.0 (Nov 20, 2024)
- Change: update include/exclude signature
-
0.12.1 (Nov 15, 2024)
- Fix: there is no debug hook in rollup 2.
-
0.12.0 (Aug 11, 2024)
- Change: throw on export all declaration.
- Change: define variables with
var
, addconstBindings
option to useconst
instead. - Change: resolve identifiers as external.
-
0.11.0 (Jun 27, 2024)
- Fix: local variable conflict in export declaration.
- Change: don't throw on parse error.
-
0.10.0 (Apr 5, 2024)
- Add:
exports
field in package.json to export typescript declaration.
- Add:
-
0.9.2 (Jan 21, 2024)
- Fix: support rollup 4.9.6.
-
0.9.1 (Nov 19, 2023)
- Fix: type declaration.
-
0.9.0 (Oct 28, 2023)
- Breaking: bump to rollup@4.
-
0.8.0 (May 12, 2023)
- Bump dependencies. Update to magic-string@0.30
-
0.7.2 (mar 9, 2023)
- Add: typescript declaration.
-
0.7.0 (Nov 21, 2022)
- Breaking: bump to rollup@3.
-
0.6.1 (Oct 21, 2020)
- Fix: add an extra assignment when exporting globals.
-
0.6.0 (Aug 14, 2020)
- Breaking: bump to rollup@2.
-
0.5.0 (Dec 8, 2019)
- Add:
dynamicWrapper
option. - Add: now
globals
can be a function. - Bump dependencies/peer dependencies.
- Add:
-
0.4.0 (Sep 24, 2019)
- Add: transform dynamic imports i.e.
import("foo")
=>Promise.resolve(FOO)
.
- Add: transform dynamic imports i.e.
-
0.3.1 (Jun 6, 2019)
- Fix: all export-from statements are incorrectly transformed.
- Bump dependencies.
-
0.3.0 (Mar 25, 2019)
- Fix: temporary variable name conflicts.
- Breaking: transform virtual modules. Now the plugin transforms proxy modules generated by commonjs plugin.
- Bump dependencies.
-
0.2.1 (Oct 2, 2018)
- Fix: don't skip export statement.
-
0.2.0 (Sep 12, 2018)
- Change: use
transform
hook. - Add: rewrite conflicted variable names.
- Add: handle export from.
- Change: use
-
0.1.0 (Aug 5, 2018)
- Initial release.
No vulnerabilities found.
Reason
no binaries found in the repo
Reason
no dangerous workflow patterns detected
Reason
license file detected
Details
- Info: project has a license file: LICENSE:0
- Info: FSF or OSI recognized license: MIT License: LICENSE:0
Reason
0 existing vulnerabilities detected
Reason
6 commit(s) and 1 issue activity found in the last 90 days -- score normalized to 5
Reason
dependency not pinned by hash detected -- score normalized to 4
Details
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:9: update your workflow using https://app.stepsecurity.io/secureworkflow/eight04/rollup-plugin-external-globals/test.yml/master?enable=pin
- Warn: GitHub-owned GitHubAction not pinned by hash: .github/workflows/test.yml:10: update your workflow using https://app.stepsecurity.io/secureworkflow/eight04/rollup-plugin-external-globals/test.yml/master?enable=pin
- Warn: third-party GitHubAction not pinned by hash: .github/workflows/test.yml:15: update your workflow using https://app.stepsecurity.io/secureworkflow/eight04/rollup-plugin-external-globals/test.yml/master?enable=pin
- Info: 0 out of 2 GitHub-owned GitHubAction dependencies pinned
- Info: 0 out of 1 third-party GitHubAction dependencies pinned
- Info: 1 out of 1 npmCommand dependencies pinned
Reason
Found 5/30 approved changesets -- score normalized to 1
Reason
detected GitHub workflow tokens with excessive permissions
Details
- Warn: no topLevel permission defined: .github/workflows/test.yml:1
- Info: no jobLevel write permissions found
Reason
no effort to earn an OpenSSF best practices badge detected
Reason
security policy file not detected
Details
- Warn: no security policy file detected
- Warn: no security file to analyze
- Warn: no security file to analyze
- Warn: no security file to analyze
Reason
project is not fuzzed
Details
- Warn: no fuzzer integrations found
Reason
branch protection not enabled on development/release branches
Details
- Warn: branch protection not enabled for branch 'master'
Reason
SAST tool is not run on all commits -- score normalized to 0
Details
- Warn: 0 commits out of 10 are checked with a SAST tool
Score
4.2
/10
Last Scanned on 2024-12-23
The Open Source Security Foundation is a cross-industry collaboration to improve the security of open source software (OSS). The Scorecard provides security health metrics for open source projects.
Learn More