Deploying an Angular
Deploying an Angular application involves building it for production and hosting it on a server or cloud platform. Proper deployment ensures fast loading, optimized bundles, and secure hosting.
1. Build for Production
Generate a production-ready build:
- Compiles TypeScript to JavaScript
- Optimizes bundle size (minification, tree-shaking, AOT)
- Output folder:
dist/<project-name>
Serve locally to test:
2. Deploy to Firebase Hosting
- Install Firebase CLI:
- Login and initialize:
- Select Hosting
- Set
dist/<project-name>as public folder - Configure as SPA: Yes (rewrite all URLs to
index.html) - Deploy:
3. Deploy to Netlify
- Sign up at Netlify and connect your GitHub repository.
- Configure build settings:
- Deploy automatically on push to main branch.
4. Deploy to Vercel
- Install Vercel CLI:
- Deploy:
- Set
dist/<project-name>as output directory - Follow prompts for project name and scope
5. Deploy to AWS S3
- Build Angular app:
- Create S3 bucket and enable static website hosting.
- Upload
dist/<project-name>files. - Optional: Use CloudFront for CDN and HTTPS.
6. Deploy to Azure
- Build Angular app:
- Create Azure Storage Static Website or App Service.
- Upload
dist/<project-name>files via Azure portal or Azure CLI:
- Access the site via Azure URL.
7. Deploy to NGINX
- Build Angular app:
- Copy files to NGINX server directory (e.g.,
/var/www/html). - Configure
nginx.conffor SPA routing:
- Restart NGINX:
Summary
- Build Angular app with
ng build --prodfor optimized production code. - Deploy to hosting platforms like Firebase, Netlify, Vercel, AWS S3, Azure, or NGINX.
- Ensure SPA routing is handled correctly (rewrite all URLs to
index.html). - Use CDN or caching for faster loading.
- Test after deployment for performance and correctness.