Skip to content
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

Provide instructions on publishing GH Pages #162

Merged
merged 6 commits into from
Jul 24, 2016
Merged
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
4 changes: 4 additions & 0 deletions config/webpack.config.prod.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ var faviconPath = path.resolve(__dirname, relativePath, 'favicon.ico');
var buildPath = path.join(__dirname, isInNodeModules ? '../../..' : '..', 'build');
var homepagePath = require(path.resolve(__dirname, relativePath, 'package.json')).homepage;
var publicPath = homepagePath ? url.parse(homepagePath).pathname : '/';
if (!publicPath.endsWith('/')) {
// Prevents incorrect paths in file-loader
publicPath += '/';
}

module.exports = {
bail: true,
Expand Down
28 changes: 20 additions & 8 deletions scripts/build.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,13 @@ var config = require('../config/webpack.config.prod');

var isInNodeModules = 'node_modules' ===
path.basename(path.resolve(path.join(__dirname, '..', '..')));
var relative = isInNodeModules ? '../..' : '.';
var relative = isInNodeModules ? '../../..' : '..';
if (process.argv[2] === '--debug-template') {
relative = './template';
relative = '../template';
}
rimrafSync(relative + '/build');
var packageJsonPath = path.join(__dirname, relative, 'package.json');
var buildPath = path.join(__dirname, relative, 'build');
rimrafSync(buildPath);

webpack(config).run(function(err, stats) {
if (err) {
Expand All @@ -30,18 +32,28 @@ webpack(config).run(function(err, stats) {
}

var openCommand = process.platform === 'win32' ? 'start' : 'open';
var homepagePath = require(path.resolve(relative, 'package.json')).homepage;
var homepagePath = require(packageJsonPath).homepage;
console.log('Successfully generated a bundle in the build folder!');
console.log();
if (homepagePath) {
console.log('You can now deploy and serve it from ' + homepagePath + '.');
console.log('You can now deploy it to ' + homepagePath + '.');
console.log('For example, if you use GitHub Pages:');
console.log();
console.log(' git checkout -B gh-pages');
console.log(' git add -f build');
console.log(' git commit -am "Rebuild website"');
console.log(' git push origin :gh-pages');
console.log(' git subtree push --prefix build origin gh-pages');
console.log(' git checkout -');
console.log();
} else {
console.log('You can now serve it with any static server, for example:');
console.log('You can now serve it with any static server.');
console.log('For example:');
console.log();
console.log(' cd build');
console.log(' npm install -g http-server');
console.log(' hs');
console.log(' ' + openCommand + ' http://localhost:8080');
console.log();
}
console.log();
console.log('The bundle is optimized and ready to be deployed to production.');
});
3 changes: 2 additions & 1 deletion scripts/init.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,14 @@ module.exports = function(hostPath, appName, verbose) {
}

console.log('Success! Created ' + appName + ' at ' + hostPath + '.');
console.log();
console.log('Inside that directory, you can run several commands:');
console.log();
console.log(' * npm start: Starts the development server.');
console.log(' * npm run build: Bundles the app into static files for production.');
console.log(' * npm run eject: Removes this tool. If you do this, you can’t go back!');
console.log();
console.log('We suggest that you begin by typing:');
console.log();
console.log(' cd', cdpath);
console.log(' npm start');
console.log();
Expand Down
28 changes: 27 additions & 1 deletion template/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ Please be advised that this is also a custom feature of Webpack.

**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.

### Adding Flow
### Add Flow

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:

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

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

### Deploy to GitHub Pages

First, open your `package.json` and add a `homepage` field.
It could look like this:

```js
{
"name": "my-app",
"homepage": "http://myusername.github.io/my-app",
// ...
}
```

Now, whenever you run `npm run build`, you will see a cheat sheet with a sequence of commands to deploy to GitHub pages:

```sh
git checkout -B gh-pages
git add -f build
git commit -am "Rebuild website"
git push origin :gh-pages
git subtree push --prefix build origin gh-pages
git checkout -
```

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

### Something Missing?

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)