-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
vue-cli-pwa serves some weird service-worker.js. Service Workers are not just for caching. #4801
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Hi |
+1 I have the same question: How can I run my service worker in development? |
@kubamarkiewicz you can't with this "vue-cli-pwa" plugin. While there isn't a HMR "hot-reload" solution, this bug is about how this vue-cli-pwa plugin stops any solution. It's not possible to develop a SW using the vue-cli's "vue serve". AND, "vue serve" breaks for development once your Vue app starts using any custom SW features. SO, once your app starts using your SW's features, you can't develop your app with "vue serve". Instead of "vue serve", you have to iterate using "vue build" to create production build, then serve it yourself. We implemented VUE_APP_NO_MINIMIZE in our build stuff to help debugging.
My current client is paying me to iterate by building and deploying to a server because the app won't authenticate users from localhost (CORS). This is a 10 min iteration loop. Developing the SW features, I was able to develop the service worker functionality on localhost with the app crashing by building and serving manually (2 min iteration loop). Note that the Service Worker is an independent background process (like a hidden tab), so loading the "crashing" URL in the browser is just a way to attach the console to the service worker. Once attached to the console, you can interact with the SW using fetch():
Other tips:
|
I just started developing a PWA with vue. I commented out :
and hot reload works again. Tested by changing the text in :
Not sure though what the implications will be, the console shows the added "Now it is getting hot-reloaded again'" text though implying that the service worker is updated. Can anyone advise for any pitfalls this method may bring? By the way I really love vue :) Cheers! |
Why does it break? I keep seeing posts about how this shouldn't be done, but not the reasoning behind it. |
I believe that there are some issues you can run into, because service worker caching can mess up hot reloading. I have modified my The clean solution for this problem is to enable/disable only caching, depending on development/production mode. Maybe I am missing something here though. I have not tested my |
Hi, One way would be to allow a build sequence only for the service-worker.js, and for the registerServiceWorker.js code. This mode would not be default, and the operator would be responsible for disabling cache. |
I went through the trouble of using Everyone is saying a service worker will make HMR explode... but it sounds to me like it should be fairly easy to fix that by just adding a path exclusion to your service worker... will come back to this if I need faster service-worker development and fix it. The fastest way to get it working is probably disable HMR, include the worker code via a custom webpack config and have the worker go into an amnesia mode during development. |
Version
4.0.5
Reproduction link
https://www.npmjs.com/package/@vue/cli-plugin-pwa
localhost:8080/service-worker.js is returning some weird code I didn't write.
Reading the docs, the plugin is doing this to prevent "caching problems".
Service Workers can do more than "caching", and running Service Workers in development is necessary to develop application features that depend on them.
Steps to reproduce
Read the docs here:
https://www.npmjs.com/package/@vue/cli-plugin-pwa
The docs indicate I should compile for production, then do development. This doesn't make sense.
Also, the plugin serves non-functional code that I didn't write into my application. There doesn't seem to be a way to override this feature, and run my code in development.
Here is the plugin code:
https://github.com/MichaelJCole/vue-cli/blob/dev/packages/%40vue/cli-plugin-pwa/index.js
How can I run my service worker in development?
What is expected?
To run my code.
What is actually happening?
Some weird code I didn't write is running.
The text was updated successfully, but these errors were encountered: