很遺憾,沒有什麼區別,比如postInstall
和postInstallDev
。儘管如此,你可以創建一箇中間腳本來處理差異。例如,如果您有以下幾點:
"scripts": { "postinstall": "node postInstall.js" },
然後在這個腳本,你可以從那裏檢查環境變量和執行正確的步兵任務:
// postInstall.js
var env = process.env.NODE_ENV;
if (env === 'development') {
// Spawn a process or require the Gruntfile directly for the default task.
return;
}
if (env === 'production') {
// Spawn a process or require the Gruntfile directly to the prod task.
return;
}
console.error('No task for environment:', env);
process.exit(1);
兩三週相關穴位..
- 儘量不要讓Grunt和co。作爲
dependencies
。請將它們保存到devDependencies
以避免必須在生產中安裝所有這些東西。在上面的香草節點中有一箇中間腳本可以讓你做到這一點。我喜歡使用這樣的postInstall腳本來安裝git鉤子腳本(但也僅限於開發環境)。
- 您不必使用
./node_modules/grunt/bin/grunt default
。如果grunt-cli
是dependency
或devDependency
,npm知道在哪裏看,grunt default
將正常工作。
我也在想這個。在我的情況下,我只是想在Heroku上安裝時不運行任務。 –