diff --git a/lib/build.js b/lib/build.js index f151736..b842952 100644 --- a/lib/build.js +++ b/lib/build.js @@ -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'); @@ -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'; @@ -334,7 +336,6 @@ module.exports = function(type, unit, watcher, options, done) { waterfall([ // Minify commons components function (next) { - minify( outputCommonsJsFile, _.extend({optimize: true},uglifyOptions), @@ -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(); @@ -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 = {}; @@ -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}`) ); } diff --git a/package.json b/package.json index e4696db..247aee2 100644 --- a/package.json +++ b/package.json @@ -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"