Skip to content

Commit 04c6e33

Browse files
dsernstrandycoulman
authored andcommitted
Always build before deploying to gh-pages (facebook#959)
* Always build before deploying to gh-pages * Add line to gh-pages deploy docs about CNAME file * Remove spaces in npm run command for Windows * Grammar nit * Minor tweaks
1 parent 6d05c6c commit 04c6e33

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

packages/react-scripts/template/README.md

+6-2
Original file line numberDiff line numberDiff line change
@@ -887,7 +887,7 @@ Open your `package.json` and add a `homepage` field:
887887
**The above step is important!**<br>
888888
Create React App uses the `homepage` field to determine the root URL in the built HTML file.
889889
890-
Now, whenever you run `npm run build`, you will see a cheat sheet with instructions on how to deploy to GitHub pages.
890+
Now, whenever you run `npm run build`, you will see a cheat sheet with instructions on how to deploy to GitHub Pages.
891891
892892
To publish it at [https://myusername.github.io/my-app](https://myusername.github.io/my-app), run:
893893
@@ -901,16 +901,20 @@ Add the following script in your `package.json`:
901901
// ...
902902
"scripts": {
903903
// ...
904-
"deploy": "gh-pages -d build"
904+
"deploy": "npm run build&&gh-pages -d build"
905905
}
906906
```
907907
908+
(Note: the lack of whitespace is intentional.)
909+
908910
Then run:
909911
910912
```sh
911913
npm run deploy
912914
```
913915
916+
You can configure a custom domain with GitHub Pages by adding a `CNAME` file to the `public/` folder.
917+
914918
Note that GitHub Pages doesn't support routers that use the HTML5 `pushState` history API under the hood (for example, React Router using `browserHistory`). This is because when there is a fresh page load for a url like `http://user.github.io/todomvc/todos/42`, where `/todos/42` is a frontend route, the GitHub Pages server returns 404 because it knows nothing of `/todos/42`. If you want to add a router to a project hosted on GitHub Pages, here are a couple of solutions:
915919
* You could switch from using HTML5 history API to routing with hashes. If you use React Router, you can switch to `hashHistory` for this effect, but the URL will be longer and more verbose (for example, `http://user.github.io/todomvc/#/todos/42?_k=yknaj`). [Read more](https://github.com/reactjs/react-router/blob/master/docs/guides/Histories.md#histories) about different history implementations in React Router.
916920
* Alternatively, you can use a trick to teach GitHub Pages to handle 404 by redirecting to your `index.html` page with a special redirect parameter. You would need to add a `404.html` file with the redirection code to the `build` folder before deploying your project, and you’ll need to add code handling the redirect parameter to `index.html`. You can find a detailed explanation of this technique [in this guide](https://github.com/rafrex/spa-github-pages).

0 commit comments

Comments
 (0)