安装“全局"通过 package.json 的 npm 依赖 [英] Installing "global" npm dependencies via package.json

查看:25
本文介绍了安装“全局"通过 package.json 的 npm 依赖的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一些全局"依赖项(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:

  1. npm install -g <package_name>
  2. 在我的项目中: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 docs 之后,也许我应该使用 .gyp 文件?我很困惑.

Update Again: Or, after reading the npm docs, maybe I'm supposed to use a .gyp file? I'm confused.

推荐答案

无法从 package.json 将依赖项指定为全局".而且,这是按照 Isaac 您引用的功能请求中的陈述 设计的:

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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆