【发布时间】:2015-10-05 07:36:33
【问题描述】:
问题:如何在 ES6 中编写我的 gulp 文件,以便我可以使用 import 而不是 require 并使用 => 语法而不是 function()?
我可以使用 io.js 或 node 任何版本。
gulpfile.js:
import gulp from "./node_modules/gulp/index.js";
gulp.task('hello-world', =>{
console.log('hello world');
});
错误:
import gulp from "./node_modules/gulp/index.js";
^^^^^^
SyntaxError: Unexpected reserved word
gulp.task('hello-world', =>{
^^
SyntaxError: Unexpected token =>
在node_modules/gulp/bin/gulp.js 内,我已将第一行更改为#!/usr/bin/env node --harmony,正如stack 中所要求的那样
【问题讨论】:
-
正如提到的(但未在下面接受的答案中特别指出)第二个示例的正确语法是
gulp.task('foo', () => {...})这应该在 NodeJS 4 和 5 开箱即用的 AFAIK 中工作。跨度>
标签: javascript node.js gulp ecmascript-6