forked from ember-cli/ember-cli-terser
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (48 loc) · 1.37 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
'use strict';
module.exports = {
name: 'ember-cli-uglify',
included(app) {
this._super.included.apply(this, arguments);
const defaults = require('lodash.defaultsdeep');
let defaultOptions = {
enabled: app.env === 'production',
async: true, // run uglify in parallel
uglify: {
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.uglify.sourceMap = false;
}
this._options = defaults(app.options['ember-cli-uglify'] || {}, defaultOptions);
},
_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._options.enabled === true && type === 'all') {
return require('broccoli-uglify-sourcemap')(tree, this._options);
} else {
return tree;
}
}
};