Build Process
Count App uses Angular’s application builder with Server-Side Rendering (SSR) support. The build process compiles your TypeScript code, bundles assets, and generates optimized output for both browser and server.Production Build
Create a production-ready build:The default configuration is set to production, which includes optimizations, tree-shaking, and minification.
Build Configurations
Production Configuration
The production build includes:- Output hashing: All files get content-based hashes for cache busting
- Bundle budgets: Build fails if initial bundle exceeds 1MB
- Style budgets: Component styles limited to 8kB maximum
- Optimizations: Minification, tree-shaking, and dead code elimination enabled by default
Development Configuration
For faster builds during development:- No optimization for faster builds
- Source maps enabled for debugging
- License extraction disabled
- Rebuilds automatically on file changes
Build Output Structure
After building, thedist/count-app/ directory contains:
Browser Output
Thebrowser/ directory contains:
- Compiled and bundled JavaScript
- Processed CSS with Tailwind utilities
- Static assets from the
public/directory - Hashed filenames for cache management
Server Output
Theserver/ directory contains the SSR server built from src/server.ts.
SSR (Server-Side Rendering)
SSR Configuration
The build is configured for SSR in angular.json:- Browser: src/main.ts
- Server: src/main.server.ts
- SSR Server: src/server.ts
Building for SSR
The SSR server uses Express 5.1.0 to handle requests and render pages on the server.
Build Options
TypeScript Configuration
The build uses tsconfig.app.json for compilation:tsconfig.app.json
- Excludes test files from the build
- Includes Node.js types for SSR support
- Outputs to
out-tsc/app/
Assets Configuration
Static assets are configured in angular.json:public/ directory are copied to the build output.
Styles Configuration
Global styles are specified in angular.json:Bundle Budgets
The build enforces size budgets to keep your app performant:- Initial Bundle
- Component Styles
- Warning: 500kB
- Error: 1MB
Optimization Strategies
Lazy Loading
Lazy Loading
Use Angular’s router to lazy load feature modules:
Tree Shaking
Tree Shaking
Import only what you need from libraries:
Analyze Bundle Size
Analyze Bundle Size
Use Angular CLI’s built-in analysis:
Environment-Specific Builds
Build for specific environments:Serving the Production Build
SSR Mode (Recommended)
Static Serving
You can also serve the browser output with any static file server:Static serving won’t include SSR benefits like improved SEO and faster initial page load.
Deployment
The build output is ready for deployment to:- Node.js hosts: Deploy the entire
dist/count-app/directory and run the SSR server - Static hosts: Deploy only the
dist/count-app/browser/directory - Docker: Create a container with Node.js and the build output
Example Dockerfile
Troubleshooting
Build fails with budget errors
Build fails with budget errors
Your bundle size exceeds the limits. Options:
- Implement lazy loading for large features
- Remove unused dependencies
- Adjust budgets in angular.json (not recommended)
SSR server fails to start
SSR server fails to start
Ensure you built the project first:
Assets not copied to output
Assets not copied to output
Check your assets configuration in angular.json. Files must be in the
public/ directory.Next Steps
Setup Guide
Return to the setup guide
Testing
Learn about testing your application