# rollup-plugin-node-globals

> insert the same globals browserify does

Latest version **1.4.0** (published 2018-09-11) · MIT license · 0 weekly downloads

## Install

```sh
npm install rollup-plugin-node-globals
pnpm add rollup-plugin-node-globals
yarn add rollup-plugin-node-globals
bun add rollup-plugin-node-globals
```

## Health

**Score 23/100 (F)** — status: abandoned.

Positive: has types package; no vulnerabilities; high quality score.

Warnings: low downloads; no esm support.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 1.4.0 |
| Published | 2018-09-11 |
| First published | 2016-03-10 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | separate (@types/rollup-plugin-node-globals) |
| Module format | CommonJS |
| Dependencies | 6 |
| Unpacked size | 28.9 KB |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 91 |
| Author | Calvin Metcalf |
| Maintainers | cwmma |
| Keywords | rollup-plugin |

## Links

- npm: https://www.npmjs.com/package/rollup-plugin-node-globals
- Repository: https://github.com/calvinmetcalf/rollup-plugin-node-globals
- Homepage: https://github.com/calvinmetcalf/rollup-plugin-node-globals#readme
- Issues: https://github.com/calvinmetcalf/rollup-plugin-node-globals/issues
- npm.io page: https://npm.io/package/rollup-plugin-node-globals

## Dependencies (6)

- [acorn](https://npm.io/package/acorn.md) ^5.7.3
- [buffer-es6](https://npm.io/package/buffer-es6.md) ^4.9.3
- [process-es6](https://npm.io/package/process-es6.md) ^0.11.6
- [magic-string](https://npm.io/package/magic-string.md) ^0.22.5
- [estree-walker](https://npm.io/package/estree-walker.md) ^0.5.2
- [rollup-pluginutils](https://npm.io/package/rollup-pluginutils.md) ^2.3.1

## Alternatives

- [raw-loader](https://npm.io/package/raw-loader.md) — 4.3M weekly downloads
- [plop](https://npm.io/package/plop.md) — 1.4M weekly downloads
- [webpack-deadcode-plugin](https://npm.io/package/webpack-deadcode-plugin.md) — 80.3K weekly downloads
- [@storybook/preact-vite](https://npm.io/package/@storybook/preact-vite.md) — 54.2K weekly downloads
- [vite-plugin-transform](https://npm.io/package/vite-plugin-transform.md) — 2.4K weekly downloads

## Recent versions

- 1.4.0 (latest) — 2018-09-11
- 1.3.0 — 2018-09-04
- 1.2.1 — 2018-05-07
- 1.2.0 — 2018-03-13
- 1.1.0 — 2016-11-16
- 1.0.9 — 2016-09-22
- 1.0.8 — 2016-09-19
- 1.0.7 — 2016-09-08
- 1.0.6 — 2016-07-27
- 1.0.5 — 2016-03-17
- 1.0.4 — 2016-03-14
- 1.0.3 — 2016-03-10
- 1.0.2 — 2016-03-10
- 1.0.1 — 2016-03-10
- 1.0.0 — 2016-03-10

## 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 is based on [rollup-plugin-inject
](https://github.com/rollup/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

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

turns into

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

but with rollup that ends up being

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

or

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

turns into

```js
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

```js
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.

---
_Source: https://npm.io/package/rollup-plugin-node-globals · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
