Getting Started with Babel 6

Project Files

You can click here to download the project files.

Set up

First, it is a good idea to uninstall the babel-cli if installed globally:

npm uninstall --global babel-cli

Also make sure that you are running Node > 4 and npm > 3.

As always, first you need a package file. Run the following and accept all the defaults:

npm init

install the modules

npm install --save-dev babel-cli babel-preset-es2015 babel-polyfill

make the .babelrc file

touch .babelrc

and add the following:

{
  "presets": ["es2015"]
}

Add some code in the src folder:

mkdir src
touch src/main.js
echo "const fn = () => { return 5; }" > src/main.js 

And then run the following to transpile all the contents of the src folder into the lib folder:

./node_modules/.bin/babel src -d lib

It should then create the output in the lib folder for each file.