This library is forked from webextension-polyfill and modified to be used on Webpack builds for Chrome using ProvidePlugin.
NPM:
npm install webextension-polyfill-for-webpack
Yarn:
yarn add webextension-polyfill-for-webpack
This polyfill is designed to be used with ProvidePlugin and exclusively when building for Chrome.
webpack.config.js
const config = { /* Your base webpack configuration here */ }
module.exports = (env, argv) => {
if (argv.browser === 'chrome') { // assumes you run "webpack --browser chrome"
config.plugins.push(
new webpack.ProvidePlugin({
browser: 'webextension-polyfill-for-webpack',
}),
);
}
}