I have an Angular v20 app with SSR enabled just for the prerendering and I'm hosting the site statically on Github Pages. I enabled Server Side Rendering in Angular just for the Static Site Rendering capability and now I'm going through exercises in shrinking the footprint of my app.
Issue:
When I use Webpack Bundle Analyzer to see what I can trim out or minify, I see the largest initial JS chunk by far I'm loading is 179.6kb in size and 103.2kb (57% of it) is something called:
node_modules/@angular/core/fesm2022/debug_node-DTOmNMDH.mjs.
The dependency chain that leads to it being imported is as follows:
The entry point: angular:main-server:angular:main-server
Imports this file: node_modules/@angular/core/fesm2022/core.mjs
Which imports this file: node_modules/@angular/core/fesm2022/debug_node-DTOmNMDH.mjs
The fact that this has the name "debug" in it even though it's in the production build AND it's import chain stems from the main.server.mjs file (part of the unused 'server' output that doesn't get uploaded to GitHub Pages) makes me think it's dead code and could be optimized out. This doesn't show up in apps compiled without SSR functionality present. Setting SSR to disabled in angular.json doesn't remove it either.
Setup:
1: Run ng new testapp --ssr
2: Run npm install webpack-bundle-analyzer
3: Modify production section of angular.json to have the following:
"projects" : {
"testapp": {
"architect": {
"build": {
"builder": "@angular/build:application",
"options": {
"server": "src/main.server.ts",
"outputMode": "static",
"ssr": false
},
"configurations": {
"production": {
"outputHashing": "all",
"sourceMap": false
},
},
"defaultConfiguration": "production"
}
}
}
}
4: Run
ng build --configuration=production --stats-json --verbose
5: Upload the generated stats.json file to https://esbuild.github.io/analyze/ and inspect the largest node listed under Initial Chunk Files during build output.
This will show the issue identically to what I see. It just seems like this is almost certainly dead code, right? There should be some way to fully remove SSR from Angular and keep the SSG features, right?
