Tags: angular gitHub pages
GitHub Pages provides a simple way to host static websites for free. In this guide, we'll create a basic Angular app, build it for production, and deploy it to GitHub Pages.
Ensure you have the following installed:
Node.js (LTS recommended)
Angular CLI (npm install -g @angular/cli
)
A GitHub account
First, generate a new Angular project:
This creates a new Angular project with default settings.
To deploy the app, we need to create a production-ready build:
Explanation:
--configuration production
: Optimizes the build for production.
--base-href "/my-angular-app/"
: Required for GitHub Pages (replace my-angular-app
with your repository name).
The output files will be in the dist/my-angular-app
directory.
Go to GitHub.
Click New repository.
Name it my-angular-app
.
Initialize with a README (optional).
Click Create repository.
We’ll use the gh-pages
branch for deployment.
Go to your GitHub repository.
Navigate to Settings > Pages.
Under Branch, select gh-pages
.
Click Save.
After a few minutes, your app will be available at:
https://YOUR_USERNAME.github.io/my-angular-app/
You’ve successfully deployed an Angular app to GitHub Pages! This method is ideal for hosting small projects, demos, or personal portfolios.
404 Errors? Ensure the base-href
is correctly set.
Changes Not Reflecting? Try:
Settings > Pages
.Now, you can easily share your Angular project with the world! 🚀