Skip to content

Commit 73ff74e

Browse files
committed
readme
1 parent 7d42b96 commit 73ff74e

1 file changed

Lines changed: 72 additions & 0 deletions

File tree

READMD.md

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# @rolldown/plugin-node-polyfills
2+
3+
This is a node polyfills plugin for [Rolldown](https://rolldown.rs/), largely based on the original [rollup-plugin-polyfill-node](https://github.com/FredKSchott/rollup-plugin-polyfill-node) by @fks, which is in turn a fork of [rollup-plugin-node-polyfills](https://github.com/ionic-team/rollup-plugin-node-polyfills).
4+
5+
The reason for a Rolldown-specific version is because Rolldown natively supports [esbuild-style `inject` option](https://esbuild.github.io/api/#inject), which removes the need for [@rollup/plugin-inject](https://github.com/rollup/plugins/tree/master/packages/inject#readme), which is used to inject polyfills for globals like `Buffer`. Rolldown's native `inject` is many times more efficient than a plugin because it completely avoids extra AST parse and traversals.
6+
7+
## Quickstart
8+
9+
```
10+
npm install --save-dev @rolldown/plugin-node-polyfills
11+
```
12+
13+
```js
14+
import { rolldown } from 'rolldown'
15+
import nodePolyfills from '@rolldown/plugin-node-polyfills'
16+
17+
rolldown({
18+
entry: 'main.js',
19+
plugins: [nodePolyfills()]
20+
})
21+
```
22+
23+
## Node.js Builtin Support Table
24+
25+
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.
26+
27+
- process*
28+
- events
29+
- stream*
30+
- util*
31+
- path
32+
- buffer*
33+
- querystring
34+
- url*
35+
- string_decoder*
36+
- punycode
37+
- http*
38+
- https*
39+
- os*
40+
- assert*
41+
- constants
42+
- timers*
43+
- console*
44+
- vm*§
45+
- zlib*
46+
- tty
47+
- domain
48+
- dns∆
49+
- dgram∆
50+
- child_process∆
51+
- cluster∆
52+
- module∆
53+
- net∆
54+
- readline∆
55+
- repl∆
56+
- tls∆
57+
- fs˚
58+
- crypto˚
59+
- perf_hooks˚ - **New:* just an empty shim for now, but would love help building a true polyfill!*
60+
61+
62+
† the http and https modules are actually the same and don't differentiate based on protocol
63+
64+
‡ default export only, because it's console, seriously just use the global
65+
66+
§ vm does not have all corner cases and has less of them in a web worker
67+
68+
∆ not shimmed, just returns mock
69+
70+
˚ shimmed, but too complex to polyfill fully. Avoid if at all possible. Some bugs and partial support expected.
71+
72+
Not all included modules bundle 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.

0 commit comments

Comments
 (0)