問題描述
pm2 是管理節點應用的好工具.它如何與 grunt/glup 一起使用?谷歌搜索 20 分鐘后,我沒有找到任何有用的線索.
pm2 is a great tool to manage node apps. How does it work with grunt/glup ? I didn't find any useful clues after Googling for 20 minutes.
推薦答案
如果我理解你的問題,看來你想部署你的應用程序.
If I understand your question well, it seems you want to deploy your app.
由于 pm2 0.9
部署可以使用 pm2 deploy
參見自述文件.
Since pm2 0.9
deployment can be done with pm2 deploy
see README.
在 grunt/gulp 的情況下,我看到兩個選項:
In the case of grunt/gulp, I see two options:
你已經提交了你的
node_modules
.使用pm2 deploy
從post-deploy
部分運行您的 gulp 進程:
You've your
node_modules
comitted. Usingpm2 deploy
run your gulp process from thepost-deploy
section:
"post-deploy" : "node ./node_modules/gulp/bin/gulp.js ./GulpFile.js && pm2 startOrRestart ecosystem.json --env production"
使用將為您啟動 npm install
的基本腳本,您可以使用 package.json
來 grunt/gulp:
Using a basic script that will launch npm install
for you, you could use the package.json
to grunt/gulp:
"scripts": {
"test": "echo "Error: no test specified" && exit 1",
"start": "node server.js",
"postinstall": "./node_modules/bower/bin/bower -q -s -f install && ./node_modules/gulp/bin/gulp.js"
},
我的 gulp 通常需要 bower 來縮小腳本,所以我只保留它作為示例.
My gulp generally needs bower to minify scripts so I left it only for example purpose.
您可以結合這兩個選項讓 pm2 deploy
安裝您的 npm
腳本,并在 package 中有一個
.postinstall
腳本.json
You may combine the two options to let pm2 deploy
install your npm
scripts and have a postinstall
script in the package.json
.
請注意,我使用的是 gulp
模塊二進制文件的相對路徑!如果沒有安裝全局模塊,這只是為了避免出現問題.
Note that I'm using the relative path to the gulp
module binary! It's just to avoid an issue if the global module is not installed.
現在,在我看來,要在生產中部署應用程序,最好簡單地擁有一個 git 分支,其中所有內容都已預先打包,這樣您只需克隆該分支就可以了.它還可以縮短部署時間,尤其是當您使用 gulp 或 grunt 運行測試時...
Now, in my opinion to deploy an application in production it's better to simply have a git branch where everything is pre-gulped so that you only clone that branch and you're good to go. It also improves the deploy time, especially if you're running tests with gulp or grunt...
希望這已經足夠清楚了!
Hope that's clear enough!
這篇關于如何在 pm2 中使用 Grunt/Gulp?的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!