17

This is clearly something I'm misunderstanding but I'm desperately struggling to find an answer.

I've been teaching myself React with create-react-app, I've run "npm run build" to spit out my finished project, and I have the project pushed to a private bitbucket repo.

My expectation would be to then SSH to my server, and git clone the /build directory in order to make this project live. Obviously that is possible (if I removed /build from .gitignore), but since the /build directory is in .gitignore this clearly isn't the intended/desired behaviour.

So, my question is - what is? How does one publish a completed build to server without pulling from git (and obviously without FTP)?

Thanks!

MyNotes
  • 426
  • 4
  • 11
  • did you read the deployment instructions? https://github.com/facebookincubator/create-react-app/blob/master/packages/react-scripts/template/README.md#deployment – azium Apr 25 '17 at 21:53

1 Answers1

14

The build directory is in .gitignore as it can be generated from the existing files.

To minimize upload/download time only essential items should be kept in the git repo. Anything that can be generated need not be in the repo (The build directory in this case).

If you are working on a server that has node (AWS, Heroku etc) you can git clone the entire repo on the server and then run npm run build there (after npm install). Then you can do something like

npm install -g serve
serve -s build

The serve module serves static files and you pass the build folder as a parameter.

If you are working on a more old style server like Apache static hosting with cPanel etc then you will need to upload the entire build directory containing static files and index.html.

mrinalmech
  • 2,065
  • 1
  • 20
  • 18