我正在尝试为我的项目对 npm 包进行测试,这样每次我尝试安装模块时,即运行 npm install <module>
在安装该模块之前必须运行一个脚本。预安装脚本仅适用于 npm install
而不是 npm install <module>
.
例如:- 如果运行 npm install request
.它应该运行一个脚本,在安装模块之前向我显示请求模块的所有依赖项。提前致谢。
最佳答案
在 package.json 的脚本部分添加 "install": "[Your Command]"
例子:
{
"name": "test",
"version": "1.0.0",
"description": "A sample test",
"main": "index.js",
"scripts": {
"install": "echo Test"
}
}
您还可以使用 pre hook使用 "preinstall": "[Your Command]"
关于javascript - 如何在安装任何 npm 模块之前运行脚本?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46725374/