Add polyfill.io to your HtmlWebpackPlugin generated HTML
npm install html-webpack-polyfill-io-plugin2HtmlWebpackPolyfillIOPlugin
Use the Financial Times' polyfill.io service in your webpack builds with the help of the HtmlWebpackPlugin.
Install the plugin with npm:
``shell`
$ npm install --save-dev html-webpack-polyfill-io-plugin
Install the pluging with yarn:
`shell`
yarn add --dev html-webpack-polyfill-io-plugin
Add the plugin to your webpack configuration.
`js
const HtmlWebpackPlugin = require('html-webpack-plugin')
const HtmlWebpackPolyfillIOPlugin = require('html-webpack-polyfill-io-plugin')
module.exports = {
/ ... /
plugins: [
new HtmlWebpackPlugin(),
new HtmlWebpackPolyfillIOPlugin(),
]
}
`
The plugin's configuration mirrors that listed at polyfill.io/v2/docs/api when possible. Documentation here is minimal to avoid duplicating the official documentation.
default: true when NODE_ENV === 'production', false otherwise.
Features to include.
May be a string defining a comma separated list of features or an array of features.
Features to exclude from output.
May be a string defining a comma separated list of features or an array of features.
default: not set
If set, specifies whether features listed in features should be gated or always included.
A function to be called once the polyfill has been loaded successfully.
Must be a valid javascript identifier.
What to do when the user agent is not recognized.
Explicitly enable or diable real user monitoring
`js``
new HtmlWebpackPolyfillIOPlugin({
minify: true, // Always minify, even in dev
features: [
'Intl',
'Map',
'Set',
'Array.isArray',
'Array.prototype.find',
'Array.prototype.some',
'Object.assign',
'Promise',
], // Features to include
flags: 'always', // Include all specified features regardless of user-agent
unknown: 'polyfill', // Polyfill all listed features if user-agent is unkown
callback: 'polyfillHasLoaded',
rum: true, // Allow real-user monitoring
})