Webpack Service Worker Plugin
Plugin used to minify, link and build Service Worker for Webpack. Unlike workbox-webpack-plugin
, this plugin's primary task is to compile existing Service Worker with all plugins – not to generate new SW or inject chunks of boilerplate code.
Usage
Suitable for webpack v4 and webpack v5. From package.json
:
"peerDependencies": {
"webpack": "^4.4.0 || ^5.9.0"
}
- Install –
npm i @serguun42/webpack-service-worker-plugin
. - Add to webpack config's plugins section (usually
webpack.config.js
):
const WebpackSWPlugin = require("@serguun42/webpack-service-worker-plugin");
module.exports = {
entry: "…",
output: {
path: "…",,
filename: "…",
},
…
plugins: [
…,
new WebpackSWPlugin({
/** Relative to project's root */
source: "src/service-worker.js",
/** Relative to build/dist folder */
output: "js/sw.js"
}),
…
]
}
Config/params
name | description/type | default |
---|---|---|
source |
Path of Service Worker entry file relative to project's root | src/service-worker.js |
output |
Path of minified, linked and built Service Worker file inside relative to build folder | service-worker.js |
In general can be used to side-compile any non-SW code, just change these two parameters.