我一直在创建一个 angularjs 应用程序并将 Gruntjs 添加为它的任务运行程序..
因此,每当我尝试运行应用程序时,我都会转到项目目录并运行一个 Grunt 任务,即 grunt 服务器
。该命令由以下代码组成
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 start Ecosystem.json
瞧!结果太棒了!开始喜欢这个组件!
关于javascript - 使用 PM2 监控 Gruntjs 任务运行程序,可能吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32947277/