Reputation: 8407
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
Upvotes: 8
Views: 7554
Reputation: 523
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"
}
Upvotes: 0
Reputation: 816462
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.
Upvotes: 16
Reputation: 12890
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
Upvotes: 2
Reputation: 30330
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
Upvotes: 0