安装“全局"文件通过package.json的npm依赖 [英] Installing "global" npm dependencies via package.json
问题描述
我有一些全局"依赖项(jshint,csslint,buster等),当通过npm install
安装我的软件包时,我希望通过命令行自动安装并执行这些依赖项.这可能吗?
I have a few "global" dependencies (jshint, csslint, buster, etc..) that I'd like to have automatically installed and executable via the command line when my package is installed via npm install
. Is this possible?
当前,我正在手动执行以下操作:
Currently, I'm doing the following manually:
-
npm install -g <package_name>
- 在我的项目中:
npm link <package_name>
npm install -g <package_name>
- from within my project:
npm link <package_name>
更新:
刚遇到npm的此功能请求.看来package.json中的scripts
配置是可行的方法?
Update:
Just came across this feature request for npm. It seems like the scripts
config within package.json is the way to go?
再次更新: 或者,在阅读 npm文档之后,也许我应该使用
Update Again: Or, after reading the npm docs, maybe I'm supposed to use a .gyp file? I'm confused.
推荐答案
不可能从package.json
中将依赖项指定为全局".而且,这是设计使然,因为艾萨克在该功能请求中声明您引用:
It's not possible to specify dependencies as "global" from a package.json
. And, this is by design as Isaac states in that feature request you referenced:
是的,我们永远不会这样做.
Yeah, we're never going to do this.
但是,在本地安装软件包时,仍然可以使用二进制文件".它们将位于.../node_modules/.bin/
中.并且,您应该能够使用 preinstall
脚本将它们排队
But, "binaries" can still be used when a package is installed locally. They'll be in .../node_modules/.bin/
. And, you should be able to queue them up with a preinstall
script.
但是,如果一系列命令相当冗长(如" jshint,csslint,buster等."将建议),则您可能希望使用诸如 grunt
来执行各种任务:
Though, if the series of commands is rather lengthy (as "jshint, csslint, buster, etc.." would suggest), you may want to look into using a build tool such as grunt
to perform the various tasks:
{
// ...,
"scripts": {
"preinstall": "grunt"
}
}
这篇关于安装“全局"文件通过package.json的npm依赖的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!