1 | 'use strict';
|
2 |
|
3 | module.exports = {
|
4 | name: 'ember-cli-uglify',
|
5 |
|
6 | included(app) {
|
7 | this._super.included.apply(this, arguments);
|
8 |
|
9 | const defaults = require('lodash.defaultsdeep');
|
10 |
|
11 | let defaultOptions = {
|
12 | enabled: app.env === 'production',
|
13 | async: true,
|
14 |
|
15 | uglify: {
|
16 | compress: {
|
17 |
|
18 | 'negate_iife': false,
|
19 |
|
20 | sequences: 30,
|
21 | },
|
22 | mangle: {
|
23 | safari10: true
|
24 | },
|
25 | output: {
|
26 |
|
27 | semicolons: false,
|
28 | },
|
29 | }
|
30 | };
|
31 |
|
32 | if (app.options.sourcemaps && !this._sourceMapsEnabled(app.options.sourcemaps)) {
|
33 | defaultOptions.uglify.sourceMap = false;
|
34 | }
|
35 |
|
36 | this._options = defaults(app.options['ember-cli-uglify'] || {}, defaultOptions);
|
37 | },
|
38 |
|
39 | _sourceMapsEnabled(options) {
|
40 | if (options.enabled === false) {
|
41 | return false;
|
42 | }
|
43 |
|
44 | let extensions = options.extensions || [];
|
45 | if (extensions.indexOf('js') === -1) {
|
46 | return false;
|
47 | }
|
48 |
|
49 | return true;
|
50 | },
|
51 |
|
52 | postprocessTree(type, tree) {
|
53 | if (this._options.enabled === true && type === 'all') {
|
54 | return require('broccoli-uglify-sourcemap')(tree, this._options);
|
55 | } else {
|
56 | return tree;
|
57 | }
|
58 | }
|
59 | };
|