如何在pm2上使用Grunt / Gulp? [英] How to use Grunt/Gulp with pm2?
问题描述
我在Google搜寻20分钟后没有找到任何有用的线索。 看起来你想部署你的应用程序。
由于pm2 0.9
可以用 pm2 deploy
请参阅自述文件。
在grunt / gulp的情况下,我看到两个选项:
-
你已经完成了
node_modules
。使用pm2 deploy
从部署后
部分运行您的gulp流程:
post-deploy:node ./node_modules/gulp/bin/gulp.js ./GulpFile.js&&&&&2; start2rRestart ecos.json --env生产
-
使用基本脚本启动
npm install
为你,你可以使用package.json
来咕噜/ gulp:
<$ p $scripts:{
test:echo \错误:未指定测试\&& exit 1,
start: node server.js,
postinstall:./node_modules/bower/bin/bower -q -s -f install&& ./node_modules/gulp/bin/gulp.js
$,
以便将脚本缩小,所以我只将其留作示例。
您可以将两个选项合并为 pm2 deploy
安装 npm
脚本并安装 postinstall
script pt在 package.json中
。
请注意,我正在使用<$ c $的相对路径c> gulp 模块二进制文件!这只是为了避免一个问题,如果没有安装全局模块。
现在,在我看来,在生产环境中部署应用程序,最好只需要一个git分支,是预先吞噬,所以你只克隆该分支,你很好去。它还可以改善部署时间,特别是如果你正在运行测试时使用gulp或grunt ...
希望已经足够清楚了!
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.
Since pm2 0.9
deployment can be done with pm2 deploy
see README.
In the case of grunt/gulp, I see two options:
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"
Using a basic script that will launch
npm install
for you, you could use thepackage.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" },
My gulp generally needs bower to minify scripts so I left it only for example purpose.
You may combine the two options to let pm2 deploy
install your npm
scripts and have a postinstall
script in the package.json
.
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.
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?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!