8

I have a reactjs application that I created using the create-react-app. I have installed gh-pages and successfully deployed it to github pages (project page) using the following command:

gh-pages -d build

However, when I add a custom domain to my github project repository my application could not load the js and css files. My browser is looking for the following files:

http://my.custom.domain/<repo name>/static/css/main.caaf9ea4.css
http://my.custom.domain/<repo name>/static/js/main.76fabd7f.js

The correct link to load these files should be:

http://my.custom.domain/static/css/main.caaf9ea4.css
http://my.custom.domain/static/js/main.76fabd7f.js

In the GitHub repo pages, I have set custom domain to be 'my.custom.domain' (root domain without www). The source is gh-pages branch.

My DNS settings are:

  • A record, @, value: 192.30.252.153
  • A record, @, value: 192.30.252.154
  • CNAME record, www, value: username.github.io

Any ideas how to change the settings so that repo name is not added to the domain?

2 Answers 2

4

Make sure your package.json have the attribute homepage. e.g.

  "homepage": "https://<git-USER>.github.io/",

That's literally what I just did with my cra projet. If you want to take a look on my project just look at the develop branch. However, I haven't use gh-pages -d build. I just built the project myself and create the branch gh-pages and put the content of my build into it. It should be the same though.

Sign up to request clarification or add additional context in comments.

6 Comments

My GitHub page is for a project repo, so I have put the following attribute into package.json "homepage": "https://<gith-user>.github.io/<repo_name>",
And this is why your browser is looking for my.custom.domain/<repo name>/static/css/main.caaf9ea4.css
after changing the homepage attribute to point to my username.github.io, the site becomes not found. I believe the "homepage" attribute should be "git-user.githbu.io/reponame", according to create-react-app doc
I know, but when I switched to a custom domain I had to change my homepage setting. Anyway, have you done the step 5 of your guide? Added the CNAME file to your project. If you look into my github project I linked on my last comment, it is a create-react-app project hosted by gh-pages with a costum domain
I have finally solved this. Since I am using custom domain, I have set the homepage attribute to be https://my.custom.domain/ . I have also inadvertently deleted the CNAME file. After adding back the CNAME file, the site comes back to life. Thanks @kerrygougeon for your help.
|
2

Adding a copy CNAME script to my package.json scripts worked for me as it wasn't being published to gh-pages branch automatically in the React Create App build dir.

"copy": "cp ./CNAME ./build/CNAME",
"predeploy": "yarn build && yarn copy",

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.