Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

A Vite plugin to polyfill Node's Core Modules for browser environments.

License

NotificationsYou must be signed in to change notification settings

davidmyersdev/vite-plugin-node-polyfills

Sponsor meDonate

vite-plugin-node-polyfills

A Vite plugin to polyfill Node's Core Modules for browser environments. Supportsnode: protocol imports.

Why do I need this?

Module "stream" has been externalized for browser compatibility. Cannot access "stream.Readable" in client code.

Since browsers do not support Node'sCore Modules, packages that use them must be polyfilled to function in browser environments. In an attempt to prevent runtime errors, Vite produceserrors orwarnings when your code references builtin modules such asfs orpath.

Getting Started

Install the package as a dev dependency.

# npmnpm install --save-dev vite-plugin-node-polyfills# pnpmpnpm install --save-dev vite-plugin-node-polyfills# yarnyarn add --dev vite-plugin-node-polyfills

Add the plugin to yourvite.config.ts file.

import{defineConfig}from'vite'import{nodePolyfills}from'vite-plugin-node-polyfills'// https://vitejs.dev/config/exportdefaultdefineConfig({plugins:[nodePolyfills(),],})

Customizable when you need it

The following options are available to customize it for your needs.

import{defineConfig}from'vite'import{nodePolyfills}from'vite-plugin-node-polyfills'// https://vitejs.dev/config/exportdefaultdefineConfig({plugins:[nodePolyfills({// To add only specific polyfills, add them here. If no option is passed, adds all polyfillsinclude:['path'],// To exclude specific polyfills, add them to this list. Note: if include is provided, this has no effectexclude:['http',// Excludes the polyfill for `http` and `node:http`.],// Whether to polyfill specific globals.globals:{Buffer:true,// can also be 'build', 'dev', or falseglobal:true,process:true,},// Override the default polyfills for specific modules.overrides:{// Since `fs` is not supported in browsers, we can use the `memfs` package to polyfill it.fs:'memfs',},// Whether to polyfill `node:` protocol imports.protocolImports:true,}),],})

All polyfills

  • If protocolImports is true, also adds node:[module]
['_stream_duplex','_stream_passthrough','_stream_readable','_stream_transform','_stream_writable','assert','buffer','child_process','cluster','console','constants','crypto','dgram','dns','domain','events','fs','http','http2','https','module','net','os','path','process','punycode','querystring','readline','repl','stream','string_decoder','sys','timers','timers/promises','tls','tty','url','util','vm','zlib',]

About the author

Hello! My name is David, and in my spare time, I build tools to help developers be more productive. If you find my work valuable, I would really appreciate asponsorship ordonation. If you want to see more of my work, check outdavidmyers.dev.

Thanks for your support! 🪴

About

A Vite plugin to polyfill Node's Core Modules for browser environments.

Topics

Resources

License

Code of conduct

Contributing

Security policy

Stars

Watchers

Forks

Packages

No packages published

Contributors14


[8]ページ先頭

©2009-2025 Movatter.jp