Skip to content

Commit 8a29cda

Browse files
committed
refactor: tweak pwa plugin
1 parent 9095483 commit 8a29cda

File tree

1 file changed

+19
-17
lines changed

1 file changed

+19
-17
lines changed

packages/@vue/cli-plugin-pwa/index.js

Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
module.exports = (api, options) => {
22
api.chainWebpack(webpackConfig => {
33
const name = api.service.pkg.name
4-
54
const userOptions = options.pwa || {}
65

76
// the pwa plugin hooks on to html-webpack-plugin
@@ -17,24 +16,27 @@ module.exports = (api, options) => {
1716
// Default to GenerateSW mode, though InjectManifest also might be used.
1817
const workboxPluginMode = userOptions.workboxPluginMode || 'GenerateSW'
1918
const workboxWebpackModule = require('workbox-webpack-plugin')
20-
if (workboxPluginMode in workboxWebpackModule) {
21-
const workBoxConfig = Object.assign({
22-
cacheId: name,
23-
exclude: [
24-
new RegExp('\.map$'),
25-
new RegExp('img/icons/'),
26-
new RegExp('favicon\.ico$'),
27-
new RegExp('manifest\.json$')
28-
]
29-
}, userOptions.workboxOptions)
3019

31-
webpackConfig
32-
.plugin('workbox')
33-
.use(workboxWebpackModule[workboxPluginMode], [workBoxConfig])
34-
} else {
35-
throw new Error(`${workboxPluginMode} is not a supported Workbox webpack plugin mode. ` +
36-
`Valid modes are: ${Object.keys(workboxWebpackModule).join(', ')}`)
20+
if (!(workboxPluginMode in workboxWebpackModule)) {
21+
throw new Error(
22+
`${workboxPluginMode} is not a supported Workbox webpack plugin mode. ` +
23+
`Valid modes are: ${Object.keys(workboxWebpackModule).join(', ')}`
24+
)
3725
}
26+
27+
const workBoxConfig = Object.assign({
28+
cacheId: name,
29+
exclude: [
30+
/\.map$/,
31+
/img\/icons\//,
32+
/favicon\.ico$/,
33+
/manifest\.json$/
34+
]
35+
}, userOptions.workboxOptions)
36+
37+
webpackConfig
38+
.plugin('workbox')
39+
.use(workboxWebpackModule[workboxPluginMode], [workBoxConfig])
3840
}
3941
})
4042

0 commit comments

Comments
 (0)