Pm2: Use PM2 with Babel in dev, and ES5 in production

Created on 9 Apr 2016  路  2Comments  路  Source: Unitech/pm2

The tutorial gives examples of both a production- and a development way, but not combined. I'd like a single processes.json containing my apps, that supports running them in development with watch, babel-transpiler and cwd=src, where in production I'd like to enable logs and cwd=dist where the ES5 is located.

Am I taking a wrong approach here or is there a nice way to do this?

Question

Most helpful comment

Thank you for taking the time to answer my question. Since pm2 supports transpilation, watching and restarting I've chosen to make a processes-dev.json and processes-prod.json, with a seperate build script that is run before processes-prod.json is read.

All 2 comments

You may use a pre-processor that handles file transpilation + watch + restart. Then, use pm2 only for production.
Thing is, with an execution interpreter or a require hook, files won't be transpiled to new ES5 files, and therefore won't be able to use. In your case I'd add a Gulp process that:

  • watch for changes
  • restart pm2 if dev mode
  • babelize (or something like that)
  • writes to dist/

Then to handle dist / src, use environment variables.

Thank you for taking the time to answer my question. Since pm2 supports transpilation, watching and restarting I've chosen to make a processes-dev.json and processes-prod.json, with a seperate build script that is run before processes-prod.json is read.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

rajendar38 picture rajendar38  路  3Comments

getvega picture getvega  路  3Comments

liujb picture liujb  路  3Comments

lefam picture lefam  路  3Comments

morfies picture morfies  路  3Comments