Writing a Gulpfile in ES6

March 30, 2016 0 Comments babel, gulp, Javascript, Code

So you've written your app in ES6 and you're using babel to transpile to ES5.

But your build process uses Gulp and it requires you to write your Gulpfile in ES5 meaning you can't take advantage of all the latest JavaScript features you're using elsewhere in your project.

What do you do?

You could go down the route of requiring in the babel register at the top of your Gulpfile to get it to transpile on the fly.

require('babel-register');  

But there is some built in functionality in Gulp which allows your to name your Gulpfile gulpfile.babel.js.

Doing this will make Gulp look for a .babelrc and run your gulpfile via babel to get all the latest ES6/7 goodies you're using in the rest of your codebase.