0

I want to push a React app to GitHub and subsequently point the build folder as the root to GitHub pages.

There seems to be a doc here : https://create-react-app.dev/docs/deployment/#github-pages

I want to know why this won't work ?

  1. I push the entire react app to github.
  2. I do npm run build on my localhost.
  3. I set source to /build instead of /root - but I can't seem to set this

Is there a way to set the path (source) of the custom domain to /build?

enter image description here

anjanesh
  • 3,771
  • 7
  • 44
  • 58
  • No, /build isn't a supported source: https://docs.github.com/en/github/working-with-github-pages/about-github-pages#publishing-sources-for-github-pages-sites. Nor is /root, for that matter. But the gh-pages *package* on the page you link to can deploy from a specified directory to the root of the gh-pages *branch*, which is a supported source. It's unclear what you're actually doing. – jonrsharpe Mar 14 '21 at 10:02
  • You can use github actions ( Template already available) to deploy /build folder. https://github.com/marketplace/actions/deploy-to-github-pages – GokulnathP Mar 14 '21 at 10:11
  • I felt these steps - https://github.com/gitname/react-gh-pages - was long and is easier to just point the source to a subl-folder - which in this case is build. Thought that was possible. – anjanesh Mar 14 '21 at 10:16
  • Note it's "/ (root)" (the root directory of the repo, being represented as /) not "/root" - and again "/build" isn't a supported source. Also the build directory is ignored by default, you shouldn't generally put generated code in source control. What the recommended package does is create a new git repo in the specified directory, so the build outputs *are* at the root, and push that to the gh-pages branch. – jonrsharpe Mar 14 '21 at 10:17
  • You *could* move the build outputs to the /docs directory, see https://stackoverflow.com/q/41495658/3001761, but then you'd have extra work to remember to keep that in sync with the source code - again, I wouldn't generally commit generated code alongside the source code. – jonrsharpe Mar 14 '21 at 10:19
  • "What the recommended package does is create a new git repo" - did you mean branch which is `gh-pages` ? it doesn't seem it'll create a new repo. – anjanesh Mar 14 '21 at 10:31

0 Answers0