这是我的存储库 https://github.com/shellwe/QA_WP_Template
如果您只是需要查看代码段;这是
gulp.task('uglify', function() {
return gulp.src('js/all.min.js')
.pipe(uglify())
.pipe(gulp.dest('js/'));
});
我正在跑步" gulp uglify"我收到了以下错误。
events.js:160
throw er; // Unhandled 'error' event
^
Error
at new JS_Parse_Error (eval at <anonymous> (C:\Users\sh3240\Documents\My Web Sites\wordpress\wp-content\themes\QA_WP_Template\node_modules\uglify-js\tools\node.js:28:1), <anonymous>:1534:18)
at js_error (eval at <anonymous> (C:\Users\sh3240\Documents\My Web Sites\wordpress\wp-content\themes\QA_WP_Template\node_modules\uglify-js\tools\node.js:28:1), <anonymous>:1542:11)
at croak (eval at <anonymous> (C:\Users\sh3240\Documents\My Web Sites\wordpress\wp-content\themes\QA_WP_Template\node_modules\uglify-js\tools\node.js:28:1), <anonymous>:2089:9)
at token_error (eval at <anonymous> (C:\Users\sh3240\Documents\My Web Sites\wordpress\wp-content\themes\QA_WP_Template\node_modules\uglify-js\tools\node.js:28:1), <anonymous>:2097:9)
at unexpected (eval at <anonymous> (C:\Users\sh3240\Documents\My Web Sites\wordpress\wp-content\themes\QA_WP_Template\node_modules\uglify-js\tools\node.js:28:1), <anonymous>:2103:9)
at semicolon (eval at <anonymous> (C:\Users\sh3240\Documents\My Web Sites\wordpress\wp-content\themes\QA_WP_Template\node_modules\uglify-js\tools\node.js:28:1), <anonymous>:2123:56)
at simple_statement (eval at <anonymous> (C:\Users\sh3240\Documents\My Web Sites\wordpress\wp-content\themes\QA_WP_Template\node_modules\uglify-js\tools\node.js:28:1), <anonymous>:2314:73)
at eval (eval at <anonymous> (C:\Users\sh3240\Documents\My Web Sites\wordpress\wp-content\themes\QA_WP_Template\node_modules\uglify-js\tools\node.js:28:1), <anonymous>:2183:19)
at eval (eval at <anonymous> (C:\Users\sh3240\Documents\My Web Sites\wordpress\wp-content\themes\QA_WP_Template\node_modules\uglify-js\tools\node.js:28:1), <anonymous>:2136:24)
at eval (eval at <anonymous> (C:\Users\sh3240\Documents\My Web Sites\wordpress\wp-content\themes\QA_WP_Template\node_modules\uglify-js\tools\node.js:28:1), <anonymous>:2904:23)
我看到的大多数例子都在一个过程中进行了concat和uglify,但由于concat部分正在工作,我将它们拆开以显示出来。我知道uglify有问题,我无法弄清楚我做错了什么。
答案 0 :(得分:4)
你得到的错误并没有真正解释太多......但是,根据 gulp-uglify 的 npm.js 上的小“文档”,< / p>
为帮助使用节点流正确处理错误情况,本项目建议使用pump
您可以阅读gulp-uglify和pump。
所以,我尝试了以下内容:
# grab pump
npm install pump --save-dev
然后,在 gulpfile.js 中,我执行了以下操作:
gulp.task('uglify2', function (cb) {
pump([
gulp.src('./js/all.min.js'),
uglify(),
gulp.dest('./js/')
],
cb
);
});
我得到的错误,顺便提一下,比你得到的错误要好得多,如下:
问题似乎在线191,这表明您的代码存在问题,而不是 gulp任务。