Package Exports
- esbuild-plugin-polyfill-node
Readme
esbuild-plugin-polyfill-node
ESBuild plugin to polyfill Node.js built-ins geared towards edge environments.
Installation
npm install esbuild-plugin-polyfill-nodeUsage
import { build } from "esbuild";
import { nodePolyfills } from "esbuild-plugin-polyfill-node";
build({
entryPoints: ["src/index.js"],
bundle: true,
outfile: "dist/bundle.js",
plugins: [
nodePolyfills({
// Options (optional)
}),
],
});Options
buffer: Whether to inject theBufferglobal. Disable it to prevent code likeif (typeof Buffer !== "undefined")from pulling in the (quite large)buffer-es6polyfill. Default:true.process: Whether to inject theprocessglobal. Disable it to preventprocess.env.NODE_ENVfrom pulling in theprocess-es6polyfill. You can use thedefineoption to replaceprocess.env.NODE_ENVinstead. Default:true.crypto: Whether to polyfill thecryptomodule. This is disabled by default because thecrypto-browserifypolyfill is quite large and you may want to think again before pulling it in. Using the Web Crypto API is usually a better idea. Default:false.fs: Whether to polyfill thefsmodule. This is disabled by default because thebroserify-fspolyfill is quite large and you may want to think again before pulling it in. Default:false.
Provided polyfills
_buffer_listas implemented inreadable-stream_stream_passthroughas implemented inreadable-stream_stream_readableas implemented inreadable-stream_stream_transformas implemented inreadable-stream_stream_writableas implemented inreadable-streamassertas implemented inassertbufferas implemented inbuffer-es6consoleas implemented inconsole-browserifycrypto¹ as implemented incrypto-browserifydomainas implemented indomain-browsereventsas implemented ineventsfs¹ as implemented inbrowserify-fshttpas implemented instream-httphttpsas implemented instream-httposas implemented inospathas implemented inpathprocessas implemented inprocess-es6punycodeas implemented inpunycodequerystringas implemented inquerystringstreamas implemented instreamstring_decoderas implemented instring_decodersysas implemented inutiltimersas implemented intimers-browserifyttyas implemented intty-browserifyurlas implemented inurlutilas implemented inutilvmas implemented invm-browserifyzlibas implemented inbrowserify-zlib
¹ crypto and fs polyfills have to be explicitly enabled by passing crypto: true and fs: true to the plugin options. Otherwise, they will be replaced with empty stubs.
Shimmed globals
global(aliased toglobalThis)process¹ (imports theprocessmodule)Buffer¹ (imports thebuffermodule)__dirname(always"/")__filename(always"/index.js")
¹ process and Buffer shims can be disabled by passing process: false and buffer: false to the plugin options.
Empty polyfills
dnsdgramchild_processclustermodulenetreadlinerepltls
crypto and fs will also produce empty stubs unless explicitly enabled by passing crypto: true and fs: true to the plugin options.
Credits
- Fatih Aygün, under the MIT license
- Loosely based on rollup-plugin-polyfill-node