• Stars
    star
    174
  • Rank 218,216 (Top 5 %)
  • Language
    TypeScript
  • License
    Other
  • Created almost 4 years ago
  • Updated 4 months ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A modern Node.js polyfill for your Rollup bundle.

rollup-plugin-polyfill-node

🔩 A modern Node.js polyfill for your Rollup bundle.

This repo is an updated, maintained fork of https://github.com/ionic-team/rollup-plugin-node-polyfills to support better Node.js polyfills in Snowpack and all other Rollup projects. See this thread for discussion on moving this plugin into the official Rollup org: rollup/plugins#51 (comment)

This repo is completely community-maintained. If you have an issue and know JavaScript, help out and submit a PR. This may be the only way to get your issue resolved!

Quickstart

npm install --save-dev rollup-plugin-polyfill-node
import nodePolyfills from 'rollup-plugin-polyfill-node';
rollup({
  entry: 'main.js',
  plugins: [
    nodePolyfills( /* options */ )
  ]
})

Options

All options are optional.

  • include: Array<string | RegExp> | string | RegExp | null;: Defaults to transforming Node.js builtins in all node_modules/**/*.js files only. Pass in null to transform all files, including all files including any source files.
  • exclude: Array<string | RegExp> | string | RegExp | null;: Exclude files from transformation.
  • sourceMap: boolean: True to get source maps, false otherwise.

Node.js Builtin Support Table

The following modules include ES6 specific version which allow you to do named imports in addition to the default import and should work fine if you only use this plugin.

  • process*
  • events
  • stream*
  • util*
  • path
  • buffer*
  • querystring
  • url*
  • string_decoder*
  • punycode
  • http*†
  • https*†
  • os*
  • assert*
  • constants
  • timers*
  • console*‡
  • vm*§
  • zlib*
  • tty
  • domain
  • dns∆
  • dgram∆
  • child_process∆
  • cluster∆
  • module∆
  • net∆
  • readline∆
  • repl∆
  • tls∆
  • fs˚
  • crypto˚
  • perf_hooks˚ - New: just an empty shim for now, but would love help building a true polyfill!

† the http and https modules are actually the same and don't differentiate based on protocol

‡ default export only, because it's console, seriously just use the global

§ vm does not have all corner cases and has less of them in a web worker

∆ not shimmed, just returns mock

˚ shimmed, but too complex to polyfill fully. Avoid if at all possible. Some bugs and partial support expected.

Not all included modules rollup equally, streams (and by extension anything that requires it like http) are a mess of circular references that are pretty much impossible to tree-shake out, similarly url methods are actually a shortcut to a url object so those methods don't tree shake out very well, punycode, path, querystring, events, util, and process tree shake very well especially if you do named imports.

More Repositories

1

snowpack

ESM-powered frontend build tool. Instant, lightweight, unbundled development. ✌️
JavaScript
19,494
star
2

CoVim

Collaborative Editing for Vim
Vim Script
2,945
star
3

pika-pack

📦⚡️ Build your npm package using composable plugins. https://www.pika.dev/blog/introducing-pika-pack/
JavaScript
2,312
star
4

the-node-way

Design patterns and best practices for building scaleable, maintainable and beautiful Node.js applications. Now with website! -->
JavaScript
1,492
star
5

create-snowpack-app

The all-in-one app template for Snowpack. [moved]
JavaScript
728
star
6

fflip

Flexible Feature Flipping/Flagging for Node.js
JavaScript
655
star
7

esm-hmr

a Hot Module Replacement (HMR) API for your ESM-based dev server.
TypeScript
412
star
8

pika-pack-builders

🏗 A collection of official & community @pika/pack build plugins
JavaScript
162
star
9

react

ESM builds of React & React DOM (v16)
JavaScript
53
star
10

standard-pkg

Standard NPM Package Format
TypeScript
42
star
11

analyze-npm

Analyze npm, hunt for es module packages
JavaScript
35
star
12

pika-pack-examples

Example @pika/pack packages & projects
JavaScript
33
star
13

slackey

The simple, easy-to-use JavaScript SDK for Slack
JavaScript
32
star
14

fflip-express

fflip integration for the express.js web framework
JavaScript
16
star
15

dbplace

JavaScript
12
star
16

snowpack-plugin-starter-template

Blank Snowpack plugin template to get up and running fast
TypeScript
6
star
17

headless-garden

TypeScript
3
star
18

middle-man

Simple express middleware manager
JavaScript
3
star
19

ie11-going-away-party

Working title
HTML
1
star