最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - Using babel-cli locally - Stack Overflow

programmeradmin2浏览0评论

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
Add a comment  | 

4 Answers 4

Reset to default 16

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.

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"
}
发布评论

评论列表(0)

  1. 暂无评论