-
Notifications
You must be signed in to change notification settings - Fork 11
/
index.js
76 lines (62 loc) · 1.88 KB
/
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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
'use strict';
const mergeTrees = require('broccoli-merge-trees');
const BroccoliWorkbox = require('./lib/broccoli-workbox');
module.exports = {
name: require('./package').name,
isDevelopingAddon: () => true,
config(env, baseConfig) {
const emberCliWorkboxOptions = baseConfig['ember-cli-workbox'];
const appOptions =
(this.app && this.app.options['ember-cli-workbox']) || {};
const projectName = (baseConfig.APP && baseConfig.APP.name) || 'app';
let workboxOptions = (this.app && this.app.options.workbox) || {};
let options = emberCliWorkboxOptions || {};
workboxOptions = Object.assign(
{
swDest: 'sw.js',
globDirectory: './',
globPatterns: [
'**/*.{json,css,js,png,svg,eot,ttf,woff,jpg,gif,ico,xml,html,txt}',
],
skipWaiting: false,
clientsClaim: false,
cacheId: projectName,
},
workboxOptions
);
env = env || process.env.EMBER_ENV;
// Do nothing if no ENV. For example, when running an ember generator.
/* istanbul ignore else */
if (!env) {
return;
}
const isProdBuild = Boolean(env.match('prod'));
options = Object.assign(
{
enabled: isProdBuild,
debug: !isProdBuild,
importScriptsGlobPatterns: ['assets/service-workers/*.js'],
},
options,
appOptions
);
this._options = options;
this.workboxOptions = workboxOptions;
// Append "workbox" config to "ember-cli-workbox" config
if (emberCliWorkboxOptions) {
emberCliWorkboxOptions.swDest = workboxOptions.swDest;
}
},
postprocessTree(type, tree) {
if (type !== 'all') {
return tree;
}
const workboxFunnel = new BroccoliWorkbox([tree], {
options: this._options,
workboxOptions: this.workboxOptions,
});
return mergeTrees([tree, workboxFunnel], {
overwrite: true,
});
},
};