GulpUglifyError:无法通过Browserify缩小JavaScript错误

我将这个脚本与Browserify + Babel捆绑在一起,如下所示:

function buildJs() {
    let bopts = {
        paths: [
            `${SRC}/js`,
            './config'
        ],
        debug: !isProduction
    };
    let opts = Object.assign({}, watchify.args, bopts);
    let b = watchify(persistify(opts));

    b.add(`${SRC}/js/index.js`)
    .on('update', bundle)
    .on('log', gutil.log)
    .external(vendors)
    .transform(babelify, { 
        presets: ["es2015", "react"],
        plugins: [
            "syntax-async-functions",
            "transform-regenerator",
            "transform-class-properties",
            "transform-decorators-legacy",
            "transform-object-rest-spread",
            "transform-react-jsx-source",
            staticFs
        ]
    })
    .transform(browserifyCss, { global: true });

    function bundle() {
        let stream = b.bundle()
        .on('error', swallowError)
        .on('end', () => {
            gutil.log(`Building JS:bundle done.`);
        })
        .pipe(source('bundle.js'))
        .pipe(streamify(uglify()));

        return stream.pipe(gulp.dest(`${DIST}/js`));
    }

    return bundle();
}

这只是浏览 - > babelify - > browserify-css - > uglify - > gulp.dest。 但是如果我运行这个任务,它会失败:

[17:00:30] Using gulpfile ~/ctc-web/gulpfile.js
[17:00:30] Starting 'build'...
[17:00:46] 1368516 bytes written (16.43 seconds)
[17:00:46] Building JS:bundle done.

events.js:160
      throw er; // Unhandled 'error' event
      ^
GulpUglifyError: unable to minify JavaScript
    at createError (/home/devbfex/ctc-web/node_modules/gulp-uglify/lib/create-error.js:6:14)
    at wrapper (/home/devbfex/ctc-web/node_modules/lodash/_createHybrid.js:87:15)
    at trycatch (/home/devbfex/ctc-web/node_modules/gulp-uglify/minifier.js:26:12)
    at DestroyableTransform.minify [as _transform] (/home/devbfex/ctc-web/node_modules/gulp-uglify/minifier.js:79:19)
    at DestroyableTransform.Transform._read (/home/devbfex/ctc-web/node_modules/readable-stream/lib/_stream_transform.js:159:10)
    at DestroyableTransform.Transform._write (/home/devbfex/ctc-web/node_modules/readable-stream/lib/_stream_transform.js:147:83)
    at doWrite (/home/devbfex/ctc-web/node_modules/readable-stream/lib/_stream_writable.js:338:64)
    at writeOrBuffer (/home/devbfex/ctc-web/node_modules/readable-stream/lib/_stream_writable.js:327:5)
    at DestroyableTransform.Writable.write (/home/devbfex/ctc-web/node_modules/readable-stream/lib/_stream_writable.js:264:11)
    at Transform.ondata (_stream_readable.js:555:20)

只要跳过uglify作品,但我真的需要它。

奇怪的是,结束事件后发生错误。 我尝试使用乙烯基缓冲区,但同样的错误发生。

我找不到任何解决方案,我的每一次尝试都会失败,并显示相同的错误消息。

我错过了什么? 有没有我错过的东西?


尝试用var替换let ,看看会发生什么。

链接地址: http://www.djcxy.com/p/32933.html

上一篇: GulpUglifyError: unable to minify JavaScript error with Browserify

下一篇: Have to run gulp more than once to get Style changes