Production Build Explained - Dev vs Prod Build, HTTP Server
- Build means compiling code to make it ready to run
- Angular has two types of builds
- Development build
- Production build
Development Build
- Used while working on the project
- Runs using
ng serve - Code changes reflect instantly in the browser
- Easy debugging
- Source code is visible in browser DevTools
- Slower performance compared to production
Production Build
- Code is compiled and optimized
- Code is minified and compressed
- File size becomes smaller
- Application runs faster
- Source code is not visible in browser
- Used for deployment
Create Production Build
Command:
ng build
- After running this command, a
distfolder is created - Build time depends on project size
Dist Folder Structure
- Go to
dist → project-name → browser index.htmlis the main file- One minified JavaScript file
- One minified CSS file
- Original
srccode is merged and compressed
Why Production Build is Faster?
- JavaScript code is minified
- CSS file size is reduced
- Fewer files are loaded
- Better browser performance
Run Production Build Locally
Production build needs a server.
Install HTTP Server
Command:
npm i -g http-server
- Installed globally
- On Mac,
sudomay be required - On Windows, usually no sudo needed
Run Production Build Using HTTP Server
Steps:
- Go inside
dist → project-name → browser - Run command:
http-server -p 88
- If port is busy, use another port
- Server starts successfully
- Open given URL in browser
Development vs Production (Browser Check)
Development Build:
srcfolder is visible in DevTools- All component files are readable
Production Build:
srcfolder is not visible- Only one minified JS file exists
Performance Test Using Lighthouse
Development Build:
- Lower performance score
- Higher load time (example: 2.6s)
Production Build:
- Better performance score
- Faster load time (example: 1s)
- Better SEO, accessibility, best practices