4

例如,如果在我的 package.json 中,我有这个:

 "dependencies": {
     "cacheman": "2.1.0"   }

它可以工作,当我执行 npm install 时,它会触发 cacheman 中的构建脚本。

但是,如果我这样做:

 "dependencies": {
     "cacheman": "https://github.com/cayasso/cacheman.git"   }

它行不通。npm install 不会触发 cacheman 的构建过程。

这是为什么?

4

1 回答 1

5

您所指的脚本是在将 npm 模块发布到 npm 注册表之前运行的预发布脚本。在这里查看package.json#L9

此处显示的摘录

"scripts": {
    "test": "make test",
    "prepublish": "make"
}

当您从 github 安装它时,没有发布步骤,因此脚本不会运行。

如果您只想从 github 安装并运行脚本,您可以将其添加为 cacheman 的 postinstall 脚本(如果您不是 cacheman 的所有者,则必须派生 repo 以进行更改)

"scripts": {
    "test": "make test",
    "prepublish": "make",
    "postinstall": "make"//Added postinstall
}

查看npm 脚本文档中的示例以获取更多详细信息。

于 2016-01-28T09:32:26.483 回答