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?
Asked
Active
Viewed 872 times
2
-
1Use babel https://babeljs.io/ and polyfill for IE11 https://babeljs.io/docs/en/babel-polyfill – kiranvj Jun 01 '19 at 02:42
-
Never used either gulp or babel but a quick test shows that babel doesn't support the spaceship operator ("abc" <=> 42). – Jun 01 '19 at 03:28
-
@jeff there is no spaceship operator in JS (which OP is asking for and babeljs only transpiles) https://stackoverflow.com/questions/34852855/combined-comparison-spaceship-operator-in-javascript – dippas Jun 01 '19 at 13:05
-
@dippas, oops got my languages confused. – Jun 03 '19 at 05:06
1 Answers
6
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'))
);

SuperStar518
- 2,814
- 2
- 20
- 35

dippas
- 58,591
- 15
- 114
- 126