我正在使用Workbox的v2,现在正在升级到v3。我使用Webpack生成它。
我已经开始使用GenerateSW,并将旧配置的部分移动到新配置中,更改v3所需的位置。
我遇到了一个templatedUrls
的错误,似乎没有像在v2中那样工作。
Webpack配置:
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',
,它似乎有效,并且我希望我的网址基于该公共目录(../resources...
)。但是,它给了我这个警告:
WARNING in You're using the following Workbox configuration
option: [globDirectory]. In Workbox v3 and later, this is usually not needed.
在文档中似乎没有提及此密钥。
任何建议都会得到充分的体会!