使用gulp将es6脚本转换为JS [英] Converting es6 script to JS using gulp
本文介绍了使用gulp将es6脚本转换为JS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用gulp中的babel将ES6代码转换为简单的JS.运行以下代码,我收到消息[插件"gulp-babel错误"]:[插件/预设文件不允许导出对象,只能导出功能.]
I am trying to convert the ES6 code to simple JS, using babel in gulp. Running the below code I am getting [Error in Plugin "gulp-babel"] with Message: [Plugin/Preset files are not allowed to export objects, only functions.]
var gulp = require('gulp');
var babel = require('gulp-babel');
gulp.task('scripts',function(){
return gulp.src(['src/scripts/app.js'])
.pipe(babel({presets:['es2015']}))
.pipe(gulp.dest('build/scripts/'))
});
src/scripts/app.js
src/scripts/app.js
const hello = (name) => {
return `hello ${name}`;
};
非常感谢您指导我将ES6代码转换为原始JS.
Guiding me to convert the ES6 code to vanilla JS would be most appreciated.
推荐答案
您可能正在使用Babel 7,并且您的预设与其不兼容.您应该安装并使用{ presets: ["@babel/preset-env"] }
.
You're probably using Babel 7, and your preset is not compatible with it. You should install and use { presets: ["@babel/preset-env"] }
.
这篇关于使用gulp将es6脚本转换为JS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文