I use browserize + gulp + babel in my project and have problems with ES7 features. This is what I installed:
- babel-plugin-transform-async-to-generator@6.8.0
- babel-plugin-transform-decorators-legacy@1.3.4 // for using decorators
- babel- polyfill @ 6.9.1
- babel-preset-es2015@6.9.0
- babel-preset-es2016@6.11.0
- babel-preset-stage-0@6.5.0
- babelify@7.3.0
- browserify@13.0.1
- gulp
- gulp -sourcemaps
- vinyl buffer
- vinyl source stream
and this is my gulp code:
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}`));
});
and this is my js code:
import 'babel-polyfill';
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'));
When I try to do this, an error message appears:
Unprepared ReferenceError: restoreatorRuntime not defined
import . Webpack, , , , .
, , babel-preset-es2015 babel-preset-es2016 , . es2015, ES6? babel-preset-stage-0, , , ES7. babel-preset-es2016?