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

[FEATURE] Switch to Terser for JavaScript minification #305

Merged
merged 1 commit into from
Jul 31, 2019
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 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");
const {SectionType} = require("./BundleDefinition");
Expand Down Expand Up @@ -197,7 +197,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 @@ -322,7 +322,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 @@ -115,7 +115,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 @@ -162,7 +162,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 @@ -177,7 +177,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