1 | rollup-plugin-node-builtins
|
2 | ===
|
3 |
|
4 | ```
|
5 | npm install --save-dev rollup-plugin-node-builtins
|
6 | ```
|
7 |
|
8 | Allows the node builtins to be `require`d/`import`ed. Doing so gives the proper shims to support modules that were designed for Browserify, some modules require [rollup-plugin-node-globals](https://github.com/calvinmetcalf/rollup-plugin-node-globals).
|
9 |
|
10 | The following modules include ES6 specific version which allow you to do named imports in addition to the default import and should work fine if you only use this plugin.
|
11 |
|
12 | - process*
|
13 | - events
|
14 | - stream*
|
15 | - util*
|
16 | - path
|
17 | - buffer*
|
18 | - querystring
|
19 | - url*
|
20 | - string_decoder*
|
21 | - punycode
|
22 | - http*†
|
23 | - https*†
|
24 | - os*
|
25 | - assert*
|
26 | - constants
|
27 | - timers*
|
28 | - console*‡
|
29 | - vm*§
|
30 | - zlib*
|
31 | - tty
|
32 | - domain
|
33 | - dns∆
|
34 | - dgram∆
|
35 | - child_process∆
|
36 | - cluster∆
|
37 | - module∆
|
38 | - net∆
|
39 | - readline∆
|
40 | - repl∆
|
41 | - tls∆
|
42 | - fs˚
|
43 | - crypto˚
|
44 |
|
45 | \* requires [node-globals plugin](https://github.com/calvinmetcalf/rollup-plugin-node-globals)
|
46 |
|
47 | † the http and https modules are actually the same and don't differentiate based on protocol
|
48 |
|
49 | ‡ default export only, because it's console, seriously just use the global
|
50 |
|
51 | § vm does not have all corner cases and has less of them in a web worker
|
52 |
|
53 | ∆ not shimmed, just returns mock
|
54 |
|
55 | ˚ optional, add option to enable browserified shim
|
56 |
|
57 | Crypto is not shimmed and and we just provide the commonjs one from browserify and it will likely not work, if you really want it please pass `{crypto: true}` as an option.
|
58 |
|
59 |
|
60 |
|
61 | Not all included modules rollup equally, streams (and by extension anything that requires it like http) are a mess of circular references that are pretty much impossible to tree-shake out, similarly url methods are actually a shortcut to a url object so those methods don't tree shake out very well, punycode, path, querystring, events, util, and process tree shake very well especially if you do named imports.
|
62 |
|
63 | config for using this with something simple like events or querystring
|
64 |
|
65 | ```js
|
66 | import builtins from 'rollup-plugin-node-builtins';
|
67 | rollup({
|
68 | entry: 'main.js',
|
69 | plugins: [
|
70 | builtins()
|
71 | ]
|
72 | })
|
73 | ```
|
74 |
|
75 | and now if main contains this, it should just work
|
76 |
|
77 | ```js
|
78 | import EventEmitter from 'events';
|
79 | import {inherits} from 'util';
|
80 |
|
81 | // etc
|
82 | ```
|
83 |
|
84 | Config for something more complicated like http
|
85 |
|
86 | ```js
|
87 | import builtins from 'rollup-plugin-node-builtins';
|
88 | import globals from 'rollup-plugin-node-globals';
|
89 | rollup({
|
90 | entry: 'main.js',
|
91 | plugins: [
|
92 | globals(),
|
93 | builtins()
|
94 | ]
|
95 | })
|
96 | ```
|
97 |
|
98 | License
|
99 | ===
|
100 |
|
101 | MIT except ES6 ports of browserify modules which are whatever the original library was.
|