oinume journal

Scratchpad of what I learned

Making an enviroment to learn ES6 with babel

This is a just memo for me who is a beginner of front-end development.

First of all, install nodejs v4.4.0.

$ brew install homebrew/versions/node4-lts
$ node -v
v4.4.0

Put package.json into a current directory. DO NOT forget to add babel-preset-es2015.

{
  "name": "hello",
  "version": "1.0.0",
  "engines": {
    "node": "4.4.0",
    "npm": "3.8.2"
  },
  "devDependencies": {
    "babel-cli": "^6.0.0",
    "babel-preset-es2015": "^6.6.0"
  }
}

Run npm install

$ npm install 

Put .babelrc to tell babel using es2015 preset.

echo '{ "presets": ["es2015"] }' > .babelrc

Put hello.js.

"use strict";

class Hello {
    say(message) {
        console.log(message);
    }
}

new Hello().say("hello");

Transpile hello.js and run it.

$ node_modules/.bin/babel hello.js | node
hello