How to use Grunt/Gulp with pm2?

后端 未结 2 711
一向
一向 2020-12-30 12:44

pm2 is a great tool to manage node apps. How does it work with grunt/glup ? I didn\'t find any useful clues after Googling for 20 minutes.

2条回答
  •  一整个雨季
    2020-12-30 13:10

    If I understand your question well, it seems you want to deploy your app.

    Since pm2 0.9 deployment can be done with pm2 deploy see README.

    In the case of grunt/gulp, I see two options:

    1. You've your node_modules comitted. Using pm2 deploy run your gulp process from the post-deploy section:

      "post-deploy" : "node ./node_modules/gulp/bin/gulp.js ./GulpFile.js && pm2 startOrRestart ecosystem.json --env production"
      
    2. Using a basic script that will launch npm install for you, you could use the package.json to grunt/gulp:

      "scripts": {
          "test": "echo \"Error: no test specified\" && exit 1",
          "start": "node server.js",
          "postinstall": "./node_modules/bower/bin/bower -q -s -f install && ./node_modules/gulp/bin/gulp.js"
      },
      

    My gulp generally needs bower to minify scripts so I left it only for example purpose.

    You may combine the two options to let pm2 deploy install your npm scripts and have a postinstall script in the package.json.

    Note that I'm using the relative path to the gulp module binary! It's just to avoid an issue if the global module is not installed.

    Now, in my opinion to deploy an application in production it's better to simply have a git branch where everything is pre-gulped so that you only clone that branch and you're good to go. It also improves the deploy time, especially if you're running tests with gulp or grunt...

    Hope that's clear enough!

提交回复
热议问题