Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Babel CLI is extremely slow

So I follow the installation here, but babel takes very long time to compile, even small files:

app.js

let app = 1;

.babelrc

{ "presets": ["es2015"] }

package.json

"scripts": {
    "build": "babel app.js -o dist/app.js"
},
"devDependencies": {
    "babel-cli": "^6.4.5",
    "babel-preset-es2015": "^6.3.13"
}

Then npm run build will take ~30s to compile.

I'm using [email protected]

like image 962
hjrshng Avatar asked Feb 06 '16 18:02

hjrshng


2 Answers

You might be compiling node_modules and bower_components too.

You can try adding the ignore property in your projects .babelrc like so:

{
  ...
  "ignore": /(node_modules|bower_components)/
  ...
}

Hope this solves your issue

like image 160
Vineet 'DEVIN' Dev Avatar answered Nov 13 '22 20:11

Vineet 'DEVIN' Dev


Update September 2019

Found upgrading to Babel 7 solved this. Perhaps try:

$ npm install --save-dev @babel/core @babel/node @babel/preset-env

Your package.json should contain something like:

 "devDependencies": {
    "@babel/core": "^7.6.0",
    "@babel/node": "^7.6.1",
    "@babel/preset-env": "^7.6.0"
  }

My .babelrc file is as follows:

{
  "presets": ["@babel/preset-env"]
}

Now, when I run:

npx babel-node src/index.js

the performance is almost instantaneous (it was taking 20+ seconds with babel 6).

See the babel 7.5 docs for more details on this.

Also, for reference on the upgrade, see this stackoverflow question & answer.

like image 38
arcseldon Avatar answered Nov 13 '22 20:11

arcseldon