Gathering detailed insights and metrics for @zacharygriffee/rollup-plugin-external-globals
Gathering detailed insights and metrics for @zacharygriffee/rollup-plugin-external-globals
Gathering detailed insights and metrics for @zacharygriffee/rollup-plugin-external-globals
Gathering detailed insights and metrics for @zacharygriffee/rollup-plugin-external-globals
npm install @zacharygriffee/rollup-plugin-external-globals
Typescript
Module System
Node Version
NPM Version
54.1
Supply Chain
97.3
Quality
78.5
Maintenance
100
Vulnerability
99.6
License
Total Downloads
1,169
Last Day
1
Last Week
1
Last Month
16
Last Year
1,169
Latest Version
0.0.6
Package Id
@zacharygriffee/rollup-plugin-external-globals@0.0.6
Unpacked Size
28.20 kB
Size
9.12 kB
File Count
8
NPM Version
8.19.4
Node Version
16.20.2
Publised On
15 Jan 2024
Cumulative downloads
Total Downloads
Last day
-66.7%
1
Compared to previous day
Last week
-85.7%
1
Compared to previous week
Last month
-11.1%
16
Compared to previous month
Last year
0%
1,169
Compared to previous year
1
4
rollup-plugin-external-globals
.npm install -D @zacharygriffee/rollup-plugin-external-globals
1import { externalGlobals } from "@zacharygriffee/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.
This module exports a single function.
1const plugin = externalGlobals( 2 globals 3: 4Object | Function, 5 { 6 include? : Array, 7 exclude? : Array, 8 dynamicWrapper? : Function 9 } = {} 10) 11;
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 an array of glob patterns. If defined, only matched files would be transformed.
exclude
is an array of glob 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.
0.9.1 (Nov 19, 2023)
0.9.0 (Oct 28, 2023)
0.8.0 (May 12, 2023)
0.7.2 (mar 9, 2023)
0.7.0 (Nov 21, 2022)
0.6.1 (Oct 21, 2020)
0.6.0 (Aug 14, 2020)
0.5.0 (Dec 8, 2019)
dynamicWrapper
option.globals
can be a function.0.4.0 (Sep 24, 2019)
import("foo")
=> Promise.resolve(FOO)
.0.3.1 (Jun 6, 2019)
0.3.0 (Mar 25, 2019)
0.2.1 (Oct 2, 2018)
0.2.0 (Sep 12, 2018)
transform
hook.0.1.0 (Aug 5, 2018)
No vulnerabilities found.
No security vulnerabilities found.