如何使用PM2运行Grunt服务 [英] How to use pm2 to run grunt serve

查看:232
本文介绍了如何使用PM2运行Grunt服务的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的同事给我传递了一个项目,由您运行咕serve的服务来启动.现在,我尝试使用pm2永久在后台启动项目,以便关闭命令行.但是,我找不到正确的方法.

my colleague passed me a project that you run grunt serve to start. Now I'm trying to use pm2 to start the project in the background forever so I can close my command line. However, I couldn't find a right way to do it.

我见过类似的答案

cd/path/to/fullstack

cd /path/to/fullstack

pm2开始咕unt-名称网站-服务

pm2 start grunt --name website -- serve

但是我不太了解,我对咕unt声的了解也很少.我所知道的是,咕unt的服务对我来说同时执行多个任务.

but I don't quite understand and I have very little knowledge regarding grunt. All I know is that grunt serve runs multiple tasks at the same time for me.

我知道,如果我知道为我的应用程序创建Web服务器(例如index.js)的基本js文件.我可以只运行pm2 start index.js.

I know that if I know the base js file that creates a web server for my app such as index.js. I can just run pm2 start index.js.

我尝试使用节点index.js运行基本文件,但是它给我一个错误提示,因为我需要同时运行babel,这是由grunt服务完成的.

I tried to run the base file with node index.js, but it gives me an error cuz I need to run babel at the same time which is done by the grunt serve.

有人可以帮助我使用pm2运行grunt serve命令吗?

Can anyone help me to run grunt serve command using pm2?

推荐答案

对于任何想知道如何在2019年实现这一目标的人,这里都提供了解决方案.利用PM2和 PM2的生态系统文件.

For anyone wondering how to achieve this in 2019, here's the solution. Leverage PM2 and PM2's Ecosystem File.

首先,创建一个名为ecosystem.config.js的文件.

First, create a file named ecosystem.config.js.

然后,执行以下操作:

module.exports = {
  apps : [{
    name   : 'myapp', // the name of your app
    cwd    : '/path/to/myapp', // the directory from which your app will be launched
    script : '/usr/local/bin/grunt', // the location of grunt on your system
    args   : 'serve' // the grunt command
  }]
};

然后,运行:

pm2 start ecosystem.config.js

这篇关于如何使用PM2运行Grunt服务的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆