1.0.1 • Published 3 years ago

@sapphire/rollup-plugin-node-polyfills v1.0.1

Weekly downloads
-
License
MIT
Repository
github
Last release
3 years ago

Sapphire Logo

@sapphire/rollup-plugin-node-polyfills

NodeJS pollyfills for Rollup

Code is forked from, and inspired by, https://github.com/ionic-team/rollup-plugin-node-polyfills/

GitHub Total alerts Language grade: JavaScript Coverage Status npm Depfu

Support Server


Description

Allows the node builtins to be required/imported.

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 ˚

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

˚ optional, add option to enable browserified shim

Crypto is not shimmed and and we just provide the commonjs one from browserify and it will likely not work, if you really want it please pass {crypto: true} as an option.

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.

config for using this with something simple like events or querystring

Installation

yarn add -D @sapphire/rollup-plugin-node-polyfills
# npm i -D @sapphire/rollup-plugin-node-polyfills

Usage

import nodePolyfills from '@sapphire/rollup-plugin-node-polyfills';

rollup({
	entry: 'main.js',
	plugins: [
		nodePolyfills({
			include: [
				/* fill in the pollyfills to include here */
			]
		})
	]
});

and now if main contains this, it should work

import EventEmitter from 'events';
import { inherits } from 'util';

// etc

License

MIT except ES6 ports of browserify modules which are whatever the original library was.

Buy us some doughnuts

Sapphire Project is and always will be open source, even if we don't get donations. That being said, we know there are amazing people who may still want to donate just to show their appreciation. Thank you very much in advance!

We accept donations through Open Collective, Ko-fi, Paypal, Patreon and GitHub Sponsorships. You can use the buttons below to donate through your method of choice.

Donate WithAddress
Open CollectiveClick Here
Ko-fiClick Here
PatreonClick Here
PayPalClick Here

Contributors ✨

Thanks goes to these wonderful people (emoji key):

This project follows the all-contributors specification. Contributions of any kind welcome!