newguy
newguy

Reputation: 5976

What is the correct PM2 command to serve a js file inside the webpack production build directory?

Suppose I have used webpack to bundle my codes into a directory named dist.

I did that with the command npm run build.

Here is my script section in package.json file:

"scripts": {
    "test": "mocha ./test/test*.js --recursive --compilers js:babel-core/register",
    "start": "node server",
    "build": "rimraf dist && cross-env NODE_ENV=production webpack --config ./webpack.production.config.js --progress --profile --colors",
    "eslint": "eslint .",
    "jscs": "jscs ."
},

If I want to use PM2 to start my app in production, which is named bundle.js, How can I do this?

Upvotes: 2

Views: 1677

Answers (1)

Alexandr Lazarev
Alexandr Lazarev

Reputation: 12892

You can set a process.json file, and specify there the file you need to run explicitly:

{
  apps : [{
    name        : "server",
    script      : "./dist/bundle.js",
    watch       : true,
    env: {
      "NODE_ENV": "development",
    },
    env_production : {
       "NODE_ENV": "production"
    }
  }]
}

Upvotes: 1

Related Questions