-
Notifications
You must be signed in to change notification settings - Fork 102
/
Copy pathindex.js
42 lines (37 loc) · 1002 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
const Workbox = require('workbox-webpack-plugin');
exports.workbox = {
advanced: false, // alias
injectManifest: false, // alias
swSrc: 'service-worker.js', // template, inject-only
navigateFallbackWhitelist: [/^(?!\/__).*/],
navigateFallback: 'index.html',
swDest: 'sw.js',
exclude: [
/\.git/,
/\.map$/,
/\.DS_Store/,
/^manifest.*\.js(?:on)?$/,
/\.gz(ip)?$/,
/\.br$/
]
}
exports.webpack = function (config, env, opts) {
let isInject = opts.workbox.injectManifest || opts.workbox.advanced;
let arr = ['advanced', 'injectManifest'];
let fn = 'GenerateSW';
if (isInject) {
fn = 'InjectManifest';
arr.push('navigateFallback', 'navigateFallbackWhitelist');
} else {
arr.push('swSrc');
}
// Delete unrecognized keys (per mode)
arr.forEach(key => delete opts.workbox[key]);
// Inject-mode assumes "awareness" while developing
// ~> otherwise, only add in production
if (isInject || env.production) {
config.plugins.push(
new Workbox[fn](opts.workbox)
);
}
}