-
-
Notifications
You must be signed in to change notification settings - Fork 6.3k
Description
What problem does this feature solve?
I used vue-cli
to create a Vue app for development and so far the experience has been great. However, I also wanted to add FCM support to it which requires me adding a service worker. I have been working on the integration for two days but I still don't know how to do it and register the service worker properly.
I've tried adding a new service worker firebase-messaging-sw.js
inside the public
folder and register it in App.vue
using
const registration = await navigator.serviceWorker.register(`${process.env.BASE_URL}firebase-messaging-sw.js`)
messaging.useServiceWorker(registration)
which works but then I'll have two service workers.
Then I modified vue.config.js
to use this service worker instead:
module.exports = {
pwa: {
name: 'My App',
themeColor: '#4DBA87',
msTileColor: '#000000',
appleMobileWebAppCapable: 'yes',
appleMobileWebAppStatusBarStyle: 'black',
// configure the workbox plugin
workboxPluginMode: 'InjectManifest',
workboxOptions: {
// swSrc is required in InjectManifest mode.
swSrc: 'public/firebase-messaging-sw.js'
// ...other Workbox options...
}
}
}
Then I encounter errors like The script has an unsupported MIME type ('text/html').
I've checked Workbox's guides, @vue/cli-plugin-pwa but I still can't make it work. Can someone show me how to do the integration, cause I really don't know how to do it.
This discussion seems really close to what I'm asking for (vuejs-templates/pwa#27).
I also asked the question on StackOverflow (https://stackoverflow.com/questions/50711933/vue-cli-3-and-firebase-service-worker-registration)
What does the proposed API look like?
I should be able to have a correct config to do FCM integration.