http://sanwen.net/a/ybsfcoo.html
/** * Created by udi on 2016/11/24. */ var gulp = require(‘gulp‘); var babel = require(‘gulp-babel‘); var es7SrcJs = ["es7/*/*.js"]; var descPath = "src"; gulp.task(‘babelify‘, function () { return gulp.src(es7SrcJs) .pipe(babel({ presets: [‘es2015‘, ‘es2016‘, ‘es2017‘], plugins: [["transform-runtime", { "polyfill": false, "regenerator": true }]] })) .pipe(gulp.dest(descPath)) .on(‘error‘, function (err) { console.log(err.stack); this.emit(‘end‘); }) }); gulp.task(‘watch‘, function(){ return gulp.watch(es7SrcJs, [‘babelify‘]); }); gulp.task(‘default‘, [‘babelify‘, ‘watch‘]);
test.js
var abc = o=>{ return 1;} var sleep = function (time) { return new Promise(function (resolve, reject) { setTimeout(function () { resolve(); }, time); }) }; var start = async function () { // 在这里使用起来就像同步代码那样直观 console.log(‘start‘); await sleep(3000); console.log(‘end‘); }; start();
运行 : gulp 即可。
原文:http://www.cnblogs.com/newsea/p/6097253.html