Converting es6 script to JS using gulp

久未见 提交于 2019-12-08 13:46:22

问题


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

const hello = (name) => {
    return `hello ${name}`; 
};

Guiding me to convert the ES6 code to vanilla JS would be most appreciated.


回答1:


You're probably using Babel 7, and your preset is not compatible with it. You should install and use { presets: ["@babel/preset-env"] }.



来源:https://stackoverflow.com/questions/54087389/converting-es6-script-to-js-using-gulp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!