简体   繁体   中英

Support older browsers with gulp

I want to support es6 syntax and new features of javascript all the way to IE11. I am using gulp in my project. Is there any way so that the new javascript gets transpiled to support older browsers?

You can use gulp-babel which is the package of the babeljs transpiler

by installing it like this: (for babel 7 )

$ npm install --save-dev gulp-babel @babel/core @babel/preset-env

the basic setup is something like this:

const gulp = require('gulp'),
  babel = require('gulp-babel');

gulp.task('default', () =>
  gulp.src('src/yourJSfile.js')
  .pipe(babel({
    presets: ['@babel/env'] // the minimum presets needed to make gulp-babel work in babel 7 - https://github.com/babel/gulp-babel/tree/v7-maintenance
  }))
  .pipe(gulp.dest('dist'))
);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM