https://github.com/magicdawn/esbuild-node-builtin
esbuild plugin let u use node builtin modules
https://github.com/magicdawn/esbuild-node-builtin
esbuild esbuild-plugin esbuild-plugin-polyfill-node node-builtin node-polyfills polyfill-node rollup-plugin-polyfill-node
Last synced: 2 months ago
JSON representation
esbuild plugin let u use node builtin modules
- Host: GitHub
- URL: https://github.com/magicdawn/esbuild-node-builtin
- Owner: magicdawn
- License: mit
- Created: 2022-11-30T10:33:24.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-07-12T06:38:28.000Z (almost 3 years ago)
- Last Synced: 2025-01-23T01:17:13.126Z (over 1 year ago)
- Topics: esbuild, esbuild-plugin, esbuild-plugin-polyfill-node, node-builtin, node-polyfills, polyfill-node, rollup-plugin-polyfill-node
- Language: TypeScript
- Homepage:
- Size: 188 KB
- Stars: 1
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
- License: LICENSE
Awesome Lists containing this project
README
# esbuild-node-builtin
> esbuild plugin let u use node builtin modules
[](https://github.com/magicdawn/esbuild-node-builtin/actions/workflows/ci.yml)
[](https://codecov.io/gh/magicdawn/esbuild-node-builtin)
[](https://www.npmjs.com/package/esbuild-node-builtin)
[](https://www.npmjs.com/package/esbuild-node-builtin)
[](http://magicdawn.mit-license.org)
## Install
```sh
$ pnpm add -D esbuild-node-builtin
```
## Usage
```ts
import { nodeBuiltin } from 'esbuild-node-builtin'
esbuild.build({
// blabla
plugins: [nodeBuiltin()],
})
```
## Options
- `injectGlobal`: use esbuild inject for `global` reference, default `true`
- `injectProcess`: use esbuild inject for `process` global reference, default `true`
- `injectBuffer`: use esbuild inject for `Buffer` global reference, default `false`, since this is big AND can not perform tree-shaking
- `exclude`: `string[]`, disable proxy some builtin module
### `inject*`
see https://esbuild.github.io/api/#inject
#### `injectGlobal`
make `global.variable = 'value'` works in environment has no `global`, basicly translate to `globalThis.variable = 'value'`
## Why
there are existing packages
- https://github.com/FredKSchott/rollup-plugin-polyfill-node
- https://github.com/cyco130/esbuild-plugin-polyfill-node
AND
### rollup-plugin-polyfill-node
`rollup-plugin-polyfill-node` looks great, resolves to esm modules, and tree-shakable. but is for rollup.
### esbuild-plugin-polyfill-node
`esbuild-plugin-polyfill-node` is a esbuild plugin.
- AND use browserify commonjs deps. AND not tree-shakable
- UPDATE: 2023-07, it uses `@jspm/core`, same not well tree-shakable, e.g [path](https://github.com/jspm/jspm-core/blob/2.0.1/nodelibs/browser/path.js#L5-L19) these lines are side effects, and not tree-shakable
e.g
```ts
import { format } from 'util'
```
- this package & rollup-plugin-polyfill-node, other exports from util will not be included.
- esbuild-plugin-polyfill-node will include entire [util.js](https://unpkg.com/browse/util@0.12.5/util.js)
## Why depends on rollup
this package depends on rollup-plugin-polyfill-node, and use it's internal bundled polyfills.
the rollup dep is useless, just prevent error report.
## Changelog
[CHANGELOG.md](CHANGELOG.md)
## License
the MIT License http://magicdawn.mit-license.org