{"id":1013,"date":"2023-05-30T05:00:00","date_gmt":"2023-05-30T12:00:00","guid":{"rendered":"https:\/\/www.angulartraining.com\/daily-newsletter\/?p=1013"},"modified":"2023-05-22T15:07:09","modified_gmt":"2023-05-22T22:07:09","slug":"anti-pattern-not-using-production-builds-to-deploy-production-code","status":"publish","type":"post","link":"https:\/\/www.angulartraining.com\/daily-newsletter\/anti-pattern-not-using-production-builds-to-deploy-production-code\/","title":{"rendered":"Anti-pattern: Not using production builds to deploy production code"},"content":{"rendered":"\n<p>This is one of the most common mistakes I see with my training\/consulting clients. When deploying code to production, they would use the command: <code>ng build<\/code>.<\/p>\n\n\n\n<p>Instead, you want to use: <code>ng build --configuration=production<\/code><\/p>\n\n\n\n<p>Why is that? Because a production build is <strong>optimized in several ways<\/strong>:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>The code gets <strong>minified and obfuscated<\/strong>, which means it looks like this when running in a browser:<br><\/li>\n<\/ol>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img loading=\"lazy\" decoding=\"async\" width=\"472\" height=\"136\" src=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/05\/image-36.png\" alt=\"\" class=\"wp-image-1014\" srcset=\"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/05\/image-36.png 472w, https:\/\/www.angulartraining.com\/daily-newsletter\/wp-content\/uploads\/2023\/05\/image-36-300x86.png 300w\" sizes=\"auto, (max-width: 472px) 100vw, 472px\" \/><\/figure>\n<\/div>\n\n\n<p>This code is as lightweight as possible (no tabs, whitespace, new line characters, variables have super short names, etc.) and a lot more challenging to understand (a hacker would have a harder time understanding your code).<\/p>\n\n\n\n<p>2. The code gets<strong> tree-shaked<\/strong>. Angular removes unused dependencies and dead code and makes your build output as tiny as possible. Size matters on the web: The less code you ship to a browser, the faster it gets downloaded, parsed, and interpreted (which is also why Angular gives us <a href=\"https:\/\/www.angulartraining.com\/daily-newsletter\/lazy-loading-for-better-angular-performance\/\" target=\"_blank\" rel=\"noopener\" title=\"\">lazy-loading<\/a> capabilities)<\/p>\n\n\n\n<p>3. Source maps are <strong>not generated<\/strong> in that same spirit of hiding what our source code looks like.<\/p>\n\n\n\n<p>4. Angular DevTools are disabled on that code, again for obfuscation and reverse-engineering purposes.<\/p>\n\n\n\n<p><\/p>\n\n\n\n<p>If you&#8217;re still not convinced after reading all of this, give it a try on your Angular projects. The size of your <code>dist<\/code> folder after a production build should be at least 90 to 95% smaller compared to a regular build, which is massive.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>This is one of the most common mistakes I see with my training\/consulting clients. When deploying code to production, they would use the command: ng build. Instead, you want to use: ng build &#8211;configuration=production Why is that? Because a production build is optimized in several ways: This code is as lightweight as possible (no tabs, [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4,28,30,20,17],"tags":[],"class_list":["post-1013","post","type-post","status-publish","format-standard","hentry","category-angular","category-anti-patterns","category-cli","category-performance","category-tools"],"aioseo_notices":[],"_links":{"self":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/1013","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/comments?post=1013"}],"version-history":[{"count":1,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/1013\/revisions"}],"predecessor-version":[{"id":1015,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/posts\/1013\/revisions\/1015"}],"wp:attachment":[{"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/media?parent=1013"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/categories?post=1013"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.angulartraining.com\/daily-newsletter\/wp-json\/wp\/v2\/tags?post=1013"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}