我在官方gulp-uglify npm 页面上看到了以下内容。
注意建议:
为了帮助正确处理节点流的错误情况,该项目建议使用pump。有关更多信息,请参阅为什么使用泵?.
我对上页示例的实现是:
gulpfile.js
var gulp = require('gulp');
var pump = require('pump');
// the npm page states:
// can be a git checkout or another module
// (such as `uglify-js-harmony` for ES6 support)
var uglifyjs = require('uglify-js-harmony');
var minifier = require('gulp-uglify/minifier');
var concat = require('gulp-concat');
gulp.task('compress', function (cb) {
// the 'options' argument is included in the example,
// but i don't know what it does or how it can be removed
var options = {
preserveComments: 'license'
};
pump([
gulp.src('my_scripts/*.js'), // gets all js scripts in this folder
minifier(options, uglifyjs),
concat('my_bundled_script.js'), // concatenates all scripts into this file
gulp.dest('dist') // puts the file into this folder
],cb
);
});
包.json
{
"devDependencies": {
"gulp": "latest",
"pump": "latest",
"gulp-concat": "latest",
"gulp-uglify": "latest",
"uglify-js-harmony": "latest"
},
"dependencies": {}
}
结果
不使用uglify-js-harmony
:
pump
有助于定位错误的来源(使用时gulp-uglify
)
- 有
let
语句的文件导致错误
使用时uglify-js-harmony
,没有出现错误。
其他注意事项:
上面的页面当前显示:
// can be a git checkout or another module
// (such as `uglify-js-harmony` for ES6 support)
var uglifyjs = require('uglify-js');
但是在安装时uglify-js-harmony
我收到了警告消息:
npm WARN 不推荐使用 uglify-js-harmony@2.7.7:不推荐使用以支持 uglify-es
但是,当我尝试使用uglify-es
而不是时uglify-js-harmony
,我收到一条错误消息,类似于此处记录的内容:
https://github.com/terinjokes/gulp-uglify/issues/287
我试图从那里关注问题线程,但迷路了,找不到如何实施的最终解决方案uglify-es
。