Inspired by this issue, with these instructions you should be able to get Babel transpiling your JS in Sails JS for the client side.
- Install Grunt Babel
npm install --save grunt-babel
- Create a
babel.js
file undertasks/config
and add something like the following:
module.exports = function(grunt) {
grunt.config.set('babel', {
dev: {
files: [{
expand: true,
cwd: 'assets/js/',
src: ['**/*.js', '!dependencies/**/*.js'],
dest: '.tmp/public/js/',
ext: '.js'
}]
}
});
grunt.loadNpmTasks('grunt-babel');
};
It's up to you, but I'm not touching the dependencies folder.
- Since Babel copies the JS over, update the
copy:dev
tasks'ssrc
to excludejs
(copy.js
undertasks/config
). It should looks something like this:
src: ['**/*.!(coffee|less|js)'],
- Update both
compileAssets.js
andsyncAssets.js
undertasks/config
to include the Babel dev task:'babel:dev'
That should do it. Try running sails lift --verbose
to see if Babel is running, and then try writing some fancy ES6! If I'm missing something please advise.
Thanks for the clear instructions.
es2015 preset does not handle Promise so the code like "foo = new Promise(...)" is passed through and of course IE 11 barfs on it. Any suggestion about how to get polyfill to work in the above setup? Thx.