Deploying any app to GitHub Pages

GitHub Pages is a website holder for you & your projects. You can host your code directly from your GitHub repo. This article will help you how to manage your app in the master branch and deploy the code in the gh-pages branch easily.

You can choo…


This content originally appeared on DEV Community and was authored by Omura

GitHub Pages is a website holder for you & your projects. You can host your code directly from your GitHub repo. This article will help you how to manage your app in the master branch and deploy the code in the gh-pages branch easily.

You can choose any front-end framework like React, Vue, Gatsby, Next, Nuxt, Gridsome, and build the app in the master branch and build the code using the npm run build command and host directly using the gh-pages branch.

The quickest way to put your app to GitHub Pages is by using a package - gh-pages.

'''bash
npm i gh-pages -D

or you can install the package globally
'''bash
npm i gh-pages -g
Add this simple script to your package.json
'''json
{
"scripts": {
"deploy": "npm run build && gh-pages -d dist"
}
}

Note: Assuming the build folder to be dist

When you run npm run deploy all the contents of the build folder will be pushed to your repository’s gh-pages branch.
If you are creating a User page in GitHub
Create a repository with your username like username.github.io, Create a branch called code or you can name the branch anything. Build the app in this branch and when it comes to deploying the app use the gh-pages command to push the build folder contents to the gh-pages branch

Note: In this case, you need to push your build directory to master branch, use the following command
'''json
{
"scripts": {
"deploy": "npm build && gh-pages -d dist -b master",
}
}
After running npm run deploy you should see your website at http://username.github.io

Run gh-pages --help to list all the supported options of the gh-pages package

Useful npm scripts of gh-pages
If your source code of the app is in a private repository, create a public repository named about, the source code will reside in the private repository and the static content generated from the build will go into the public repository
'''json
{
"scripts": {
"deploy": "gridsome build && gh-pages -d dist -b master",
}
}
To include dotfiles while pushing the changes to the branch

'''json
{
"scripts": {
"deploy": "npm run build && gh-pages -d dist -t"
}
}
To change the commit message when publishing the change
'''json
{
"scripts": {
"deploy": "npm run build && gh-pages -d dist -m Build 21082020v1"
}
}


This content originally appeared on DEV Community and was authored by Omura


Print Share Comment Cite Upload Translate Updates
APA

Omura | Sciencx (2024-08-21T20:47:12+00:00) Deploying any app to GitHub Pages. Retrieved from https://www.scien.cx/2024/08/21/deploying-any-app-to-github-pages/

MLA
" » Deploying any app to GitHub Pages." Omura | Sciencx - Wednesday August 21, 2024, https://www.scien.cx/2024/08/21/deploying-any-app-to-github-pages/
HARVARD
Omura | Sciencx Wednesday August 21, 2024 » Deploying any app to GitHub Pages., viewed ,<https://www.scien.cx/2024/08/21/deploying-any-app-to-github-pages/>
VANCOUVER
Omura | Sciencx - » Deploying any app to GitHub Pages. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2024/08/21/deploying-any-app-to-github-pages/
CHICAGO
" » Deploying any app to GitHub Pages." Omura | Sciencx - Accessed . https://www.scien.cx/2024/08/21/deploying-any-app-to-github-pages/
IEEE
" » Deploying any app to GitHub Pages." Omura | Sciencx [Online]. Available: https://www.scien.cx/2024/08/21/deploying-any-app-to-github-pages/. [Accessed: ]
rf:citation
» Deploying any app to GitHub Pages | Omura | Sciencx | https://www.scien.cx/2024/08/21/deploying-any-app-to-github-pages/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.