如果依赖性不是来自NPM,NPM安装不会触发babel构建

mur*_*lai 4 node.js npm babeljs npm-install

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

 "dependencies": {
     "cacheman": "2.1.0"   }
Run Code Online (Sandbox Code Playgroud)

它工作正常,当我进行npm安装时,它将触发缓存器内的构建脚本.

但是,如果我这样做:

 "dependencies": {
     "cacheman": "https://github.com/cayasso/cacheman.git"   }
Run Code Online (Sandbox Code Playgroud)

它不会起作用.npm install不会触发cacheman的构建过程.

这是为什么?

Vis*_*ath 5

您要引用的脚本是预发布脚本,该脚本在将npm模块发布到npm注册表之前运行.点击这里查看package.json#L9

这里显示的提取物

"scripts": {
    "test": "make test",
    "prepublish": "make"
}
Run Code Online (Sandbox Code Playgroud)

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

如果你只想从github安装并运行脚本,你可以将它添加为cacheman的postinstall脚本(如果你不是cacheman的所有者,你必须分叉repo进行更改).

"scripts": {
    "test": "make test",
    "prepublish": "make",
    "postinstall": "make"//Added postinstall
}
Run Code Online (Sandbox Code Playgroud)

有关详细信息,请查看npm脚本文档中的示例.