Skip to content

Commit 458d3f9

Browse files
authored
Provide instructions on publishing GH Pages (#162)
* Provide instructions on GH Pages deploy * Add docs for GH Pages deployment * Prevent incorrect paths in file-loader * Minor message tweaks * Update README.md * Fix relative paths
1 parent ef4f8e9 commit 458d3f9

File tree

4 files changed

+53
-10
lines changed

4 files changed

+53
-10
lines changed

config/webpack.config.prod.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ var faviconPath = path.resolve(__dirname, relativePath, 'favicon.ico');
2929
var buildPath = path.join(__dirname, isInNodeModules ? '../../..' : '..', 'build');
3030
var homepagePath = require(path.resolve(__dirname, relativePath, 'package.json')).homepage;
3131
var publicPath = homepagePath ? url.parse(homepagePath).pathname : '/';
32+
if (!publicPath.endsWith('/')) {
33+
// Prevents incorrect paths in file-loader
34+
publicPath += '/';
35+
}
3236

3337
module.exports = {
3438
bail: true,

scripts/build.js

Lines changed: 20 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,13 @@ var config = require('../config/webpack.config.prod');
1616

1717
var isInNodeModules = 'node_modules' ===
1818
path.basename(path.resolve(path.join(__dirname, '..', '..')));
19-
var relative = isInNodeModules ? '../..' : '.';
19+
var relative = isInNodeModules ? '../../..' : '..';
2020
if (process.argv[2] === '--debug-template') {
21-
relative = './template';
21+
relative = '../template';
2222
}
23-
rimrafSync(relative + '/build');
23+
var packageJsonPath = path.join(__dirname, relative, 'package.json');
24+
var buildPath = path.join(__dirname, relative, 'build');
25+
rimrafSync(buildPath);
2426

2527
webpack(config).run(function(err, stats) {
2628
if (err) {
@@ -30,18 +32,28 @@ webpack(config).run(function(err, stats) {
3032
}
3133

3234
var openCommand = process.platform === 'win32' ? 'start' : 'open';
33-
var homepagePath = require(path.resolve(relative, 'package.json')).homepage;
35+
var homepagePath = require(packageJsonPath).homepage;
3436
console.log('Successfully generated a bundle in the build folder!');
35-
console.log();
3637
if (homepagePath) {
37-
console.log('You can now deploy and serve it from ' + homepagePath + '.');
38+
console.log('You can now deploy it to ' + homepagePath + '.');
39+
console.log('For example, if you use GitHub Pages:');
40+
console.log();
41+
console.log(' git checkout -B gh-pages');
42+
console.log(' git add -f build');
43+
console.log(' git commit -am "Rebuild website"');
44+
console.log(' git push origin :gh-pages');
45+
console.log(' git subtree push --prefix build origin gh-pages');
46+
console.log(' git checkout -');
47+
console.log();
3848
} else {
39-
console.log('You can now serve it with any static server, for example:');
49+
console.log('You can now serve it with any static server.');
50+
console.log('For example:');
51+
console.log();
4052
console.log(' cd build');
4153
console.log(' npm install -g http-server');
4254
console.log(' hs');
4355
console.log(' ' + openCommand + ' http://localhost:8080');
56+
console.log();
4457
}
45-
console.log();
4658
console.log('The bundle is optimized and ready to be deployed to production.');
4759
});

scripts/init.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,13 +69,14 @@ module.exports = function(hostPath, appName, verbose) {
6969
}
7070

7171
console.log('Success! Created ' + appName + ' at ' + hostPath + '.');
72-
console.log();
7372
console.log('Inside that directory, you can run several commands:');
73+
console.log();
7474
console.log(' * npm start: Starts the development server.');
7575
console.log(' * npm run build: Bundles the app into static files for production.');
7676
console.log(' * npm run eject: Removes this tool. If you do this, you can’t go back!');
7777
console.log();
7878
console.log('We suggest that you begin by typing:');
79+
console.log();
7980
console.log(' cd', cdpath);
8081
console.log(' npm start');
8182
console.log();

template/README.md

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ Please be advised that this is also a custom feature of Webpack.
219219

220220
**It is not required for React** but many people enjoy it (and React Native uses a similar mechanism for images). However it may not be portable to some other environments, such as Node.js and Browserify. If you prefer to reference static assets in a more traditional way outside the module system, please let us know [in this issue](https://github.com/facebookincubator/create-react-app/issues/28), and we will consider support for this.
221221

222-
### Adding Flow
222+
### Add Flow
223223

224224
Flow typing is currently [not supported out of the box](https://github.com/facebookincubator/create-react-app/issues/72) with the default `.flowconfig` generated by Flow. If you run it, you might get errors like this:
225225

@@ -275,6 +275,32 @@ module.name_mapper='^\(.*\)\.\(jpg\|png\|gif\|eot\|svg\|ttf\|woff\|woff2\|mp4\|w
275275

276276
We will consider integrating more tightly with Flow in the future so that you don’t have to do this.
277277

278+
### Deploy to GitHub Pages
279+
280+
First, open your `package.json` and add a `homepage` field.
281+
It could look like this:
282+
283+
```js
284+
{
285+
"name": "my-app",
286+
"homepage": "http://myusername.github.io/my-app",
287+
// ...
288+
}
289+
```
290+
291+
Now, whenever you run `npm run build`, you will see a cheat sheet with a sequence of commands to deploy to GitHub pages:
292+
293+
```sh
294+
git checkout -B gh-pages
295+
git add -f build
296+
git commit -am "Rebuild website"
297+
git push origin :gh-pages
298+
git subtree push --prefix build origin gh-pages
299+
git checkout -
300+
```
301+
302+
You may copy and paste them, or put them into a custom shell script. You may also customize them for another hosting provider.
303+
278304
### Something Missing?
279305

280306
If you have ideas for more “How To” recipes that should be on this page, [let us know](https://github.com/facebookincubator/create-react-app/issues) or [contribute some!](https://github.com/facebookincubator/create-react-app/edit/master/template/README.md)

0 commit comments

Comments
 (0)