Create-react-app: deploying to github pages as subdirectory

Created on 24 Aug 2016  路  3Comments  路  Source: facebook/create-react-app

I have a small project with create-react-app, which I wanted to host on github pages. It would be:

stopachka.github.io/my-project

The help in our tutorial was awesome. However, when loading the project, assets are not correctly found.

In the generated index.html, we have ->

<script type="text/javascript" src="/static/js/main.ce66e420.js"></script>

This will direct github-pages too

https://stopachka.github.io/static/js/main.ce66e420.js

which return a 400. It should instead direct to ->

stopachka.github.io/my-project/static/js/main.ce66e420.js

Ideas:

  1. Make it so the source path does not have the / prepended to it.
  2. Find simple way to tell github-pages to do the right thing, or to prepend /my-project/ to the source path through some option
  3. If this is something that we don't want to support out of the box, we can tell users to eject, and write some quick instructions in the docs

Most helpful comment

I think the tutorial you linked to mentions the fix in the first sentence 馃槈 .

Open your package.json and add a homepage field:

 "homepage": "http://myusername.github.io/my-app",

If you do this, Create React App will know to use /my-app as root URL.

All 3 comments

I think the tutorial you linked to mentions the fix in the first sentence 馃槈 .

Open your package.json and add a homepage field:

 "homepage": "http://myusername.github.io/my-app",

If you do this, Create React App will know to use /my-app as root URL.

Clarified in the doc: 6aabe7e881f45fd52e8481bbe2463ea3fce8c1ba.
The most recent version also explains this behavior after build:

screen shot 2016-08-23 at 23 21 24

Ah, nice, thanks for the clarification @gaearon -- initially thought it was just meant as a flag to output the instructions. Super nice touch :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

fson picture fson  路  3Comments

xgqfrms-GitHub picture xgqfrms-GitHub  路  3Comments

jnachtigall picture jnachtigall  路  3Comments

oltsa picture oltsa  路  3Comments

barcher picture barcher  路  3Comments