boot-to-es6-node v0.0.3
#Boot to ES6
Demo project using ES6, transpile to ES5 during using babel
Recently I tried to build a small React UI libary, in order to publish it to npm registry, I need to convert all my modules from ES6 to ES5 CommonJS modules. In frontend, I choose webpack to load all dependencies and transpile my modules using babel-loader. For backend, I tried to follow the method found in this blog http://jlongster.com/Backend-Apps-with-Webpack--Part-I, but it turn out I can't use webpack because webpack can't output module that I want. you can execute the output module, but it's not a nodejs module.
First, add babel and grunt-babel to devDependencies:
npm install --save-dev babel
And transpile es6 source to es5 source.
babel: {
"options": {
"sourceMap": true,
"stage": 2
},
dist: {
files: [
{
"expand": true,
"cwd": "src/",
"src": ["**/*.js"],
"dest": "build/lib",
"ext": ".js"
},
]
}
}
Note: stage: 0,2,3,4 value explained here: https://babeljs.io/docs/usage/experimental/
Last, I publish this module to npm:
npm adduser
npm publish ./
After done this, I can use this npm module in my other project now :)