esbuild-node-builtin
v0.1.1
Published
esbuild plugin let u use node builtin modules
Downloads
1,176
Maintainers
Readme
esbuild-node-builtin
esbuild plugin let u use node builtin modules
Install
$ pnpm add -D esbuild-node-builtin
Usage
import { nodeBuiltin } from 'esbuild-node-builtin'
esbuild.build({
// blabla
plugins: [nodeBuiltin()],
})
Options
injectGlobal
: use esbuild inject forglobal
reference, defaulttrue
injectProcess
: use esbuild inject forprocess
global reference, defaulttrue
injectBuffer
: use esbuild inject forBuffer
global reference, defaultfalse
, since this is big AND can not perform tree-shakingexclude
: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 these lines are side effects, and not tree-shakable
e.g
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
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
License
the MIT License http://magicdawn.mit-license.org