Deploying an Angular App
Angular is a popular open-source web application framework maintained by Google. It provides a robust platform for building dynamic, scalable, and maintainable single-page applications (SPAs) using TypeScript.
This guide explains how to deploy an Angular application to Klutch.sh, both with and without a Dockerfile. It covers installation, sample code, and deployment steps.
Prerequisites
- Node.js & npm installed (Download)
- Git and GitHub account
- Klutch.sh account
Getting Started: Create an Angular App
- Install Angular CLI globally:
Terminal window npm install -g @angular/cli - Create a new Angular app:
Terminal window ng new my-angular-app --defaultscd my-angular-app - Start the development server:
Your app should be running at http://localhost:4200.
Terminal window ng serve
Sample Code (src/app/app.component.ts)
Replace the contents of src/app/app.component.ts
with:
import { Component } from '@angular/core';
@Component({ selector: 'app-root', template: `<h1>Hello from Angular on Klutch.sh!</h1>`})export class AppComponent {}
Deploying Without a Dockerfile
Angular apps are static sites after build. Klutch.sh can deploy static sites directly.
- Push your Angular app to a GitHub repository.
- Log in to Klutch.sh.
- Create a new project.
- Create a new app:
- Select your Angular GitHub repository and branch
- Choose “Static Site” as the app type
- Set build command:
ng build --configuration production
- Set output directory:
dist/my-angular-app
- Configure region, compute, and environment variables as needed
- Click “Create” to deploy. Klutch.sh will build and serve your static Angular app.
Deploying With a Dockerfile
If you need custom server logic or want to use a Dockerfile:
- Add a
Dockerfile
to your project root. Example:# Build stageFROM node:20-alpine AS builderWORKDIR /appCOPY package*.json ./RUN npm install -g @angular/cli && npm installCOPY . .RUN ng build --configuration production# Production stageFROM nginx:alpineCOPY --from=builder /app/dist/my-angular-app /usr/share/nginx/htmlEXPOSE 80CMD ["nginx", "-g", "daemon off;"] - Push your code (with Dockerfile) to GitHub.
- In Klutch.sh, create a new app and select the Dockerfile option when prompted.
- Set service details and environment variables as needed.
- Click “Create” to deploy. Klutch.sh will build your Docker image and serve your Angular app via Nginx.
Resources
Deploying Angular to Klutch.sh is fast and flexible. Use static site deployment for most cases, or Dockerfile for custom setups.