
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
Polyfillr dynamically load polyfills with dynamic import before start your application
polyfillr is a minimalist function to dynamically load polyfills before start your application. The function is inspired by Anuj Nair about the conditionally load of multiple Polyfills using Webpack
The plugin is available as the polyfillr package name on npm and Github.
npm i --save-dev polyfillr
yarn add --dev polyfillr
polyfillr was built for Node.js >=8.11.2.
Webpack need __webpack_public_path__ variable to find the path to dynamically load files. More information in the Webpack documentation.
The following example load Array.from polyfill from core-js node modules with dynamic import.
const polyfillr = require('polyfillr');
polyfillr({
polyfills: [
{
name: 'Array.from',
test: typeof Array.from !== 'function',
load: () => {
return import('core-js/es/array/from')
}
}
]
});
The following example load Array.from polyfill from core-js node modules with dynamic import and executed the callback function.
const polyfillr = require('polyfillr');
polyfillr({
polyfills: [
{
name: 'Array.from',
test: typeof Array.from !== 'function',
load: () => {
return import('core-js/es/array/from');
}
}
],
callback: () => {
console.log('Polyfill loaded');
}
});
The following example load Array.from polyfill from core-js node modules with dynamic import and add Webpack chunk name polyfill.array-from for the loaded polyfill file.
More information about Webpack magic comments.
const polyfillr = require('polyfillr');
polyfillr({
polyfills: [
{
name: 'Array.from',
test: typeof Array.from !== 'function',
load: () => {
return import(/* webpackChunkName: "polyfill.array-from" */ 'core-js/es/array/from');
}
}
]
});
The following example load HTMLPictureElement polyfill from ./polyfills project directory with dynamic import.
const polyfillr = require('polyfillr');
polyfillr({
polyfills: [
{
name: 'HTMLPictureElement',
test: typeof window.HTMLPictureElement !== 'function',
load: () => {
return import('./polyfills/picturefill.min.js');
}
}
]
});
The following example load HTMLPictureElement polyfill from ./polyfills project directory and Array.from polyfill from core-js node modules with dynamic import.
const polyfillr = require('polyfillr');
polyfillr({
polyfills: [
{
name: 'HTMLPictureElement',
test: typeof window.HTMLPictureElement !== 'function',
load: () => {
return import('./polyfills/picturefill.min.js');
}
},
{
name: 'Array.from',
test: typeof Array.from !== 'function',
load: () => {
return import('core-js/es/array/from');
}
}
]
});
The following example load Array.from polyfill from core-js node modules with dynamic import and enables debug log in the browser devtools.
const polyfillr = require('polyfillr');
polyfillr({
polyfills: [
{
name: 'Array.from',
test: typeof Array.from !== 'function',
load: () => {
return import('core-js/es/array/from');
}
}
],
debug: true
});
polyfillsArray
Tells to the function the list of polyfills to load. The polyfills array accept configurations of polyfills with an object with three parameters:
nameString
The name of the polyfill.
testBoolean
The test to see if we need to download the polyfill to the browser.
loadFunction
The function to executes to dynamically import the polyfill file.
callbackFunction = () => {}
Tells the optional function to execute when all polyfills are loaded.
debugBoolean = false
Tells to the function to enable the debug mode. Log messages will be displayed in the browser devtools for every polyfill files load.
polyfillr is licensed under the MIT License.
Created with ♥ by @yoriiis.
FAQs
Polyfillr dynamically load polyfills with dynamic import before start your application
We found that polyfillr demonstrated a not healthy version release cadence and project activity because the last version was released 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
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.