Here is a general procedure for getting your project hosted on GitHub pages so you can show your hard work to your loved ones.
- Checkout your
main
branch and double-check to make sure it is up-to-date and there is nothing needed to be committed at this point - Navigate to the root of your project directory
- Open your project in your text editor
- Double-check that all image tags in your HTML have the
src
attribute have./
to start the path, e.gsrc="./images/turing-logo.png"
- Go to your GitHub Repo and click
Settings
>Pages
- Select "Deploy from branch" from the
main
branch and clickSave
. Note that after this step, your deployed site will be showing the README. This is expected. In order to get your actual app to show up, the following steps are necessary. - In the
package.json
file, within the"repository"
object, add the lines:
"type": "git",
"url": "git+https://github.com/USERNAME/REPONAME.git"
...where USERNAME and REPONAME are replaced with your GitHub username and your repository name, respectively. Note: If there is no "repository"
object, create one.
-
In the
package.json
file, add the line:"homepage": "http://USERNAME.github.io/REPONAME",
where USERNAME and REPONAME are replaced with your GitHub username and your repository name, respectively -
Add these two lines to the
scripts
section of thepackage.json
file:
"predeploy": "npm run build",
"deploy": "gh-pages -d dist"
Your package.json
file should now look like this:
{
"name": "dog-party",
"version": "1.0.0",
"description": "Dog Party starter kit using webpack and SCSS/SASS enabled.",
"main": "index.js",
"homepage": "http://USERNAME.github.io/REPONAME",
"repository": {
"type": "git",
"url": "git+https://github.com/USERNAME/REPONAME.git"
},
"scripts": {
"start": "webpack server",
"build": "webpack",
"predeploy": "npm run build",
"deploy": "gh-pages -d dist"
},
"author": "Turing School of Software and Design",
...
}
- In the terminal, run
npm install --save-dev gh-pages
- You should see these lines of JSON added to your
package.json
file:
"devDependencies": {
"gh-pages": "^1.1.0"
}
- Run
npm run build
in the command line - Run
npm run deploy
in the command line
All of this will create a gh-pages
branch in your repo with the contents from the build
directory.
- Now go back to your GitHub Repo and click
Settings
>Pages
- Change the branch to
gh-pages
and clickSave
Wait a few minutes (deploying takes time!) and then visit the GitHub pages site (http://USERNAME.github.io/REPONAME). You should see your app! If not, check out the console to see what errors you're getting and troubleshoot from there.
If you make new changes to your main
branch, GitHub Pages doesn't automatically know about these changes, and your site won't be up-to-date. You need to update the gh-pages
branch to see those changes live on GitHub Pages. Here is how to update and keep everything in sync:
- After you're done making changes, checkout your
main
branch and double-check to make sure it is up-to-date and there is nothing needed to be committed at this point - Run
npm run build
in the command line - Run
npm run deploy
in the command line