sw-loader
Yet another Service Workers loader for webpack.
Install
npm install --save-dev sw-loader
Usage
This loader emits a standalone service worker file and exports the entry point.
;// => 'scriptURL = {output.publicPath}/sw.js'// => file location: {output.path}/sw.js navigatorserviceWorker;
Options
name
Specify the name of output file:
;// => 'scriptURL = {output.publicPath}/my-worker.js'// => file location: {output.path}/my-worker.js
Notice: this loader DOES NOT support filename interpolation, for the reason that a service worker is considered as a persistent resource.
outputPath
By default the output path follows output.path
option in webpack configurations, you can change it to anywhere you like.
The outputPath
will be resolved to project root.
;// => 'scriptURL = {output.publicPath}/sw.js'// => file location: build/workers/sw.js
The outputPath
modifies only the output destination, if you want to change the access URL address of service worker script, use the publicPath
option below.
publicPath
By default this loader uses output.publicPath
to concatenate the public URL address of service worker script, you can modify it by:
;// => 'scriptURL = /sw.js'// => file location: {output.path}/sw.js