First of all, don't put your "npm run build" step in your Procfile.
Doing so will cause that step to run every time your web dyno restarts, which is not what you want.
Instead, you want to run webpack (or whatever else you need for making sure the dependencies you need are present in your app) during slug compilation.
By virtue of the fact that you are using the heroku/node.js buildpack, it will automatically take care of running "npm install" for you (or yarn install, if you choose to use the yarn package manager instead).
However, if you need more than npm/yarn install (e.g. if you need to run webpack to bundle client dependencies), then you need to provide the slug compiler with additional instructions for those steps. A good way to do that is by using heroku-specific build steps.
So, for example, you might want to run webpack in a heroku-postbuild step in your package.json "scripts", e.g.:
"heroku-postbuid" : "cross-env NODE_ENV=production WEBPACK_CONFIG=browser_prod,server_prod webpack --colors",
However, in addition you need to be aware that by default Heroku won't install any of your package.json devDependencies. So if you have webpack itself listed in devDependencies, you won't be able to use it in a heroku-postbuild step by default.
The way to workaround that is to either move webpack (together with any other build dependencies you need) to "dependencies" (instead of "devDependencies"), or to set config var NPM_CONFIG_PRODUCTION to false:
heroku config:set NPM_CONFIG_PRODUCTION=false
For more info, see here and here.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…