指令碼
你可以定義可以在另一個指令碼之前或之後執行或觸發的指令碼。
{
"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
使用者定義的指令碼也支援預和後指令碼,如示例中所示的上方。