Reputation: 308
I have a React app (CRA) that exceeds heroku's maximum slug size soft limit (300MB), so I use this solution to reduce the slug size:
heroku buildpacks:add https://github.com/opencounter/heroku-buildpack-post-build-clean.git
.slug-post-clean
at the project root:src
public
node_modules
But, as the same time, I'm serving my app using serve, package.json
:
...
"dependencies": {
...
"serve": "^12.0.1",
...
},
...
"scripts" : {
"start": "serve -s build",
}
Excluding node_modules
altogether will also exclude serve
, making heroku unable to serve my app.
How to reduce heroku slug size while whitelisting 'serve' and its dependencies ?
For now, I'm excluding some big independent packages (e.g. @mui
, @testing-library
, etc.), but that's a bit hacky.
Upvotes: 0
Views: 564
Reputation: 391
Try to use heroku-cleanup
command in your package.json
like this:
script: {
"start": "serve -s build",
"heroku-cleanup": "rm -rf node_modules src"
}
It's not necessary any buildpack, you can see more information in heroku support page: https://devcenter.heroku.com/articles/nodejs-support
Upvotes: 1
Reputation: 308
After excluding node-modules/.cache
, the slug size has been reduced down 90% (~400M). So the solution is quite simple:
In .slug-post-clean
, add:
node-modules/.cache
Upvotes: 0