Package Exports
- rollup-plugin-node-globals
- rollup-plugin-node-globals/dist/buffer
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (rollup-plugin-node-globals) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
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 not only uses rollup-plugin-inject but bases itself on that as well.
- 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
Only option beyond the default plugin ones is an optional 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.