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
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
Share
Improve this question
edited Nov 9, 2015 at 22:55
Felix Kling
816k180 gold badges1.1k silver badges1.2k bronze badges
asked Nov 9, 2015 at 22:53
Zack ArgyleZack Argyle
8,4074 gold badges30 silver badges38 bronze badges
4 Answers
Reset to default 16Any 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.
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
Yes, you could install locally and run from node_modules
:
./node_modules/.bin/babel
If you have a local package.json you could add an NPM script to simplify the command, since NPM scripts run with ./node_modules/.bin
on the PATH
:
"scripts": {
"babel": "babel ...",
}
To run from any directory under package.json:
$ npm run babel
If you just want to run test with command "npm test testFile.js". This is my package.json:
"scripts": {
"build": "babel-node",
"test": "node_modules/.bin/babel-node"
}