gpt4 book ai didi

javascript - 使用 PM2 监控 Gruntjs 任务运行程序,可能吗?

转载 作者:行者123 更新时间:2023-11-29 21:40:58 25 4
gpt4 key购买 nike

我一直在创建一个 angularjs 应用程序并添加 Gruntjs 作为它的任务运行器..

所以每当我尝试运行我的应用程序时,我都会转到项目目录并运行一个 Grunt 任务,它是 grunt server。该命令由以下代码组成

grunt.registerTask('server',
'start a web server with extras',
function (target)
{
if (target === 'dist')
{
return grunt.task.run(['build', 'connect:dist:keepalive']);
}

grunt.task.run([
'clean:server',
'concurrent:server',
'connect:livereload',
'watch'
]);
}
);

我的项目经理给了我一项新任务,即使用 pm2 控制 grunt 服务器

因此,每当 grunt server 任务崩溃时,它将再次重新启动。是否可以使用 pm2 ?因为 AFAIK pm2 是 Node.js 的生产过程管理器所以我真的不知道它是否适用于 Grunt 但我知道 Gruntjs 是使用 npm 安装的

最佳答案

我已经设法做到了..显然解决方案很简单

首先运行pm2生态系统,它会生成一个ecosystem.json

并用这个选项填充它

{
"name": "management-app", //this is optional
"script": "grunt", // the script that will be run
"args": ["server"] //argument of the script
}

提供ecosystem.json的配置文件后,运行即可

pm2 启动 ecosystem.json 瞧!结果很好!开始喜欢这个组件了!

关于javascript - 使用 PM2 监控 Gruntjs 任务运行程序,可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32947277/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com