All notes
Babel

babel-cli

babeljs.io: cli.

Quick start


# Always run babel-cli in a local environment.
npm init
npm install --save-dev babel-cli

# Remove babel-cli if it is installed globally.
npm uninstall --global babel-cli

# Error: Unexpected token import
# https://stackoverflow.com/questions/33604470/unexpected-token-import-in-nodejs5-and-babel
# Since Babel is focusing on being a platform for JavaScript tooling and not an ES2015 transpiler, we’ve decided to make all of the plugins opt-in. This means when you install Babel it will no longer transpile your ES2015 code by default.
# To make it transpile ES6:
npm install -S babel-preset-es2015
# or with yarn
yarn add babel-preset-es2015 --dev
# And enabled the preset in .babelrc
# {
#   "presets": ["es2015"]
# }

# Then you should use babel-node to run es6 scripts:
# https://stackoverflow.com/questions/36417585/how-to-execute-es6-scripts-from-cli
# Babel comes with a CLI babel-node which works exactly the same as Node.js's CLI, only it will compile ES6 code before running it.
babel-node myscript.js

Command line


babel script.js -o script-compiled.js --presets=es2015,react