[英]Using babel-cli locally
Is there a way to use the babel client without installing it globally? 有没有办法在没有全局安装的情况下使用babel客户端?
So rather than this 所以而不是这个
npm install -g babel-cli
I'd like to do this 我想这样做
npm install babel-cli --save-dev
Any local package's binary can be accessed inside npm scripts as if it was installed globally: 可以在npm脚本中访问任何本地包的二进制文件,就好像它是全局安装的一样:
// 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/
的相对路径:
$ 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. 这与第一个示例有关:
node_modules/.bin/
是简单地添加到执行npm脚本的环境的PATH中。
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. 在你的
package.json
, test.js
是你想要运行的脚本。 Now you can run it with npm start
command 现在您可以使用
npm start
命令运行它
Yes, you could install locally and run from node_modules
: 是的,您可以在本地安装并从
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
: 如果你有一个本地的package.json,你可以添加一个NPM 脚本来简化命令,因为NPM脚本在
PATH
上运行./node_modules/.bin
:
"scripts": {
"babel": "babel ...",
}
To run from any directory under package.json: 要从package.json下的任何目录运行:
$ npm run babel
If you just want to run test with command "npm test testFile.js". 如果您只想使用命令“npm test testFile.js”运行测试。 This is my package.json:
这是我的package.json:
"scripts": {
"build": "babel-node",
"test": "node_modules/.bin/babel-node"
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.