forked from BBVAEngineering/ember-cli-workbox
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
78 lines (61 loc) · 1.69 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
77
78
/* eslint-disable no-sync */
'use strict';
const Funnel = require('broccoli-funnel');
const mergeTrees = require('broccoli-merge-trees');
const BroccoliWorkbox = require('./lib/broccoli-workbox');
function mergeOptions(options, defaultOptions) {
for (const option in defaultOptions) {
if (!options.hasOwnProperty(option)) {
options[option] = defaultOptions[option];
}
}
return options;
}
module.exports = {
name: require('./package').name,
isDevelopingAddon: () => true,
config(env, baseConfig) {
const workboxOptions = baseConfig.workbox || {};
const options = baseConfig['ember-cli-workbox'] || {};
const projectName = baseConfig.APP && baseConfig.APP.name || 'app';
mergeOptions(workboxOptions, {
swDest: 'sw.js',
globDirectory: './',
globPatterns: ['**/*.{json,css,js,png,svg,eot,ttf,woff,jpg,gif,ico,xml,html,txt}'],
skipWaiting: false,
clientsClaim: false,
importWorkboxFrom: 'local',
cacheId: projectName
});
env = env || process.env.EMBER_ENV;
// Do nothing if no ENV. For example, when running an ember generator.
if (!env) {
return;
}
const isProdBuild = Boolean(env.match('prod'));
mergeOptions(options, {
enabled: isProdBuild,
debug: !isProdBuild
});
this.options = options;
this.workboxOptions = workboxOptions;
},
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
});
},
treeForPublic(tree) {
const assetsTree = new Funnel('public');
return mergeTrees([tree, assetsTree], {
overwrite: true
});
}
};