0

以下是我如何使 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甚至是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),这是输出:

{ [Error: /Path/To/My/Application/app.js: Unexpected token: punc ())]
message: '/Path/To/My/Application/app.js: Unexpected token: punc ())',
        fileName: '/Path/To/My/Application/app.js',
        lineNumber: 41,
        stack: 'Error\n    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)\n    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)\n    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)\n    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)\n    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)\n    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)\n    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)\n    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)\n    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)\n    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)',
        showStack: false,
        showProperties: true,
        plugin: 'gulp-uglify' }

非常感谢帮助

4

1 回答 1

0

你已经有了一个很好的开始。根据调试日志,原始代码中的注释似乎没有按预期删除。您应该在第 41 行结账/path/to/my/application/app.js,看看那里有什么。

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

于 2015-12-11T11:18:37.970 回答