Skip to content

Commit

Permalink
Merge pull request #1118 from stealjs/terser
Browse files Browse the repository at this point in the history
Replace uglify-es with terser
  • Loading branch information
m-mujica committed Mar 18, 2019
2 parents 504d11d + cb444c7 commit f091485
Show file tree
Hide file tree
Showing 8 changed files with 18 additions and 10 deletions.
4 changes: 2 additions & 2 deletions doc/types/build-options.md
Expand Up @@ -69,9 +69,9 @@ using `//!steal-remove-start`, and `//!steal-remove-end` comments.
All available options are listed in the [clean-css documentation](https://github.com/jakubpawlowicz/clean-css#how-to-use-clean-css-programmatically).

@option {Object} [uglifyOptions] A hash of options to customize the minification of JavaScript files. StealTools uses the
top-level `minify` function of uglify-js, and the available options are listed [here](https://github.com/mishoo/UglifyJS2#minify-options).
top-level `minify` function of terser-js, and the available options are listed [here](https://github.com/terser-js/terser#minify-options).

For example, to not uglify function names you can use [keep_fnames option](https://github.com/mishoo/UglifyJS2#mangle-options):
For example, to not uglify function names you can use [keep_fnames option](https://github.com/terser-js/terser#mangle-options):

```javascript
stealTools.build(config, {
Expand Down
4 changes: 2 additions & 2 deletions lib/build_types/uglify.js
Expand Up @@ -2,7 +2,7 @@ var assign = require("lodash/assign");
var isFunction = require("lodash/isFunction");

function uglify(source, options) {
var UglifyJS = require("uglify-es");
var Terser = require("terser");

var code = source.code;
var existingSourceMap = source.map;
Expand All @@ -23,7 +23,7 @@ function uglify(source, options) {
uglifyOptions.sourceMap = sourceMap;
}

return UglifyJS.minify(code, uglifyOptions);
return Terser.minify(code, uglifyOptions);
}

function getRawSourceMap(map) {
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -35,11 +35,11 @@
"steal-bundler": "^0.3.6",
"steal-parse-amd": "^1.0.0",
"steal-rollup": "^0.58.4",
"terser": "^3.17.0",
"through2": "^3.0.0",
"tmp": "0.0.33",
"traceur": "0.0.111",
"transpile": "^2.7.0",
"uglify-es": "3.1.3",
"urix": "^0.1.0",
"winston": "^2.2.0",
"ws": "^5.1.1",
Expand Down
10 changes: 9 additions & 1 deletion test/minify/config.js
@@ -1,9 +1,17 @@
System.paths.foo = "bar";

function getKeysOf(obj) {
return Object.keys(obj);
}

// make sure this file is minified, too.
// The code below is used to assert uglify-js can take options
var anotherLongObjectName = {
bar: "baz"
};
module.exports = anotherLongObjectName;

// this line prevents the minifier to inline the variable in the export,
// which breaks the test where we make sure steal can pass option down to terser
getKeysOf(anotherLongObjectName);

module.exports = anotherLongObjectName;
2 changes: 1 addition & 1 deletion test/multibuild_test.js
Expand Up @@ -245,7 +245,7 @@ describe("multi build", function(){
});
});

it("should allow setting uglify-js options", function() {
it("should allow setting terser-js options", function() {
var config = {
config: path.join(__dirname, "minify", "config.js"),
main: "minify"
Expand Down
2 changes: 1 addition & 1 deletion test/slim/basics/main-size.snap
@@ -1 +1 @@
module.exports = 260;
module.exports = 255;
2 changes: 1 addition & 1 deletion test/slim/plugins/main-size.snap
@@ -1 +1 @@
module.exports = 311;
module.exports = 308;
2 changes: 1 addition & 1 deletion test/slim/progressive/main-size.snap
@@ -1 +1 @@
module.exports = 893;
module.exports = 879;

0 comments on commit f091485

Please sign in to comment.