Skip to content

Commit

Permalink
Added Terser to minify es6 code
Browse files Browse the repository at this point in the history
  • Loading branch information
SonoIo committed Sep 30, 2020
1 parent 2dbd6de commit 6c2dd8e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions lib/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,8 @@ const browserify = require('browserify');
const watchify = require('watchify');
const fs = require('fs');
const path = require('path');
const UglifyJS = require('uglify-js');
// const UglifyJS = require('uglify-js');
const Terser = require('terser');
const jscrambler = require('jscrambler').default;
const bowerrcFile = path.resolve('.bowerrc');
const factor = require('factor-bundle');
Expand Down Expand Up @@ -111,6 +112,7 @@ module.exports = function(type, unit, watcher, options, done) {
case 'dist':
debug = false;
configs.env = 'production';
break;
case 'dev':
debug = true;
configs.env = 'development';
Expand Down Expand Up @@ -334,7 +336,6 @@ module.exports = function(type, unit, watcher, options, done) {
waterfall([
// Minify commons components
function (next) {

minify(
outputCommonsJsFile,
_.extend({optimize: true},uglifyOptions),
Expand Down Expand Up @@ -377,7 +378,9 @@ module.exports = function(type, unit, watcher, options, done) {
// Remove source map files
function (next) {
for (var i = 0; i < mapFiles.length; i++) {
fs.unlinkSync(mapFiles[i]);
try {
fs.unlinkSync(mapFiles[i]);
} catch(e) {}
// console.log( path.resolve(mapFiles[i]) );
}
return next();
Expand Down Expand Up @@ -416,7 +419,7 @@ module.exports = function(type, unit, watcher, options, done) {


// Function for minified
function minify( file, options, done ){
async function minify( file, options, done ){
if (_.isFunction(options)){
done = options;
options = {};
Expand All @@ -432,7 +435,7 @@ module.exports = function(type, unit, watcher, options, done) {
console.log(" minify file %s...".grey, file);
try {
var code = fs.readFileSync( file, {encoding: 'utf8'} );
var minify = UglifyJS.minify( code, options );
var minify = await Terser.minify( code, options );
} catch (e) {
return done( new Error(`Error on parse file ${e.filename}`) );
}
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@
"node-watch": "^0.6.3",
"optimize-js": "^1.0.3",
"realpathify": "^1.0.1",
"uglify-js": "^3.9.4",
"terser": "^5.3.3",
"underscore": "^1.9.1",
"underscore.string": "^3.3.5",
"watchify": "^3.11.1"
Expand Down

0 comments on commit 6c2dd8e

Please sign in to comment.