I have something like that mounted on an app I'm working on. Then I mix things from Browserify and Babel because I import modules that I want to have in the client with npm. But the only Babel version might look like this:
"use strict";
var exec = require('child_process').exec;
function babel(){
return new Promise(resolve, reject){
exec('babel --presets es2015 js --out-dir public/js', {
cwd: __dirname + '/../'
}, (err) => {
if (err) reject(err);
else resolve();
});
});
}
module.exports = Promise.all([babel]);
I use Promise.all because I put in this array more things that I need to compile. You can chain with .then()
and call the cordoba compiler next if you are calling via command line.
In my folder I'm running this module in root/lib
, the original files are in root/js
and I'm compiling all files from .js
to root/public/js
.
Dependencies are:
"babel-cli": "^6.4.5",
"babel-preset-es2015": "^6.3.13",