I'm getting Heroku warnings about my slug size being too big:
-----> Compressing...
Done: 304.9M
-----> Launching...
! Warning: Your slug size exceeds our soft limit (304 MB) which may affect boot time.
How can I reduce my slug size? It's a .NET Core 2.1.401 and Angular 6 app, so I'm using the following buildpacks:
- dotnetcore-buildpack;
- heroku-nodejs
- heroku-buildpack-apt
Running heroku run "du . -h --max-depth=3 --threshold=1M"
yields the following result:
2.5M ./App/obj
524M ./App/ClientApp/node_modules
16M ./App/ClientApp/dist
9.4M ./App/ClientApp/src
549M ./App/ClientApp
2.5M ./App/bin/Release
3.3M ./App/bin
556M ./App
16M ./heroku_output/ClientApp/dist
16M ./heroku_output/ClientApp
130M ./heroku_output
189M ./.heroku/dotnet/sdk
140M ./.heroku/dotnet/shared
329M ./.heroku/dotnet
27M ./.heroku/node/lib
3.0M ./.heroku/node/include
34M ./.heroku/node/bin
63M ./.heroku/node
391M ./.heroku
11M ./.apt/usr/lib
3.3M ./.apt/usr/include
15M ./.apt/usr
15M ./.apt
1.1G .
The bulk is in node_modules/
(524M), ./heroku/dotnet/
(329M) and ./heroku_output
(130M).
I don't think I can use a .slugignore
file, because the node_modules
folder is required for the build process, so I tried deleting the node_modules/
folder after dotnet publish
using this entry in the app's .csproj
, but it didn't reduce the slug size.
<Target Name="CleanupNodeModules" AfterTargets="Publish">
<Exec WorkingDirectory="$(SpaRoot)" Command="rm -rf node_modules" Condition=" '$(OS)' != 'Windows_NT' " ConsoleToMSBuild="true" />
</Target>
Any ideas?
I created a pull request to build the .NET Core project as a self-contained
exe
and delete the .NET Core SDK afterwards.With that, I passed from a 304MB to a 149MB slug size!
Looks like
node_modules
has no effect...