如何在gulpfile.js中使用babel-polyfill

Alt*_*ung 6 javascript node.js gulp

在Babel 文档中,他们只是说要包含import "babel-polyfill";以便我可以使用ES6生成器,但在我在gulpfile.js中包含该行后,我仍然会产生异常:Uncaught ReferenceError: regeneratorRuntime is not defined 这是我的gulpfile.js

import 'babel-polyfill';

var gulp = require("gulp"),
babel = require("gulp-babel"),
concat = require('gulp-concat'),
rename = require('gulp-rename'),
uglify = require('gulp-uglify');

gulp.task("babel", function() {
return gulp.src(jsSrc)
    .pipe(concat('Main.js'))
    .pipe(babel())
    .pipe(gulp.dest(jsDest))
    .pipe(rename('Main-min.js'))
    .pipe(uglify())
    .pipe(gulp.dest(jsDest));
});
Run Code Online (Sandbox Code Playgroud)

jsSrcmaines6.js和其他.js文件.在maines6.js这里是我的发电机:

function* anotherGenerator(i) {
  yield i + 1;
  yield i + 2;
  yield i + 3;
}
Run Code Online (Sandbox Code Playgroud)

我不知道怎么用这个..你能帮帮我吗?

ada*_*eck 1

要包含 Polyfill,您需要将其放在应用程序入口点的顶部。

import 'babel/polyfill'需要放在 jsSrc 条目文件的顶部