Skip to content

Add new github docs folder hosting option #520

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 4 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 5 additions & 6 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,15 +130,14 @@ function build(previousSizeMap) {
console.log('You can control this with the ' + chalk.green('homepage') + ' field in your ' + chalk.cyan('package.json') + '.');
console.log();
console.log('The ' + chalk.cyan('build') + ' folder is ready to be deployed.');
console.log('To publish it at ' + chalk.green(homepagePath) + ', run:');
console.log('To publish it at ' + chalk.green(homepagePath) + ' using the docs/ folder, run:');
console.log();
console.log(' ' + chalk.cyan('git') + ' commit -am ' + chalk.yellow('"Save local changes"'));
console.log(' ' + chalk.cyan('git') + ' checkout -B gh-pages');
console.log(' ' + chalk.cyan('git') + ' add -f build');
console.log(' ' + chalk.cyan('rm') + ' -rf docs/');
Copy link
Contributor

@fson fson Sep 16, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If ./docs/CNAME file exists, we should preserve it. (Our current deployment code accidentally removes it, see #654.) When the custom domain is edited trough the GitHub Pages settings, GitHub saves it in this file.

console.log(' ' + chalk.cyan('mv') + ' build/ docs/');
console.log(' ' + chalk.cyan('git') + ' add docs -A');
console.log(' ' + chalk.cyan('git') + ' commit -am ' + chalk.yellow('"Rebuild website"'));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The -a flag is probably not needed because we added the docs in the previous command?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fine to keep for consistency so people don’t think it matters and stress over it.

console.log(' ' + chalk.cyan('git') + ' filter-branch -f --prune-empty --subdirectory-filter build');
console.log(' ' + chalk.cyan('git') + ' push -f origin gh-pages');
console.log(' ' + chalk.cyan('git') + ' checkout -');
console.log(' ' + chalk.cyan('git') + ' push origin master');
console.log();
} else if (publicPath !== '/') {
// "homepage": "http://mywebsite.com/project"
Expand Down
13 changes: 7 additions & 6 deletions template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -850,16 +850,17 @@ Open your `package.json` and add a `homepage` field:
**The above step is important!**
Create React App uses the `homepage` field to determine the root URL in the built HTML file.

Now, whenever you run `npm run build`, you will see a cheat sheet with a sequence of commands to deploy to GitHub pages:
To host your app using the `/docs` folder you just need to move the `build` folder to a new `docs` folder, check in the new `docs` folder and set the GitHub Pages Source to the `master branch /docs folder` setting. [Read more here](https://help.github.com/articles/configuring-a-publishing-source-for-github-pages/#publishing-your-github-pages-site-from-a-docs-folder-on-your-master-branch) about setting up the GitHub settings.

You can use the following sequence of commands to clear out the old docs folder, move the build to the docs folder, and then check it in to the master branch:

```sh
git commit -am "Save local changes"
git checkout -B gh-pages
git add -f build
rm -rf docs/
mv build/ docs/
git add docs -A
git commit -am "Rebuild website"
git filter-branch -f --prune-empty --subdirectory-filter build
git push -f origin gh-pages
git checkout -
git push origin master
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

An extra space between push and origin.

```

You may copy and paste them, or put them into a custom shell script. You may also customize them for another hosting provider.
Expand Down