rollup-plugin-node-globals
DefinitelyTyped icon, indicating that this package has TypeScript declarations provided by the separate @types/rollup-plugin-node-globals package

1.4.0 • Public • Published

rollup-plugin-node-globals

Plugin to insert node globals including so code that works with browserify should work even if it uses process or buffers. This is based on rollup-plugin-inject .

  • process
  • global
  • Buffer
  • __dirname
  • __filename

Plus process.nextTick and process.browser are optimized to only pull in themselves and __dirname and __filename point to the file on disk

There are a few options to control output

  • process - pass false to disable process polyfilling
  • global - pass false to disable global polyfilling
  • buffer - pass false to disable Buffer polyfilling
  • dirname - pass false to disable __dirname polyfilling
  • filename - pass false to disable __filename polyfilling
  • baseDir which is used for resolving __dirname and __filename.

examples

var foo;
if (process.browser) {
  foo = 'bar';
} else {
  foo = 'baz';
}

turns into

import {browser} from 'path/to/process';
var foo;
if (browser) {
  foo = 'bar';
} else {
  foo = 'baz';
}

but with rollup that ends up being

var browser = true;
var foo;
if (browser) {
  foo = 'bar';
} else {
  foo = 'baz';
}

or

var timeout;
if (global.setImmediate) {
  timeout = global.setImmediate;
} else {
  timeout = global.setTimeout;
}
export default timeout;

turns into

import {_global} from 'path/to/global.js';
var timeout;
if (_global.setImmediate) {
  timeout = _global.setImmediate;
} else {
  timeout = _global.setTimeout;
}
export default timeout;
 

which rollup turns into

var _global = typeof global !== "undefined" ? global :
            typeof self !== "undefined" ? self :
            typeof window !== "undefined" ? window : {}
 
var timeout;
if (_global.setImmediate) {
  timeout = _global.setImmediate;
} else {
  timeout = _global.setTimeout;
}
var timeout$1 = timeout;
 
export default timeout$1;

With that top piece only showing up once no matter how many times global was used.

Versions

Current Tags

VersionDownloads (Last 7 Days)Tag
1.4.058,572latest

Version History

VersionDownloads (Last 7 Days)Published
1.4.058,572
1.3.01,136
1.2.1935
1.2.01,548
1.1.04,201
1.0.918
1.0.80
1.0.70
1.0.686
1.0.50
1.0.40
1.0.30
1.0.20
1.0.10
1.0.00

Package Sidebar

Install

npm i rollup-plugin-node-globals

Weekly Downloads

66,496

Version

1.4.0

License

MIT

Unpacked Size

29.6 kB

Total Files

9

Last publish

Collaborators

  • cwmma