I am trying to install a Rails 6 app to Heroku with Webpacker
The git push heroku command seems to trigger the whole build proces
The node.js is invoked successfully and completes.
devDependencies then get pruned apparently.
Then the ruby buildpack kicks in which installs all of the ruby gems and "detects rake tasks" during which it runs rake assets:precompile
Then I get:
Compilation failed:
CLI for webpack must be installed.
webpack-cli (https://github.com/webpack/webpack-cli)
I am pretty sure I need to run
bin/rails webpacker:install
somewhere before asset compilation starts, but there is no chance to customise the build script as there is with node.js package.json script hooks for prebuild and postbuild from what I can see and I just end up with:
Precompiling assets failed.
Push rejected, failed to compile Ruby app.
So how am I supposed to get around this and get webpacker installed properly before heroku tries to compile the assets?
I think the solution is that because I am running 2 buildpacks in sequence, node.js followed by ruby, I need to prevent the node.js buildpack from pruning the devdependencies (ie webpack) defined in package.json as:
"devDependencies": {
"webpack-cli": "^4.3.1",
"webpack-dev-server": "^3.11.1"
},
by:
echo Setting Heroku to not prune dev dependencies
heroku config:set NPM_CONFIG_PRODUCTION=false YARN_PRODUCTION=false
The net result is I think that when the ruby buildpack comes to call the assets:precompile rake task that the webpacker CLI is still installed whereas previously it was not.