以下是我如何使 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' }
非常感谢帮助