Skip to content

Instantly share code, notes, and snippets.

@victorkane
Last active November 22, 2015 16:16
Show Gist options
  • Save victorkane/dea1ae566272974180c6 to your computer and use it in GitHub Desktop.
Save victorkane/dea1ae566272974180c6 to your computer and use it in GitHub Desktop.
babel 6: trying out Immutable.js with node-babel from the command line
node_modules

The obsolete file .babelrc is now replaced with a babel section in package.json:

  "babel": {
    "presets": [
      "es2015"
    ]
  },

So to run babel-node i.js from the command line, all that is required is:

npm install -g babel-cli
npm install

Later you can add more presets, like

npm install -S babel-preset-stage-0

and the babel section of package.json becomes:

"babel": { "presets": [ "es2015", "stage-0" ] },

import {Map, List} from 'immutable';
var person1 = Map({
name: 'John',
birth: 594687600000,
phone: '12345678'
});
var person2 = Map({
name: 'Mary',
birth: 594689600300,
phone: '87654321'
});
var phoneBook = List.of(person1, person2);
console.log('person1 phone: ', person1.get('phone'));
console.log('person2 phone: ', person2.get('phone'));
console.log(phoneBook);
phoneBook.forEach(person => {
var n = person.get('name');
var p = person.get('phone');
console.log(n + ': ' + p);
});
{
"name": "try-immutable",
"version": "1.0.0",
"description": "",
"main": "i.js",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
},
"keywords": [],
"author": "",
"license": "ISC",
"babel": {
"presets": [
"es2015"
]
},
"dependencies": {
"babel-preset-es2015": "^6.1.18",
"immutable": "^3.7.5"
}
}
@victorkane
Copy link
Author

Revision 2 updates for babel 6.x.x (babel options specified in package.json babel section rather than in .babelrc)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment