I'm writing PWA app. I was using default Service Worker from template that I'm using (Vue.js PWA template), but now I have decided to write my own from the scratch. I have placed it (service-worker.js
) into static
folder, because I want to have static name for it - I don't want to change name each time (build).
In this particular Service Worker I want to use package name
and version
, so that I can nicely generate cache ID.
So I want to achieve something like this:
./package.json:
{
"name": "my.app",
"version": "1.0.0",
...
}
./static/service-worker.js:
var CACHE_ID = 'PACKAGE_NAME-vPACKAGE_VERSION';
...
./build/service-worker.js:
var CACHE_ID = 'my.app-v1.0.0';
The ./build/service-worker.js
shows what I want to achieve.
I have tried https://www.npmjs.com/package/string-replace-loader with below configuration:
{
test: /service-worker\.js$/,
loader: 'string-replace-loader',
options: {
multiple: [
{
search: 'PACKAGE_NAME',
replace: packageConfig.name
},
{
search: 'PACKAGE_VERSION',
replace: packageConfig.version
}
]
}
}
But as I understand files placed in static
are not modules (am I right?), so those are not checked by module.rules
.
I would be greatful for help and/or guidence how I can solve this problem.