Service worker is generated but no include script is added to index.html file
dannysmc95 opened this issue · 5 comments
BEFORE YOU SUBMIT please read the following:
- I'm submitting a bug report
- I'm submitting a feature request
- [ + ] I'm submitting a support request
webpack version:
3.8.1
sw-precache-webpack-plugin version:
0.11.4
Please tell us about your environment:
OSX 10.13.1 (High Sierra)
Browser: [Phantom XX | Chrome XX | Firefox XX | IE XX | Safari XX | Other XX]
Chrome 63.0.3239.84 (Official Build) (64-bit)
Current behavior:
So currently I am using this repository as a boilerplate: https://github.com/vuejs-templates/webpack
and what is happening is I am adding the config into my build/webpack.prod.conf.js file as follows:
// Service Worker Cache
new SWPrecacheWebpackPlugin({
cacheId: '{{ name }}',
filename: 'service-worker.js',
staticFileGlobs: ['dist/**/*.{js,html,css}'],
minify: true,
stripPrefix: 'dist/'
}),
Then when I run npm run build
it works fine, I was then told (following a guide) to add the following: <%= htmlWebpackPlugin.options.serviceWorkerLoader %>
to get the script to be added to my index.html page, but it never gets added? So no service worker loads?
Expected/desired behavior:
I just want the service worker to be loaded correctly via some kind of script that adds it onto the page.
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:
I mean, it's been 3 months nearly, so any idea what to do here?
@dannysmc95 Are you using HTMLWebpackPlugin? I think that instruction implies that you're using it.
call this in your index.html or main.js
Super sorry for delay, I've been away. You just need to follow instructions in basic usage
Add this to your html template or main js bundle:
(function() {
if('serviceWorker' in navigator) {
navigator.serviceWorker.register('/service-worker.js');
}
})();
where /service-worker.js
is the path to your service worker
Hmmm, I see, so you have to manually load it instead. Hmm for some reason I was under the impression it generated the code for you. No worries, thank you!