FCM ServiceWorker in f7 vue pwa

Hi, everybody. Question from a novice.

There is an f7 vue pwa app. I want to add a ServiceWorker for Firebase Cloud Messaging.

Question: I need to use it as a separate file “src/firebase-messaging-sw.js”? If so, where and how do I add it to the app? In webpack.config.js? in app.js?

Or the app can only have one ServiceWorker “src/service-worker.js”? And there I need to write code?


Всем привет. Вопрос от новичка.

Имеется f7 vue pwa приложение. Я хочу добавить СервисВоркер для Firebase Cloud Messaging.

Вопрос: Его нужно как отдельный файл использовать “src/firebase-messaging-sw.js”? Если да, то где и как его нужно добавить в приложение? В webpack.config.js? в app.js?

Или в приложении может быть только один СервисВоркер “src/service-worker.js”? И там нужно код писать?

This file must be in root location where your PWA is generated (i guess it should be in www/firebase-messaging-sw.js.

So you need to put this SW file inside of src/ folder and tweak webpack config to copy this file into target root:

    new CopyWebpackPlugin({
      patterns: [
        ...
        {
          noErrorOnMissing: true,
          from: resolvePath('src/firebase-messaging-sw.js'),
          to: resolvePath('www/firebase-messaging-sw.js'),
        },
      ],
    }), 
1 Like