Skip to content

Commit

Permalink
Update deploy-gatsby.md (#1842)
Browse files Browse the repository at this point in the history
Add gh-pages section
  • Loading branch information
psongpin authored and sebastienfi committed Aug 17, 2017
1 parent 9816bb7 commit c9139bd
Showing 1 changed file with 38 additions and 1 deletion.
39 changes: 38 additions & 1 deletion docs/docs/deploy-gatsby.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,41 @@ This is a new problem when dealing with static sites built with React. React us
## Hosting on Amazon S3 and Cloudfront
If you decide to host your Gatsby site to S3 having Cloudfront as CDN you should edit on the Cloudfront panel the "Origin Domain Name" with the real URL of your S3 bucket: **examplewebsite.com.s3-website-eu-west-1.amazonaws.com** instead of the default one automatically suggested by Amazon **examplewebsite.com.s3.amazonaws.com**.

This is recommended for rendering correctly the post pages in the subfolders without typing the index.html path as described [here](https://forums.aws.amazon.com/message.jspa?messageID=314454).
This is recommended for rendering correctly the post pages in the subfolders without typing the index.html path as described [here](https://forums.aws.amazon.com/message.jspa?messageID=314454).

## Deploying on Github Pages
### Deploying a Project Page
Deploying Project on Github pages can be done with or without Custom Domain. If you choose to use the default setup (without Custom Domain), you will need to prefix your links (ex. gatsbypage.github.io/project-name/about-page - "/project-name" will be prefixed in all your links).

#### Without Custom Domain
First you have to add **gh-pages** as a dev-dependency and create an npm script command to **deploy** your project.

Run `npm install gh-pages --save-dev` or `yarn add gh-pages --dev` (if you have yarn installed). Alternatively, you can place this under *"devDependencies"* in you `package.json` file:

```
"devDependencies": {
"gh-pages": "^1.0.0",
}
```

Then run `npm install` or `yarn install`.

Add a **deploy** command in your `package.json` file.

```
"scripts": {
"deploy": "rm -rf public && gatsby build --prefix-paths && gh-pages -d public",
}
```

In the `gatsby-config.js` add the path-prefix to be added to the links. The path-prefix should be the project name in your repository. (ex. `https://github.com/username/project-name` - your pathPrefix should be `/project-name`).

```
module.exports = {
pathPrefix: `/project-name`,
}
```

In your Github Repository, create a new branch `gh-pages`. Make sure that in `Settings` > `Github Pages` > `Source` your github pages branch is set to `gh-pages branch`.

After the setup, run `yarn deploy` or `npm run deploy`. Preview changes in your github page `https://username.github.io/project-name/`. You also can view your link under `Settings` > `Github Pages`.

0 comments on commit c9139bd

Please sign in to comment.