Rollup Plugin for Node.js Polyfills

0.13.0 · active · verified Sun Apr 19

The `rollup-plugin-polyfill-node` package, currently at version `0.13.0`, provides a comprehensive solution for bundling applications that rely on Node.js built-in modules with Rollup. It acts as a modern, actively maintained fork of `rollup-plugin-node-polyfills`, offering improved and more complete polyfills. The package distinguishes itself by offering ES6-specific polyfills for many modules (like `process`, `events`, `util`), enabling named imports for better tree-shaking where applicable. Its development follows a community-driven release cadence, meaning updates are dependent on contributor engagement rather than a fixed schedule. It meticulously details the level of support for each Node.js builtin, from fully shimmed modules to partial implementations and empty mocks, crucial for developers migrating Node.js codebases to browser-compatible bundles via Rollup.

Common errors

Warnings

Install

Imports

Quickstart

Demonstrates how to integrate `rollup-plugin-polyfill-node` into a Rollup configuration, showing basic plugin instantiation alongside common accompanying plugins like `resolve` and `commonjs` for proper module resolution.

import nodePolyfills from 'rollup-plugin-polyfill-node';
import commonjs from '@rollup/plugin-commonjs';
import resolve from '@rollup/plugin-node-resolve';

// Basic Rollup configuration demonstrating node polyfills
export default {
  input: 'src/main.js', // Your main application entry point
  output: {
    file: 'dist/bundle.js',
    format: 'esm', // Output as ES module
  },
  plugins: [
    // Resolve node modules, important for finding polyfills
    resolve({
      preferBuiltins: false, // Ensure polyfills are used instead of assuming native Node.js builtins
      browser: true, // Hint to use browser-compatible versions where available
    }),
    // CommonJS plugin to convert CommonJS modules to ES modules
    // This is often needed for node_modules that are not pure ESM
    commonjs(),
    // Apply the node polyfills
    nodePolyfills({
      // Optional: include or exclude specific files. By default, it processes node_modules/**/*.js
      // include: [/node_modules/], // Example: explicitly include node_modules
      // sourceMap: true, // Enable source maps for debugging
    })
  ]
};

view raw JSON →