繁体   English   中英

如何使用 pm2 运行 grunt serve

[英]How to use pm2 to run grunt serve

我的同事给了我一个你运行 grunt serve 来启动的项目。 现在我正在尝试使用 pm2 永远在后台启动项目,以便我可以关闭我的命令行。 但是,我找不到正确的方法来做到这一点。

我见过这样的答案

cd /path/to/fullstack

pm2 start grunt --name website -- serve

但我不太明白,而且我对咕噜声知之甚少。 我所知道的是 grunt serve 可以同时为我运行多个任务。

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

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

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

我建议您创建一个生态系统文件并放置这些配置:

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

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

首先,创建一个名为ecosystem.config.js .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

暂无
暂无

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

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