Stop Heroku from Pruning Dev Dependencies

Viewed 2789

I have been trying to stop heroku from pruning my dev dependencies. Here is my config: My build script is: "build": "NPM_CONFIG_PRODUCTION=false webpack -mode production" And I have added "heroku-postbuild": "npm run build" My Dependencies:

"dependencies": {
    "express": "^4.16.3",
    "react": "^16.5.2",
    "react-dom": "^16.5.2"
  },
  "devDependencies": {
    "@babel/core": "^7.0.0",
    "@babel/plugin-proposal-class-properties": "^7.0.0",
    "@babel/preset-env": "^7.0.0",
    "@babel/preset-react": "^7.0.0",
    "babel-eslint": "^10.0.0",
    "babel-loader": "^8.0.0",
    "clean-webpack-plugin": "^0.1.19",
    "concurrently": "^4.0.0",
    "css-loader": "^1.0.0",
    "eslint": "^5.0.0",
    "eslint-config-airbnb": "^17.0.0",
    "eslint-plugin-import": "^2.11.0",
    "eslint-plugin-jsx-a11y": "^6.0.3",
    "eslint-plugin-react": "^7.7.0",
    "file-loader": "^2.0.0",
    "html-webpack-plugin": "^3.2.0",
    "nodemon": "^1.17.3",
    "style-loader": "^0.23.0",
    "url-loader": "^1.0.1",
    "webpack": "^4.5.0",
    "webpack-cli": "^3.0.8",
    "webpack-dev-server": "^3.1.3"
  }

I would appreciate any help with the config as I don't want to add my dev dependencies to my dependencies.

2 Answers

Set Heroku env var NPM_CONFIG_PRODUCTION to false with

heroku config:set NPM_CONFIG_PRODUCTION=false

instead of trying to set it in your npm script. See docs.

If you are trying to red the error during production caused by devDependencies, just do this in node.js or similar in the language you are using.

if (process.env.NODE_ENV !== "production") {
  require(<devDependency>)
}
Related