<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Rafayasad</title>
    <description>The latest articles on DEV Community by Rafayasad (@rafayasad).</description>
    <link>https://dev.to/rafayasad</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F1784140%2F5aa8db16-a47c-41f7-8893-8f6b5b9cd4c8.jpeg</url>
      <title>DEV Community: Rafayasad</title>
      <link>https://dev.to/rafayasad</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rafayasad"/>
    <language>en</language>
    <item>
      <title>How to Deploy a Single Page Application on GitHub Pages</title>
      <dc:creator>Rafayasad</dc:creator>
      <pubDate>Mon, 15 Jul 2024 11:18:16 +0000</pubDate>
      <link>https://dev.to/rafayasad/how-to-deploy-a-single-page-application-on-github-pages-k3g</link>
      <guid>https://dev.to/rafayasad/how-to-deploy-a-single-page-application-on-github-pages-k3g</guid>
      <description>&lt;p&gt;GitHub Pages is a free hosting service provided by GitHub, allowing you to serve your web projects directly from a GitHub repository and deploy a single page application (SPA) on GitHub Pages. In this guide, I’ll walk you through the steps to deploy your SPA efficiently.&lt;/p&gt;

&lt;h2&gt;
  
  
  Requirements
&lt;/h2&gt;

&lt;p&gt;Before we begin, ensure you have the following:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;GitHub account.&lt;/li&gt;
&lt;li&gt;A Single-page application ready to deploy.&lt;/li&gt;
&lt;li&gt;Git is installed on your machine.&lt;/li&gt;
&lt;/ol&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Step 1: Create a GitHub Repository&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ol&gt;
&lt;li&gt;Log in to GitHub: Go to GitHub and log in.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Create a new repository&lt;/strong&gt;:&lt;/li&gt;
&lt;/ol&gt;

&lt;ul&gt;
&lt;li&gt;Click the “+” icon in the top right corner and select “New repository.”&lt;/li&gt;
&lt;li&gt;Give your repository a name (e.g., my-spa).&lt;/li&gt;
&lt;li&gt;Set the repository to “Public.”&lt;/li&gt;
&lt;li&gt;Click “Create repository.”&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Step 2: Initialize Your Project&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;strong&gt;Open your terminal&lt;/strong&gt;: Navigate to your project directory.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Initialize a Git repository:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Add your files:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git add .
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;If you want to check your added files status (optional):
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git status
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Commit your changes:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git commit -m "Initial commit"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Step 3: Push to GitHub&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Add the remote URL:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git remote add origin https://github.com/YOUR_USERNAME/my-spa.git
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Push your code:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;git push -u origin master
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Step 4: Set Up GitHub Pages&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Go to your repository on GitHub&lt;/strong&gt;: Navigate to the repository you just pushed.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Open the “Settings” tab&lt;/strong&gt; at the top of your repository page.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Scroll down to the “GitHub Pages” section&lt;/strong&gt;: Under “Source,” select the branch you want to use for GitHub Pages. Typically, this is the main or master branch.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Save&lt;/strong&gt;: GitHub will automatically publish your site.&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Step 5: Configure Your SPA for GitHub Pages&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you are using a framework like React, you may need additional configuration to ensure your SPA works correctly with GitHub Pages. For example, if you are using React, you can use the &lt;a href="https://www.npmjs.com/package/gh-pages" rel="noopener noreferrer"&gt;gh-pages&lt;/a&gt; package.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install &lt;code&gt;gh-pages&lt;/code&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install gh-pages --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Add the following scripts to your &lt;code&gt;package.json&lt;/code&gt;:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"scripts": {
  "predeploy": "npm run build",
  "deploy": "gh-pages -d build"
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;ul&gt;
&lt;li&gt;Deploy your app:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run deploy
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will build your app and deploy it to the &lt;code&gt;gh-pages&lt;/code&gt; branch.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;** Step 6: Access Your Deployed Application**&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Once deployed, you can access your application at:&lt;br&gt;
&lt;a href="https://YOUR_USERNAME.github.io/my-spa" rel="noopener noreferrer"&gt;https://YOUR_USERNAME.github.io/my-spa&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Deploying a single-page application on GitHub Pages is a simple and effective way to host your projects for free. With these steps, you can easily share your work with others and have a live version of your SPA available online. Happy coding!&lt;/p&gt;

&lt;p&gt;Feel free to leave comments or questions below if you need further assistance.&lt;/p&gt;

&lt;p&gt;If you liked the article follow me 👍. Thank you&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
