1

使用以下 vue.config.js:

module.exports = {
  pwa: { 
    name: 'My App',
    ...
    workboxPluginMode: 'InjectManifest',
    workboxOptions: {
      swSrc: 'src/sw.js', //and I use "sw.js" in my registerServiceWorker.js file
      skipWaiting: true,
      clientsClaim: true,
    }
  }
}

构建期间的验证错误是“skipWaiting”和“clientsClaim”不是受支持的参数。为什么?swSrc 来自此处列出的相同选项列表,并且构建不会抱怨该选项。当我删除这两个选项时,构建工作。

所以我想我的问题是:

skipWaitingclientsClaim什么“不支持的参数” ?网络包?PWA 插件?workbox-webpack 插件?我在哪里可以找到正确的选项集?谢谢。

更新:我没有设置 NODE-ENV 的 .env 文件。但是,我猜只有在删除 2 个选项时才能npm run build构建生产资产。dev ( ) 中删除的选项不会产生服务工作者文件。npm run serve

4

1 回答 1

1

You are using workbox plugin in InjectManifest mode, but pass parameters for GenerateSW.

InjectManifest mode expects an existing service-worker file to be injected and it's path defined in swSrc, while GenerateSW will create service-worker file, thus accepts different set of options (e.g. swDest, etc)

All options for each of modes can be found on the same documentation page of workbox-webpack-plugin you've posted in corresponding sections.

于 2018-11-15T19:40:20.530 回答