脚本
你可以定义可以在另一个脚本之前或之后执行或触发的脚本。
{
"scripts": {
"pretest": "scripts/pretest.js",
"test": "scripts/test.js",
"posttest": "scripts/posttest.js"
}
}
在这种情况下,你可以通过运行以下任一命令来执行脚本:
$ npm run-script test
$ npm run test
$ npm test
$ npm t
预定义的脚本
脚本名称 | 描述 |
---|---|
prepublish |
在包发布之前运行。 |
发布,发布后 | 包发布后运行。 |
预装 | 在安装软件包之前运行。 |
安装,postinstall | 安装软件包后运行。 |
预安装,卸载 | 在卸载软件包之前运行。 |
postuninstall |
卸载软件包后运行。 |
preversion,版本 | 碰撞包版本之前运行。 |
postversion |
碰撞包版本后运行。 |
预测试,测试,后测 | 由 npm test 命令运行 |
prestop,stop,poststop | 由 npm stop 命令运行 |
预启动,开始,后期启动 | 由 npm start 命令运行 |
prerestart,restart,postrestart | 由 npm restart 命令运行 |
用户定义的脚本
你也可以使用与预定义脚本相同的方式定义自己的脚本:
{
"scripts": {
"preci": "scripts/preci.js",
"ci": "scripts/ci.js",
"postci": "scripts/postci.js"
}
}
在这种情况下,你可以通过运行以下任一命令来执行脚本:
$ npm run-script ci
$ npm run ci
用户定义的脚本也支持预和后脚本,如示例中所示的上方。