1

我使用的是 Workbox v2,现在升级到 v3。我使用 Webpack 生成它。

我已经开始使用 GenerateSW,并将旧配置的一部分移到新配置中,更改 v3 所需的位置。

我遇到了一个错误,templatedUrls似乎与 v2 中的工作方式不同。

网络包配置:

plugins: [
    new WorkboxPlugin.GenerateSW({
        include: [/\.css$/, /\.js$/, /sprites\\.svg$/],
        importsDirectory: path.join(__dirname, 'public/precache'),
        'clientsClaim': true,
        'skipWaiting': true,
        'templatedUrls': {
            '/': ['resources/views/index.blade.php', 'resources/views/scripts.blade.php']
        },
        navigateFallback: '/'
    })
]

错误:

There was an issue using one of the provided 'templatedUrls'. 'resources/views/index.blade.php' from '{"/":["resources/views/index.blade.php","resources/views/scripts.blade.php"]}':
Error: An error occurred when globbing for files. 'The "path" argument must be of type string'
    at .../node_modules/workbox-build/build/lib/get-file-manifest-entries.js:138:27

如果我使用字符串而不是数组,它可以正常工作,但这显然是用于手动版本控制而不是文件路径数组,这是我在这里尝试做的。

此外,即使将其更改为我的 index.php 文件也会产生同样的问题:

There was an issue using one of the provided 'templatedUrls'. 'index.php' from '{"/":["index.php"]}':
Error: An error occurred when globbing for files. 'The "path" argument must be of type string'

最后,如果我globDirectory: 'public',在它之前添加,它似乎可以工作,并且希望我的 URL 基于该公共目录 ( ../resources...)。但是,它给了我这个警告:

WARNING in You're using the following Workbox configuration 
option: [globDirectory]. In Workbox v3 and later, this is usually not needed.

文档中似乎没有提到此密钥是必需的。

任何建议将不胜感激!

4

0 回答 0