与Reactify和Babelify一起使用时,Gulp-Uglify Parse Error

时间:2015-11-19 19:20:12

标签: javascript node.js gulp gulp-uglify

以下是我这样做的方法来改进JavaScript库:

var babelify = require("babelify");
var browserify = require('browserify');
var reactify = require('reactify');
var source = require('vinyl-source-stream');
var buffer = require('vinyl-buffer');
var uglify = require('gulp-uglify');

browserify(componentPath + "app.jsx")
    .transform(reactify)
    .transform(babelify)
    .bundle()
    .pipe(source('app.js'))
    .pipe(buffer())
    .pipe(uglify())
    .pipe(gulp.dest(buildPath));

这曾经有效,直到我最近将所有库更新到最新版本(这意味着我不知道问题是gulp-uglify还是reactify甚至{{1但这就是我得到的:

babelify

我跑了events.js:85 throw er; // Unhandled 'error' event ^ Error at new JS_Parse_Error (eval at <anonymous> (/Path/To/My/Application/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:1526:18) at js_error (eval at <anonymous> (/Path/To/My/Application/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:1534:11) at croak (eval at <anonymous> (/Path/To/My/Application/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:2025:9) at token_error (eval at <anonymous> (/Path/To/My/Application/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:2033:9) at unexpected (eval at <anonymous> (/Path/To/My/Application/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:2039:9) at expr_atom (eval at <anonymous> (/Path/To/My/Application/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:2534:13) at maybe_unary (eval at <anonymous> (/Path/To/My/Application/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:2708:19) at expr_ops (eval at <anonymous> (/Path/To/My/Application/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:2743:24) at maybe_conditional (eval at <anonymous> (/Path/To/My/Application/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:2748:20) at maybe_assign (eval at <anonymous> (/Path/To/My/Application/node_modules/gulp-uglify/node_modules/uglify-js/tools/node.js:24:4), <anonymous>:2772:20) ,这是输出:

uglify().on('error', gulpUtil.log)

非常感谢帮助

1 个答案:

答案 0 :(得分:0)

你已经开了个好头。根据调试日志,原始代码中的注释似乎没有被剥离。您应该在第41行结帐/path/to/my/application/app.js,看看有什么。

如果有评论,我建议您查看删除评论插件。就我而言,最近的gulp-strip-comments是根本原因。我把它换回旧版本,一切都恢复正常。