私のプロジェクトでは、browserify + gulp + babelを使用していますが、ES7機能に問題があります。これらは私がインストールされて何をしている:babel ES7 Async - regeneratorRuntimeが定義されていません
- [email protected]
- [email protected] //使用デコレータのための
- [email protected]
- [email protected]
- [email protected]
- [email protected]
- babelify @ 7.3.0
- [email protected]
- グッ
- グッ-sourcemaps
- ビニルバッファ
- ビニルソースストリーム
、これは私のグッコードである:
gulp.task('build',() => {
let buildPath;
let destPath;
buildPath = `./src`;
destPath = `./dist`;
return browserify(`${buildPath}/app.js`)
.transform(babelify, {
presets: ["es2015", "es2016", "stage-0"],
plugins: ["transform-decorators-legacy", "transform-async-to-generator"]
})
.bundle()
.pipe(source('app.js'))
.pipe(buffer())
.pipe(sourcemaps.init({loadMaps: true}))
.pipe(sourcemaps.write('./'))
.pipe(gulp.dest(`${destPath}`));
});
これは私のjsコードです:
import 'babel-polyfill';
// Async Functions
function wait(t) {
return new Promise((r) => setTimeout(r, t));
}
async function asyncMania() {
console.log('1');
await wait(1000);
console.log('2');
}
asyncMania().then(() => console.log('3'));
私はこれをしようとすると、エラーを取得:を使用して
Uncaught ReferenceError: regeneratorRuntime is not defined
はどちらか動作しませんの代わりインポートする必要があります。ほとんどの質問はWebpackを使用しています。ブラウザではなく、他の方法が私には効果がなかったので、どうすればいいのか教えてください。
もう1つの質問があります。ご覧のとおり、babel-preset-es2015とbabel-preset-es2016の両方をインストールしていて、どちらも使用しています。 es2015プラグインを削除しても、引き続きES6機能を使用できますか?また、バベルプリセットステージ0も含まれています。これは実験的なES7機能のためのものです。実際に何をbabel-preset-es2016が得られましたか?
**変換、再生器**プラグインと**変換-非同期機能**、まだ動作しません。 :( – modernator