Title: Server bundles are minified by default · Issue #17517 · angular/angular-cli · GitHub
Open Graph Title: Server bundles are minified by default · Issue #17517 · angular/angular-cli
X Title: Server bundles are minified by default · Issue #17517 · angular/angular-cli
Description: 🐞 Bug report Command (mark with an x) new build serve test e2e generate add update lint xi18n run config help version doc Is this a regression? No Description By default, the production server bundles generated by the Angular CLI are min...
Open Graph Description: 🐞 Bug report Command (mark with an x) new build serve test e2e generate add update lint xi18n run config help version doc Is this a regression? No Description By default, the production server bund...
X Description: 🐞 Bug report Command (mark with an x) new build serve test e2e generate add update lint xi18n run config help version doc Is this a regression? No Description By default, the production server bund...
Opengraph URL: https://github.com/angular/angular-cli/issues/17517
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Server bundles are minified by default","articleBody":"\u003c!--🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅\r\n\r\nOh hi there! 😄\r\n\r\nTo expedite issue processing please search open and closed issues before submitting a new one.\r\nExisting issues often contain information about workarounds, resolution, or progress updates.\r\n\r\n🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅🔅-->\r\n\r\n\r\n# 🐞 Bug report\r\n\r\n### Command (mark with an `x`)\r\n\u003c!-- Can you pin-point the command or commands that are effected by this bug? -->\r\n\u003c!-- ✍️edit: -->\r\n\r\n- [ ] new\r\n- [x] build\r\n- [ ] serve\r\n- [ ] test\r\n- [ ] e2e\r\n- [ ] generate\r\n- [ ] add\r\n- [ ] update\r\n- [ ] lint\r\n- [ ] xi18n\r\n- [ ] run\r\n- [ ] config\r\n- [ ] help\r\n- [ ] version\r\n- [ ] doc\r\n\r\n\r\n### Is this a regression?\r\n\r\nNo\r\n\r\n### Description\r\n\r\nBy 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:\r\n\r\n> // On server, we don't want to compress anything. We still set the ngDevMode = false for it\r\n> // to remove dev code, and ngI18nClosureMode to remove Closure compiler i18n code\r\n\r\nThe reason being that, when `buildOptions.platform == 'server'` is `true`, the following object is passed to the `TerserPlugin` `compress` option:\r\n\r\n```\r\n{\r\n ecma: terserEcma,\r\n global_defs: angularGlobalDefinitions,\r\n keep_fnames: true,\r\n}\r\n```\r\n\r\nHowever, according to the TerserPlugin's [docs](https://github.com/terser/terser#compress-options), most `compress` flags default to `true`, so this effectively causes the server code to be minified.\r\n\r\nIn 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.\r\n\r\n```\r\n\"optimization\": {\r\n \"scripts\": false,\r\n \"styles\": true\r\n},\r\n```\r\n\r\nOne 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.\r\n\r\nI 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.\r\n\r\nI can look into drafting a PR if you guys agree with that.\r\n\r\n## 🔬 Minimal Reproduction\r\n\r\n\u003cpre>\u003ccode>\r\n$ npm install -g @angular/cli@latest\r\n$ ng new ssr-minify-test\r\n$ cd ssr-minify-test/\r\n$ ng add @nguniversal/express-engine\r\n$ npm run build:ssr\r\n\u003c/code>\u003c/pre>\r\n\r\nManually inspect `dist/ssr-minify-test/server/main.js` -> code is minified / unreadable\r\n\r\n## 🌍 Your Environment\r\n\u003cpre>\u003ccode>\r\n\r\n _ _ ____ _ ___\r\n / \\ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|\r\n / △ \\ | '_ \\ / _` | | | | |/ _` | '__| | | | | | |\r\n / ___ \\| | | | (_| | |_| | | (_| | | | |___| |___ | |\r\n /_/ \\_\\_| |_|\\__, |\\__,_|_|\\__,_|_| \\____|_____|___|\r\n |___/\r\n\r\n\r\nAngular CLI: 9.1.1\r\nNode: 12.4.0\r\nOS: darwin x64\r\n\r\nAngular:\r\n...\r\nIvy Workspace:\r\n\r\nPackage Version\r\n------------------------------------------------------\r\n@angular-devkit/architect 0.901.1\r\n@angular-devkit/core 9.1.1\r\n@angular-devkit/schematics 9.1.1\r\n@schematics/angular 9.1.1\r\n@schematics/update 0.901.1\r\nrxjs 6.5.4\r\n\u003c/code>\u003c/pre>","author":{"url":"https://github.com/laurentgoudet","@type":"Person","name":"laurentgoudet"},"datePublished":"2020-04-21T11:34:28Z","url":"https://github.com/angular/angular-cli/issues/17517"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:05fe78e1-b43d-0807-f258-c1495e916608 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | 80C2:3DD488:14D7498:1A6D8E1:6B012F00 |
| html-safe-nonce | de33b0b3ea36b4a20926a09372f1a6cd700945a2b0943f0e8c61b102613f878e |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiI4MEMyOjNERDQ4ODoxNEQ3NDk4OjFBNkQ4RTE6NkIwMTJGMDAiLCJ2aXNpdG9yX2lkIjoiOTE4MDEzNzY0ODAxMjk5NjM1MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | e5b5bd34dc9632d08baeb58e9c752a870dfc10574b9c4f280b64b57627ab229c |
| hovercard-subject-tag | issue:603926749 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/angular/angular-cli/17517/issue_layout |
| twitter:image | https://opengraph.githubassets.com/b0f6758fa9056a6793b861c261e46d714905d364a159ac6ff1d15b19d402ea85/angular/angular-cli/issues/17517 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/b0f6758fa9056a6793b861c261e46d714905d364a159ac6ff1d15b19d402ea85/angular/angular-cli/issues/17517 |
| og:image:alt | 🐞 Bug report Command (mark with an x) new build serve test e2e generate add update lint xi18n run config help version doc Is this a regression? No Description By default, the production server bund... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | laurentgoudet |
| hostname | github.com |
| expected-hostname | github.com |
| None | cc5dfdd32f62ebd3223cab3af3aa2b268d3605218237326a48a99d1efd89495c |
| turbo-cache-control | no-preview |
| go-import | github.com/angular/angular-cli git https://github.com/angular/angular-cli.git |
| octolytics-dimension-user_id | 139426 |
| octolytics-dimension-user_login | angular |
| octolytics-dimension-repository_id | 36891867 |
| octolytics-dimension-repository_nwo | angular/angular-cli |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 36891867 |
| octolytics-dimension-repository_network_root_nwo | angular/angular-cli |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | 8c77c9e8439031ad54c75a250694842892f693e1 |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width