【问题标题】:How to Correctly Provide swDest?如何正确提供 swDest?
【发布时间】:2020-06-04 19:51:03
【问题描述】:

我已经安装了workbox-cli

并使用下面的配置,位于config.js

const {InjectManifest} = require('workbox-webpack-plugin');
const path = require('path');

module.exports = {
  webpack: function(config, env) {
    config.plugins.push(
      new InjectManifest({
        globPatterns: ['**/*.{js,css}'],
        swSrc: path.join('public', 'custom-service-worker.js'),
        swDest: 'service-worker.js',
        maximumFileSizeToCacheInBytes: 5000000,
      })
    );
    return config;
  }
} 

然后运行

workbox generateSW config.js

我明白了

您的配置无效:

{ "webpack": function(config, env) {\n config.plugins.push(\n new InjectManifest({\n >globPatterns: ['**/*.{js,css}'],\n swSrc: 路径.join('public', 'custom-service->worker.js'),\n swDest: 'service-worker.js',\n maximumFileSizeToCacheInBytes: >5000000,\n })\n );\n 返回配置;\n }, "swDest" [1]: -- 缺失 -- }

[1] "swDest" 是必需的

我不知道还能做什么,因为我提供的是swDest

【问题讨论】:

    标签: service-worker workbox workbox-webpack-plugin


    【解决方案1】:

    从我的角度来看,它看起来不错。我唯一想到的就是尝试将 publicPath 设置为''。我正在使用 laravel-mix 所以这是我的配置。

    mix.webpackConfig(webpack => {
        return {
            plugins: [
                new WorkboxPlugin.InjectManifest({
                    swSrc: './public/sw.js',
                    swDest: 'service-worker.js',
                    maximumFileSizeToCacheInBytes: 5*1024*1024,
                })
            ],
            output: {
                publicPath: ''
            }
        };
    });
    

    【讨论】:

      猜你喜欢
      • 2011-01-11
      • 1970-01-01
      • 1970-01-01
      • 2022-01-02
      • 2013-08-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多