Plugin isn't being picked up in sw-precache-config.js
saleemepoch opened this issue · 3 comments
- I'm submitting a bug report
- I'm submitting a feature request
- I'm submitting a support request
webpack version:
3.7.1
sw-precache-webpack-plugin version:
0.11.4
Please tell us about your environment:
Windows 10
Current behavior:
sw-precache-config.js has the following:
var SWPrecacheWebpackPlugin = require('sw-precache-webpack-plugin');
...
plugins: [
new SWPrecacheWebpackPlugin({
cacheId: 'myproject',
filename: 'sw.js',
staticFileGlobs: [
'../public/index.html',
'../public/.js',
'../public/.css',
'../public/.woff2',
'../public/.svg',
'../public/**.ttf'
],
})]
...
The plugin doesn't seem to be picked up at all, for some reason. If I place staticFileGlobs outside of 'plugins' it does seem to cache the specified files, but not within 'plugins', and similarly, the service file generated is not the filename I specified above.
Expected/desired behavior:
I expect it to work, i.e. generate the service work file using the filename given and cache all the specified files.
FYI, I am using Angular 4 with webpack (so I have emitted everything to webpack.config.js
If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem along with your:
-
Webpack configuration:
-
Generated service worker (not minified):
I don't think your staticFileGlobs
are correctly pointing to your build directory and they don't look like they are pointing to your assets either. Try omitting staticFileGlobs
if you don't want to worry about it and all your webpack assets will be added
Thanks for your reply. If I place staticFileGlobs
outside of plugins
it works fine. I tested it out by removing all files except index.html and as expected it only cached index.html. I then added other files one by one and it cached each of them. This isn't the case when I put staticFileGlobs
in plugins
.
And if the plugin was being loaded, at the very least it should change the filename of the generated service worker as specified? i.e. sw.js
Its still churning out the default service-worker.js
which makes me think perhaps the whole plugin is being ignored.
staticFileGlobs
is a configuration so it makes sense that would happen. I would just stick to the default configurations if I were you (just use new SWPrecacheWebpackPlugin()
without any options).