You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// On server, we don't want to compress anything. We still set the ngDevMode = false for it
// to remove dev code, and ngI18nClosureMode to remove Closure compiler i18n code
The reason being that, when buildOptions.platform == 'server' is true, the following object is passed to the TerserPlugincompress option:
However, according to the TerserPlugin's docs, most compress flags default to true, so this effectively causes the server code to be minified.
In addition, unsetting the scripts optimizations in angular.json causes other side effects, namely ngDevMode no longer being explicitly set to false, causing the server code to run in dev mode by default.
One workaround is to set the NG_BUILD_DEBUG_OPTIMIZE flag, which does turn off compress, but my concern is that it would get removed & renamed at some point since it's undocumented.
I think compress should be set to false for server builds, as per the code comment currently reads, as working with minified code on the server is a pain. It would cause server-side bundles to jump in size, e.g. for my (fairly large) app is goes from 20 MB (with optimization: true) to 32 MB (with optimization: true but compress: false), but is definitely worth it IMO.
I can look into drafting a PR if you guys agree with that.
🔬 Minimal Reproduction
$ npm install -g @angular/cli@latest
$ ng new ssr-minify-test
$ cd ssr-minify-test/
$ ng add @nguniversal/express-engine
$ npm run build:ssr
Manually inspect dist/ssr-minify-test/server/main.js -> code is minified / unreadable
This was one of the changes in version 9 where server production code is minified, one of the main reasons behind this is to speed up server cold starts and reduce deployment times.
What I suggest is to generate sourcemaps and attach them, which will provide a better debug experience.
That being said, in the future we should probably provide different levels of optimizations as per #15761.
🐞 Bug report
Command (mark with an
x
)Is this a regression?
No
Description
By default, the production server bundles generated by the Angular CLI are minified, making debugging much harder, despite the code comment at https://github.com/angular/angular-cli/blob/master/packages/angular_devkit/build_angular/src/angular-cli-files/models/webpack-configs/common.ts#L416 reading:
The reason being that, when
buildOptions.platform == 'server'
istrue
, the following object is passed to theTerserPlugin
compress
option:However, according to the TerserPlugin's docs, most
compress
flags default totrue
, so this effectively causes the server code to be minified.In addition, unsetting the
scripts
optimizations inangular.json
causes other side effects, namelyngDevMode
no longer being explicitly set tofalse
, causing the server code to run in dev mode by default.One workaround is to set the
NG_BUILD_DEBUG_OPTIMIZE
flag, which does turn offcompress
, but my concern is that it would get removed & renamed at some point since it's undocumented.I think
compress
should be set tofalse
for server builds, as per the code comment currently reads, as working with minified code on the server is a pain. It would cause server-side bundles to jump in size, e.g. for my (fairly large) app is goes from 20 MB (withoptimization: true
) to 32 MB (withoptimization: true
butcompress: false
), but is definitely worth it IMO.I can look into drafting a PR if you guys agree with that.
🔬 Minimal Reproduction
Manually inspect
dist/ssr-minify-test/server/main.js
-> code is minified / unreadable🌍 Your Environment
The text was updated successfully, but these errors were encountered: