From a677533e43f703436d7c8f302efb0ca2dc416224 Mon Sep 17 00:00:00 2001 From: alexlamsl Date: Tue, 16 May 2017 03:26:18 +0800 Subject: [PATCH] upgrade to uglify-js 3.0.5 bump to clean-css 4.1.2 --- Gruntfile.js | 18 ++++++++++++++++++ package.json | 9 ++++----- src/htmlminifier.js | 16 +++++----------- 3 files changed, 27 insertions(+), 16 deletions(-) diff --git a/Gruntfile.js b/Gruntfile.js index 07b36d6..caf4790 100644 --- a/Gruntfile.js +++ b/Gruntfile.js @@ -30,7 +30,25 @@ module.exports = function(grunt) { src: { options: { banner: '<%= banner %>', + preBundleCB: function() { + var fs = require('fs'); + var UglifyJS = require('uglify-js'); + var files = {}; + UglifyJS.FILES.forEach(function(file) { + files[file] = fs.readFileSync(file, 'utf8'); + }); + fs.writeFileSync('./dist/uglify.js', UglifyJS.minify(files, { + compress: false, + mangle: false, + wrap: 'exports' + }).code); + }, + postBundleCB: function(err, src, next) { + require('fs').unlinkSync('./dist/uglify.js'); + next(err, src); + }, require: [ + './dist/uglify.js:uglify-js', './src/htmlminifier.js:html-minifier' ] }, diff --git a/package.json b/package.json index 86a2f12..8e565e9 100644 --- a/package.json +++ b/package.json @@ -55,22 +55,21 @@ }, "dependencies": { "camel-case": "3.0.x", - "clean-css": "4.0.x", + "clean-css": "4.1.x", "commander": "2.9.x", "he": "1.1.x", "ncname": "1.0.x", "param-case": "2.1.x", "relateurl": "0.2.x", - "uglify-js": "~2.8.22" + "uglify-js": "3.0.x" }, "devDependencies": { "grunt": "1.0.x", "grunt-browserify": "5.0.x", - "grunt-contrib-uglify": "2.3.x", + "grunt-contrib-uglify": "3.0.x", "gruntify-eslint": "3.1.x", "phantomjs-prebuilt": "2.1.x", - "qunitjs": "2.x", - "uglify-to-browserify": "1.0.x" + "qunitjs": "2.x" }, "benchmarkDependencies": { "brotli": "1.3.x", diff --git a/src/htmlminifier.js b/src/htmlminifier.js index 318e0ad..db2c56a 100644 --- a/src/htmlminifier.js +++ b/src/htmlminifier.js @@ -676,23 +676,17 @@ function processOptions(options) { if (typeof minifyJS !== 'object') { minifyJS = {}; } - minifyJS.fromString = true; (minifyJS.parse || (minifyJS.parse = {})).bare_returns = false; options.minifyJS = function(text, inline) { var start = text.match(/^\s*\s*$/, '') : text; - try { - minifyJS.parse.bare_returns = inline; - code = UglifyJS.minify(code, minifyJS).code; - if (/;$/.test(code)) { - code = code.slice(0, -1); - } - return code; - } - catch (err) { - options.log(err); + minifyJS.parse.bare_returns = inline; + var result = UglifyJS.minify(code, minifyJS); + if (result.error) { + options.log(result.error); return text; } + return result.code.replace(/;$/, ''); }; } -- 2.34.1