webpack plugin to handle manifest script assets (background, content scripts, content css, service worker) from browser extensions
npm install webpack-browser-extension-scripts[action-image]: https://github.com/cezaraugusto/webpack-browser-extension-scripts/workflows/CI/badge.svg
[action-url]: https://github.com/cezaraugusto/webpack-browser-extension-scripts/actions?query=workflow%3ACI
[npm-image]: https://img.shields.io/npm/v/webpack-browser-extension-scripts.svg
[npm-url]: https://npmjs.org/package/webpack-browser-extension-scripts
> webpack plugin to handle manifest script assets (content_scripts, background.scripts, service_worker, user_scripts) from browser extensions
Properly output script files based on the manifest fields declared in the manifest file.
- Background scripts: refers to background.scripts
- Content scripts: refers to content_scripts
- Service Worker script (V3): refers to background.service_worker
- User scripts: refers to user_scripts
```
npm i webpack-browser-extension-scripts --save-dev
Check the demo folder for a list of samples using a HMR plugin.
`js
// webpack.config.js
const ScriptsPlugin = require('webpack-browser-extension-scripts')
module.exports = {
// ...other webpack config,
plugins: [
new ScriptsPlugin({
manifestPath: '
exclude: ['
})
]
}
`
Given a manifest file, grab all possible JavaScript fields and add them as webpack entry points.
`json`
// myproject/manifest.json
{
"manifest_version": 2,
"version": "0.1",
"name": "myextension",
"author": "Cezar Augusto",
"background": {
"scripts": ["background1.js", "background2.js"]
}
}
`js
// myproject/webpack.config.js
const path = require('path')
const ScriptsPlugin = require('webpack-browser-extension-scripts').default
const manifestPath = path.join(__dirname, 'manifest.json')
const outputPath = path.resolve(__dirname, './dist')
module.exports = {
mode: 'development',
entry: {},
output: {
path: outputPath,
clean: true
},
plugins: [
new ScriptsPlugin({
manifestPath
})
]
}
`
Output:
```
- myproject/
- background/index.js
MIT (c) Cezar Augusto.