LoginSignup
4
3

More than 5 years have passed since last update.

babel 6 やってみる

Posted at

なんかバージョンが上がってやり方が変わったようです。

まずはバベルをグローバルにインストール。

npm install --global babel-cli

とりあえず初期化して、

npm init

プリセットというやつを入れる。

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

で、エディタで.babelrcなるファイルを作る。

vim .babelrc

中身はこんなの。

{
  "presets": ["es2015"]
}

サンプル用のjsを書く。

vim sample.js

とりあえずクラスとかで。

sample.js
"use strict";

class Person {
    constructor(name) {
        this.name = name;
    }

    greet() {
        console.log("Hello, I'm " + this.name);
    }
}

var bob = new Person("Bob");
bob.greet();

で、バベル実行。

babel sample.js -o sample-compiled.js

nodeで実行してみる。

node sample-compiled.js

いいんじゃないすかー。

4
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
4
3