Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Using babel-cli locally

Is there a way to use the babel client without installing it globally?

So rather than this

npm install -g babel-cli

I'd like to do this

npm install babel-cli --save-dev
like image 809
Zack Argyle Avatar asked Nov 09 '15 22:11

Zack Argyle


2 Answers

Any local package's binary can be accessed inside npm scripts as if it was installed globally:

// package.json
{
   "scripts": {
     "build": "babel ..."
   }
}

If you want to execute the binary on the command line, you can use a relative path to node_modules/.bin/:

$ node_modules/.bin/babel ...

This is related to first example: node_modules/.bin/ is simple added to the PATH of the environment the npm scripts are executed in.

like image 68
Felix Kling Avatar answered Sep 19 '22 13:09

Felix Kling


you can put something like this:

{
  "scripts": {
     "start": "babel-node test.js"
  }
}

in your package.json where test.js is a script which you want to run. Now you can run it with npm start command

like image 28
kharandziuk Avatar answered Sep 21 '22 13:09

kharandziuk