Security News
JSR Working Group Kicks Off with Ambitious Roadmap and Plans for Open Governance
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
rollup-plugin-polyfill-node
Advanced tools
The rollup-plugin-polyfill-node package is a Rollup plugin that provides polyfills for Node.js core modules, allowing you to use Node.js-specific modules in a browser environment. This is particularly useful for bundling libraries that were originally designed for Node.js but need to run in a browser.
Polyfill Node.js core modules
This feature allows you to polyfill Node.js core modules such as 'fs', 'path', 'crypto', etc., so that they can be used in a browser environment. The code sample demonstrates how to configure Rollup to use the nodePolyfills plugin.
import { nodePolyfills } from 'rollup-plugin-polyfill-node';
export default {
input: 'src/index.js',
output: {
file: 'bundle.js',
format: 'iife'
},
plugins: [
nodePolyfills()
]
};
The rollup-plugin-node-builtins package provides polyfills for Node.js core modules, similar to rollup-plugin-polyfill-node. However, it focuses more on providing built-in modules like 'buffer', 'process', and 'util'. It is a good alternative if you need specific built-in modules polyfilled.
The rollup-plugin-node-globals package provides polyfills for Node.js global variables and functions such as 'global', 'process', and 'Buffer'. It complements rollup-plugin-node-builtins and can be used together to achieve similar functionality to rollup-plugin-polyfill-node.
Browserify is a tool that allows you to use Node.js modules in the browser by bundling up all of your dependencies. While not a Rollup plugin, it achieves similar goals by transforming Node.js-specific code to be browser-compatible. It is more of a standalone tool compared to 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: https://github.com/rollup/plugins/pull/51#issuecomment-747489334
Not yet released, the following npm install command doesn't work yet.
npm install --save-dev rollup-plugin-polyfill-node
import nodePolyfills from 'rollup-plugin-polyfill-node';
rollup({
entry: 'main.js',
plugins: [
nodePolyfills( /* 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.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.
† 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.
FAQs
rollup-plugin-polyfill-node ===
The npm package rollup-plugin-polyfill-node receives a total of 112,318 weekly downloads. As such, rollup-plugin-polyfill-node popularity was classified as popular.
We found that rollup-plugin-polyfill-node demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
At its inaugural meeting, the JSR Working Group outlined plans for an open governance model and a roadmap to enhance JavaScript package management.
Security News
Research
An advanced npm supply chain attack is leveraging Ethereum smart contracts for decentralized, persistent malware control, evading traditional defenses.
Security News
Research
Attackers are impersonating Sindre Sorhus on npm with a fake 'chalk-node' package containing a malicious backdoor to compromise developers' projects.