A Vite plugin to polyfill Node.js standard library modules for browser usage.
vite-plugin-stdlib is a Vite plugin that automatically polyfills Node.js standard library modules (like Buffer, process, global) for browser environments. This enables you to use packages that depend on Node.js built-ins in your browser-based Vite applications without manual configuration.
- 🔄 Automatic Polyfills: Seamlessly polyfills Node.js globals (
Buffer,process,global) - 📦 Standard Library Support: Provides browser-compatible implementations of Node.js standard library modules
- ⚡ Vite Integration: Optimized for both development and production builds
- 🎯 Zero Configuration: Works out of the box with minimal setup
- 🔧 Rolldown & OXC Support: Configured for Vite's modern build tooling
npm install vite-plugin-stdlib
# or
pnpm add vite-plugin-stdlib
# or
yarn add vite-plugin-stdlibAdd the plugin to your vite.config.ts:
import { defineConfig } from 'vite'
import { stdlib } from 'vite-plugin-stdlib'
export default defineConfig({
plugins: [
stdlib(),
],
})That's it! Now you can use Node.js globals and standard library modules in your browser code:
// These will work in the browser
console.log(Buffer.from('hello'))
console.log(process.env)
console.log(global)The plugin provides three main polyfills:
Polyfills the Node.js Buffer API using the buffer package, making it available globally in the browser.
Polyfills the Node.js process object using the process package, providing access to process.env, process.nextTick(), etc.
Polyfills the Node.js global object by mapping it to globalThis (or this/self for older environments).
Uses node-stdlib-browser to provide browser-compatible implementations of Node.js built-in modules like:
pathfsstreamcryptoevents- And many more...
This plugin is particularly useful when:
- Using packages that depend on Node.js built-ins in browser environments
- Migrating Node.js code to run in the browser
- Working with crypto, buffer, or stream operations in the browser
- Building isomorphic applications that share code between Node.js and browser
Unlike vite-plugin-stdlib-polyfills, this plugin is specifically designed to work with Vite 8+ and leverages modern build tools like Rolldown and OXC for optimal performance and compatibility.
MIT © Jinjiang
Contributions are welcome! Please feel free to submit a Pull Request.
If you encounter any issues or have questions, please file them in the issues section.