loewydesign / loewy-assets

A front-end asset pipeline driven by gulp.js.
MIT License
12 stars 3 forks source link

Implement Babel for JS task #8

Open agopshi opened 8 years ago

agopshi commented 8 years ago

Let's implement the Babel transpiler for the JS task. Should a simple one-line addition in tasks/js.js (before the concat call). Extract the Babel options in config.js.babel, and provide sensible defaults (like { presets: ['es2015'] }).

agopshi commented 8 years ago

@dan-ld Make sure to include the runtime (see https://www.npmjs.com/package/gulp-babel#runtime and https://babeljs.io/docs/plugins/transform-runtime/).

agopshi commented 8 years ago

@dan-ld Let's make this configurable. If config.js.babel is set to false, don't run the JS through the Babel compiler. This way, we can disable it for legal projects.

agopshi commented 8 years ago

When you implement this, make sure it's working by writing some simple ES2015 and running it in the browser after Loewy Assets compiles it. E.g.

// using const
const arr1 = [1, 2, 3],
    arr2 = [4, 5, 6];

// using spread operator to combine arrays
const combined = [...arr1, ...arr2];
console.log(combined); // should be [1, 2, 3, 4, 5, 6]

// using arrow functions
const double = x => 2 * x;

console.log(double(3)); // should be 6

Feel free to try other features as well.