forked from ember-cli/ember-cli-terser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
66 lines (52 loc) · 1.76 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
'use strict';
module.exports = {
name: require('./package').name,
included(app) {
this._super.included.apply(this, arguments);
let defaultOptions = {
enabled: app.env === 'production',
terser: {
compress: {
// this is adversely affects heuristics for IIFE eval
'negate_iife': false,
// limit sequences because of memory issues during parsing
sequences: 30,
},
mangle: {
safari10: true
},
output: {
// no difference in size and much easier to debug
semicolons: false,
},
}
};
if (app.options.sourcemaps && !this._sourceMapsEnabled(app.options.sourcemaps)) {
defaultOptions.terser.sourceMap = false;
}
let addonOptions = app.options['ember-cli-terser'];
if ('ember-cli-uglify' in app.options) {
this.ui.writeWarnLine('[ember-cli-terser] Passing options as `ember-cli-uglify` in `ember-cli-build.js` is deprecated, please update to passing `ember-cli-terser` (with a `terser` property) instead.');
addonOptions = Object.assign({}, app.options['ember-cli-uglify'], { terser: app.options['ember-cli-uglify'].uglify, uglify: undefined });
}
this._terserOptions = Object.assign({}, defaultOptions, addonOptions);
},
_sourceMapsEnabled(options) {
if (options.enabled === false) {
return false;
}
let extensions = options.extensions || [];
if (extensions.indexOf('js') === -1) {
return false;
}
return true;
},
postprocessTree(type, tree) {
if (this._terserOptions.enabled === true && type === 'all') {
const Terser = require('broccoli-terser-sourcemap');
return new Terser(tree, this._terserOptions);
} else {
return tree;
}
}
};