Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Migrate to broccoli-terser-sourcemap. #228

Merged
merged 1 commit into from
Sep 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ var app = new EmberApp({

exclude: ['vendor.js'],

uglify: {
terser: {
compress: {
sequences: 50,
},
Expand All @@ -55,7 +55,7 @@ var app = new EmberApp({

- `exclude?: string[]`: A list of paths or globs to exclude from minification

- `uglify?: UglifyOptions`: A hash of [options](https://github.com/terser/terser#minify-options)
- `terser?: TerserOptions`: A hash of [options](https://github.com/terser/terser#minify-options)
that are passed directly to terser


Expand Down
20 changes: 14 additions & 6 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ module.exports = {
let defaultOptions = {
enabled: app.env === 'production',

uglify: {
terser: {
compress: {
// this is adversely affects heuristics for IIFE eval
'negate_iife': false,
Expand All @@ -29,10 +29,17 @@ module.exports = {
};

if (app.options.sourcemaps && !this._sourceMapsEnabled(app.options.sourcemaps)) {
defaultOptions.uglify.sourceMap = false;
defaultOptions.terser.sourceMap = false;
}

this._options = defaults(app.options['ember-cli-uglify'] || {}, defaultOptions);
let addonOptions = app.options['ember-cli-uglify'] || {};

if ('uglify' in addonOptions) {
this.ui.writeWarnLine('[ember-cli-uglify] Passing uglify in options is deprecated, please update to passing `terser` instead.');
addonOptions = Object.assign({}, addonOptions, { terser: addonOptions.uglify, uglify: undefined });
}

this._terserOptions = defaults(addonOptions, defaultOptions);
},

_sourceMapsEnabled(options) {
Expand All @@ -49,9 +56,10 @@ module.exports = {
},

postprocessTree(type, tree) {
if (this._options.enabled === true && type === 'all') {
const Uglify = require('broccoli-uglify-sourcemap');
return new Uglify(tree, this._options);
if (this._terserOptions.enabled === true && type === 'all') {
const Terser = require('broccoli-terser-sourcemap');

return new Terser(tree, this._terserOptions);
} else {
return tree;
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
"test": "ember test -e production"
},
"dependencies": {
"broccoli-uglify-sourcemap": "^4.0.0",
"broccoli-terser-sourcemap": "^4.1.0",
"lodash.defaultsdeep": "^4.6.1"
},
"engines": {
Expand Down
Loading