Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Migration to ES6

Is there any way to migrate ES5 code to ES6? I searched for some examples regarding the fact of using latest Node.js and it always gave me an error even with harmony flag. Error included message that there are invalid syntax even for "let" keyword. I wrote to console v8 options and seems everything is turned on..

I'm trying to migrate my framework http://twee.io

like image 433
Dmitriy Avatar asked Sep 28 '22 15:09

Dmitriy


1 Answers

ES5 code will work along side of ES6 code already. For nodejs just install babel core:

npm install babel-core --save

and you'll also need npm install babel-preset-es2015 --save

create a .babelrc file with the following:

{
    "presets": [ "es2015"],
    "ignore": "node_modules"
}

run your node app via, (assumes your file is app.js)

babel-node app

alternatively you can add require('babel-core/register'); at the top of your node project and any code below will be transpiled with babel...

a recommended way is to create something like main.js with the following contents:

require('babel-core/register');
require('./app.js');

then just run node main.

like image 162
glued Avatar answered Oct 03 '22 03:10

glued