DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workkloads.

Secure your stack and shape the future! Help dev teams across the globe navigate their software supply chain security challenges.

Releasing software shouldn't be stressful or risky. Learn how to leverage progressive delivery techniques to ensure safer deployments.

Avoid machine learning mistakes and boost model performance! Discover key ML patterns, anti-patterns, data strategies, and more.

Related

  • How to Effortlessly Host Your Angular Website on GitHub Pages
  • Step-by-Step Guide: Application Using NestJs and Angular
  • Automate Web Portal Deployment in Minutes Using GitHub Actions
  • How GitHub Codespaces Helps in Reducing Development Setup Time

Trending

  • Hybrid Cloud vs Multi-Cloud: Choosing the Right Strategy for AI Scalability and Security
  • Beyond Linguistics: Real-Time Domain Event Mapping with WebSocket and Spring Boot
  • A Modern Stack for Building Scalable Systems
  • Solid Testing Strategies for Salesforce Releases
  1. DZone
  2. Testing, Deployment, and Maintenance
  3. Deployment
  4. Deploy Your Angular App on GitHub Pages

Deploy Your Angular App on GitHub Pages

Learn more about deploying your Angular app on GitHub Pages.

By 
Sanjay Saini user avatar
Sanjay Saini
·
Updated Jun. 30, 20 · Tutorial
Likes (8)
Comment
Save
Tweet
Share
39.6K Views

Join the DZone community and get the full member experience.

Join For Free

Angled wall

Learn more about deploying your Angular app on GitHub Pages.

In this article, I am going to share with you my learnings while I was trying to publish my Angular app on GitHub Pages. I found GitHub Pages to be a very effective yet easy platform for publishing your websites. So, in this article, I am going to explain the process in the same way that I published my app.

You may also like:  How to Turn Your GitHub Page Into a Personalized Resume

I have developed this simple Todo app in Angular, in which I am going to explain how to deploy on GitHub Pages in these simple steps...

Image title

Deploy Your Local Repository on GitHub

GitHub Pages provides a very convenient way to deploy your static websites from your GitHub repository. Therefore, you need to have an account on GitHub.com in order to follow this article.

First, you need to put your code in a local repository into the remote repository at github.com, so if you don’t have a GitHub account, you need to create it now.

Then, log in to your GitHub account and create a repository in which you will upload your local code. Here, I created a repository named todo-app.

GitHub repo called Todo app

Note that the URL of the newly created repository (in my case, it's https://github.com/sanjaysaini2000/todo-app.git) that will be used to set up the remote repository for your local repository in order to push your local repository code onto the GitHub repository.

Assuming you have git installed on your machine, and you have already committed your code in the master branch of your local repository, open the git bash on the app folder and run the commands below with your GitHub repository URL to upload your code on github.com repository.

git remote add origin <your GitHub repository URL>

git push -u origin master

Refresh your GitHub repository and check that your code is pushed into the newly created GitHub repository.

Build Your Code to Generate Deployables

Now, we need to build our code in production mode in order to create distributable files that will be deployed on GitHub Pages. By default, this deployable code is generated in the /dist/<prodect-name> folder under the app folder, but we need to generate this in the “docs” folder under the app folder.

So, we need to make a small change in the angular.json file and change the outputpath value to “docs/”.

Another point to be noted is your URL is going to be hosted app on the Github Pages as https://username.github.io/respositoryname.

In my case, it would be https://sanjaysaini2000.github.io/todo-app.

This URL is needed to set the base URL of our website while generating the distributable files to deploy on GitHub Pages.

So now, run the following command with your website URL in the baseHref  option in the git bash window to generate distributable files in the docs folder.

ng build --prod --baseHref=” https://username.github.io/respository-name/”

Note that the username and repository name will be your GitHub username and repository name.

Go to your app folder and check that the docs folder is created and contains all of the distributable files.

Distributed files

Now, commit this folder into the local repository and push it into the GitHub repository as well by running the following commands in the git bash window.

git add .

git commit -m "generated deployables"

git push -u origin master


Configure Your GitHub Repository for Publishing on GitHub Pages

Once the docs folder is pushed into your GitHub repository, you need to open the repository settings and go to the GitHub Pages section and select “master branch/docs folder” from the source dropdown. And that's it!

Docs folder on GitHub Pages

Now, open the GitHub Pages URL of your deployed app in the browser window to check for the successful deployment of your app on the GitHub Pages.

Link for this todo-app (I had to create another repository named angular-todo-app so don't get confused with the different repository name in the URL of this site.)

GitHub repo

There is another method you can use to deploy your Angular app on GitHub Pages — use the angular-cli-ghpages  package. You can Google for more details, but personally, I find the above approach better and clearer than using that package.

Hope you enjoyed! Please leave questions and/or comments below.

Further Reading

Publish Your Angular GitHub Repository as a GitHub Page

How to Turn Your GitHub Page Into a Personalized Resume

GitHub app Repository (version control) AngularJS

Opinions expressed by DZone contributors are their own.

Related

  • How to Effortlessly Host Your Angular Website on GitHub Pages
  • Step-by-Step Guide: Application Using NestJs and Angular
  • Automate Web Portal Deployment in Minutes Using GitHub Actions
  • How GitHub Codespaces Helps in Reducing Development Setup Time

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!