-
Notifications
You must be signed in to change notification settings - Fork 214
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Document how to use webextension-polyfill with webpack.ProvidePlugin #156
Comments
I just want to write an hint for those who wants to use the package with webpack. (As I struggled) Instead of requiring it with I added to the webpack // Don't forget: `const CopyWebpackPlugin = require('copy-webpack-plugin');`
{ // Webpack Config
plugins: [
new CopyWebpackPlugin([
{
from: 'node_modules/webextension-polyfill/dist/browser-polyfill.min.js', // Take it directly from the node_modules
to: 'lib/browser-polyfill.js', // Where to copy the file in the destination folder
context: '../', // My extension is not at the root where node_modules/ is
flatten: true, // Don't keep the node_modules tree
},
]),
]
} Next, in your extension you can link to the file in the manifest.json or in the HTML files with the file path Note: for the devolvement build, you can use |
@Morikko Thanks for sharing. That approach looks very reasonable. The only "downside" is that you have to add an include everywhere in your extension, but the upside is that there is no duplication of polyfill code when your extension has multiple bundles for all parts (e.g. content script, background page, options page, popup, etc.). |
For the record we also use const CopyWebpackPlugin = require('copy-webpack-plugin');
{
plugins: [
new CopyWebpackPlugin([
{
from: 'node_modules/webextension-polyfill/dist/browser-polyfill.min.js'
}
])
]
} |
For those who would really prefer using webpack's Provide plugin, you can do so by installing webpack's import loader (e.g. module: {
rules: [{
test: require.resolve('webextension-polyfill'),
use: 'imports-loader?browser=>undefined'
}]
},
plugins: [
new ProvidePlugin({
"browser": "webextension-polyfill"
})
] |
Note: version 0.9.0 supports plugins: [
new ProvidePlugin({
browser: "webextension-polyfill"
})
] |
Working with webpack v5.73.0 and webextension-polyfill v0.9.0. Thank you.
|
There is some confusion over how the polyfill can be used with
webpack.ProvidePlugin
We should figure out the recommended way to do so and document it, in the README.
Here is some discussion: #86
The text was updated successfully, but these errors were encountered: