Setup Babel for ES6
Before ES6 is widely adopted by browsers, we need to use Babel (https://babeljs.io) transpiling ES6 to ES5.
Step-by-step guide
Babel can be integrated with our WebStrom IDE (https://babeljs.io/docs/setup/#installation), but I personally prefer to run the transpiler in the Terminal window.
Install Babel
npm install babel-cli babel-preset-es2015
an alternative way is to configure package.json and then run npm install
package.json{ "name": "my-babel", "version": "1.0.0", "devDependencies": { "babel-cli": "latest", "babel-preset-es2015": "latest" } }
Configure Presets. You can run command line to specify the presets using --presets es2015. Another way which I prefer to use is adding .babelrc instead, or you can configure Babel in "babel": {} hash within the above package.json (https://babeljs.io/docs/usage/babelrc/).
.babelrc{ "presets": [ "es2015" ] }
Run babel script.js -o output.js (https://babeljs.io/docs/usage/cli/)
Related Code Snippets:
https://bitbucket.org/snippets/cpmsdev/nMonn/es6-transplier-environment-set-up-using
Related articles
http://stackoverflow.com/questions/33440405/babel-file-is-copied-without-being-transformed#