How to use pm2 to run grunt serve

∥☆過路亽.° 提交于 2020-01-24 19:55:22

问题


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.

I've seen answers like

cd /path/to/fullstack

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.

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.

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.

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


回答1:


I advise you to create a ecosystem file and put these configs :

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




回答2:


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

First, create a file named ecosystem.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


来源:https://stackoverflow.com/questions/41068364/how-to-use-pm2-to-run-grunt-serve

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!