【发布时间】:2016-03-23 13:16:21
【问题描述】:
我正在尝试使用 gulp-uglify 压缩我的项目,但是 gulp 似乎在遇到代码中的箭头函数时会抛出错误 Unexpected token: punc ()。我能做些什么来解决这个问题吗?谢谢。
gulp-crash-test.js
// Function with callback to simulate the real code
function test(callback) {
if (typeof callback === "function") callback();
}
// Causes a crash
test(() => {
console.log("Test ran successfully!");
});
// Doesn't cause a crash
test(function () {
console.log("Test ran successfully!");
});
gulpfile.js
var gulp = require("gulp");
var concat = require("gulp-concat");
var uglify = require("gulp-uglify");
gulp.task("scripts", function() {
gulp.src([
"./gulp-crash-test.js"
]).pipe(
concat("gulp-crash-test.min.js")
).pipe(
uglify().on('error', function(e){
console.log(e);
})
).pipe(
gulp.dest("./")
);
});
gulp.task("watch", function() {
gulp.watch("./gulp-crash-test.js", ["scripts"]);
});
gulp.task("default", ["watch", "scripts"]);
【问题讨论】:
-
你可以在你的 gulpfile.js 中练习箭头函数。但首先检查你的 node.js 版本。
标签: javascript gulp ecmascript-6 gulp-uglify