简体   繁体   English

如何使用 pm2 运行 grunt serve

[英]How to use pm2 to run grunt serve

my colleague passed me a project that you run grunt serve to start.我的同事给了我一个你运行 grunt serve 来启动的项目。 Now I'm trying to use pm2 to start the project in the background forever so I can close my command line.现在我正在尝试使用 pm2 永远在后台启动项目,以便我可以关闭我的命令行。 However, I couldn't find a right way to do it.但是,我找不到正确的方法来做到这一点。

I've seen answers like我见过这样的答案

cd /path/to/fullstack cd /path/to/fullstack

pm2 start grunt --name website -- serve pm2 start grunt --name website -- serve

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.我所知道的是 grunt serve 可以同时为我运行多个任务。

I know that if I know the base js file that creates a web server for my app such as index.js.我知道,如果我知道为我的应用程序创建 Web 服务器的基本 js 文件,例如 index.js。 I can just run pm2 start index.js.我可以只运行 pm2 start index.js。

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.我尝试使用 node index.js 运行基本文件,但它给了我一个错误,因为我需要同时运行 babel,这是由 grunt serve 完成的。

Can anyone help me to run grunt serve command using pm2?任何人都可以帮助我使用 pm2 运行 grunt serve 命令吗?

I advise you to create a ecosystem file and put these configs :我建议您创建一个生态系统文件并放置这些配置:

script: 'grunt' and scriptArgs: ['serve'] script: 'grunt'scriptArgs: ['serve']

For anyone wondering how to achieve this in 2019, here's the solution.对于想知道如何在 2019 年实现这一目标的任何人,这里是解决方案。 Leverage PM2 and PM2's Ecosystem File .利用 PM2 和PM2 的生态系统文件

First, create a file named ecosystem.config.js .首先,创建一个名为ecosystem.config.js .config.js 的文件。

Then, do something like this:然后,做这样的事情:

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
  }]
};

Then, just run:然后,只需运行:

pm2 start ecosystem.config.js

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM