How to use workbox-webpack-plugin together with Nuxt PWA

那年仲夏 提交于 2020-02-25 04:09:26

问题


I'm currently on Nuxt with PWA Plugin, including workbox module. However if I'm not mistaken this plugin doesn't allow to add the assets generated by webpack to precaching.

Is it possible to use workbox-webpack-plugin for only generating the precaching part of the sw.js file? If so, how would it be done?

There is some documentation on https://developers.google.com/web/tools/workbox/modules/workbox-webpack-plugin, however I'm not sure how to apply this to the Nuxt PWA context.


回答1:


Turns out this is only a problem in Version 3. For now I'm using the following workaround:

  • create empty file plugins/sw-precache-register.js
  • create file plugins/sw-precache.js with following content:
workbox.precaching.precacheAndRoute(self.__precacheManifest)
  • add the following to nuxt.config.js:
import { InjectManifest } from 'workbox-webpack-plugin'

...

  workbox: {
    importScripts: ['_nuxt/sw-precache.js'],
    workboxExtensions: ['~/plugins/sw-precache-register.js']
  }

If anybody has a better solution I'll acceppt that answer.



来源:https://stackoverflow.com/questions/55591206/how-to-use-workbox-webpack-plugin-together-with-nuxt-pwa

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!