Skip to content

Commit

Permalink
[FEATURE] Switch to Terser for JavaScript minification
Browse files Browse the repository at this point in the history
`uglify-es` is no longer maintained:
mishoo/UglifyJS#3156 (comment)

Terser is a maintained fork of uglify-es, which is used by most of the
existing bundling tools.
  • Loading branch information
matz3 committed Jul 31, 2019
1 parent ae0ef66 commit fccb514
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 29 deletions.
4 changes: 2 additions & 2 deletions lib/lbt/bundle/AutoSplitter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"use strict";

const uglify = require("uglify-es");
const terser = require("terser");
const {pd} = require("pretty-data");

const ModuleName = require("../utils/ModuleName");
Expand Down Expand Up @@ -199,7 +199,7 @@ class AutoSplitter {
let fileContent = await resource.buffer();
if ( this.optimize ) {
// console.log("uglify %s start", module);
const result = uglify.minify({
const result = terser.minify({
[resource.name]: String(fileContent)
}, {
warnings: false, // TODO configure?
Expand Down
4 changes: 2 additions & 2 deletions lib/lbt/bundle/Builder.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// for consistency of write calls, we generally allow template literals
"use strict";

const uglify = require("uglify-es");
const terser = require("terser");
const {pd} = require("pretty-data");
const esprima = require("esprima");
const escodegen = require("escodegen");
Expand Down Expand Up @@ -323,7 +323,7 @@ class BundleBuilder {

compressJS(fileContent, resource) {
if ( this.optimize ) {
const result = uglify.minify({
const result = terser.minify({
[resource.name]: String(fileContent)
}, {
warnings: false, // TODO configure?
Expand Down
4 changes: 2 additions & 2 deletions lib/processors/uglifier.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const uglify = require("uglify-es");
const terser = require("terser");
const copyrightCommentsPattern = /copyright|\(c\)(?:[0-9]+|\s+[0-9A-za-z])|released under|license|\u00a9/i;

/**
Expand All @@ -13,7 +13,7 @@ const copyrightCommentsPattern = /copyright|\(c\)(?:[0-9]+|\s+[0-9A-za-z])|relea
module.exports = function({resources}) {
return Promise.all(resources.map((resource) => {
return resource.getString().then((code) => {
const result = uglify.minify({
const result = terser.minify({
[resource.getPath()]: code
}, {
warnings: false,
Expand Down
37 changes: 18 additions & 19 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@
"rimraf": "^2.6.3",
"semver": "^6.3.0",
"slash": "^3.0.0",
"uglify-es": "^3.2.2",
"terser": "^4.1.2",
"xml2js": "^0.4.17",
"yazl": "^2.5.1"
},
Expand Down
6 changes: 3 additions & 3 deletions test/lib/lbt/bundle/AutoSplitter.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
const test = require("ava");
const sinon = require("sinon");
const uglify = require("uglify-es");
const terser = require("terser");
const {pd} = require("pretty-data");
const BundleResolver = require("../../../../lib/lbt/bundle/Resolver");
const AutoSplitter = require("../../../../lib/lbt/bundle/AutoSplitter");
Expand Down Expand Up @@ -178,7 +178,7 @@ test("_calcMinSize: js resource", async (t) => {


test.serial("_calcMinSize: uglify js resource", async (t) => {
const stubUglify = sinon.stub(uglify, "minify").returns({code: "123"});
const stubTerser = sinon.stub(terser, "minify").returns({code: "123"});
const pool = {
findResourceWithInfo: function() {
return {
Expand All @@ -194,7 +194,7 @@ test.serial("_calcMinSize: uglify js resource", async (t) => {
const autpSplitter = new AutoSplitter(pool);
autpSplitter.optimize = true;
t.deepEqual(await autpSplitter._calcMinSize("mymodule.js"), 3);
stubUglify.restore();
stubTerser.restore();
});

test("_calcMinSize: properties resource", async (t) => {
Expand Down

0 comments on commit fccb514

Please # to comment.