grunt uglify 不接受 lambda 或箭头函数
grunt uglify does not accept lambda or arrow functions
我是 运行 grunt-contrib-uglify v 2.15.1。当我使用 lambda 或箭头函数时失败:
Running "uglify:admin" (uglify) task
{ message: 'SyntaxError: Unexpected token: operator (>)',
filename: 'admin-app-ng.js',
line: 4927,
col: 50,
pos: 216049,
stack: 'Error\n at new JS_Parse_Error (eval at <anonymous>
如果我删除 lambda,那么 uglify 就会起作用。
在使用 lambdas/arrow 函数时有没有办法使用 uglify?
这是箭头函数:
myService.getActions($scope.myVar, (type) => (type === 'myType')?true:false);
箭头函数是ES6的特性,Uglify不支持ES6,所以你的ES6需要先转ES5才能进行Uglifi。
当您使用 grunt 时,您可以添加另一个任务 - 在 grunt-contrib-uglify
之前 - 将您的 JavaScript 源代码从 ES6 转换为 ES5。 Babel can be used to do this and there is a Babel grunt plugin.
我是 运行 grunt-contrib-uglify v 2.15.1。当我使用 lambda 或箭头函数时失败:
Running "uglify:admin" (uglify) task
{ message: 'SyntaxError: Unexpected token: operator (>)',
filename: 'admin-app-ng.js',
line: 4927,
col: 50,
pos: 216049,
stack: 'Error\n at new JS_Parse_Error (eval at <anonymous>
如果我删除 lambda,那么 uglify 就会起作用。 在使用 lambdas/arrow 函数时有没有办法使用 uglify?
这是箭头函数:
myService.getActions($scope.myVar, (type) => (type === 'myType')?true:false);
箭头函数是ES6的特性,Uglify不支持ES6,所以你的ES6需要先转ES5才能进行Uglifi。
当您使用 grunt 时,您可以添加另一个任务 - 在 grunt-contrib-uglify
之前 - 将您的 JavaScript 源代码从 ES6 转换为 ES5。 Babel can be used to do this and there is a Babel grunt plugin.