Security News
ESLint is Now Language-Agnostic: Linting JSON, Markdown, and Beyond
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
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
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!
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 98,097 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
ESLint has added JSON and Markdown linting support with new officially-supported plugins, expanding its versatility beyond JavaScript.
Security News
Members Hub is conducting large-scale campaigns to artificially boost Discord server metrics, undermining community trust and platform integrity.
Security News
NIST has failed to meet its self-imposed deadline of clearing the NVD's backlog by the end of the fiscal year. Meanwhile, CVE's awaiting analysis have increased by 33% since June.