自定义Workbox来处理非活动的globPatterns?

问题描述 投票:0回答:1

当glob模式找不到任何匹配的文件时,Workbox会抛出以下错误:

Error: One of the glob patterns doesn't match any files. Please remove or fix the following: {
  "globDirectory": "public/",
  "globPattern": "dist/dep/**/*.{js,css}",
  ...
}

在某些情况下,可能需要一个目录为空(例如,在开发构建文件没有缩小时,它需要相当长的时间)。一个env参数可能会被用作一种解决方法,但如果没有找到文件,Workbox可以正常失败,那将是很好的。

workbox
1个回答
0
投票

我建议你做的是构建你的构建配置,以使用一些有关环境的状态信息(如NODE_ENV)来根据需要包含或删除globPatterns

您没有提到这是用于webpack,CLI还是其他方式,但这是一个示例:

const globPatterns = NODE_ENV === 'production' ?
  ['**/*.{html,js,css}'] :
  [];

GenerateSW({
  // Other config.
  globPatterns,
})
© www.soinside.com 2019 - 2024. All rights reserved.