Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why is create-react-app's build directory in .gitignore?

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!

like image 288
MyNotes Avatar asked Apr 25 '17 21:04

MyNotes


People also ask

Should I react build in Gitignore?

If you use create react app, then a good . gitignore for react projects is included. You definitely want to keep node_modules in gitignore. Save this answer.

Does create react app create a folder?

Create a New React Project To create a new app/project using this tool, all we need to do is run the command "create-react-app" followed by the app name. After running the above command, a new folder called "my-sample-app" will get created and that would have all of our application code.

What is build directory in react?

npm run build creates a build directory with a production build of your app. Inside the build/static directory will be your JavaScript and CSS files. Each filename inside of build/static will contain a unique hash of the file contents. This hash in the file name enables long term caching techniques.

Why use Webpack instead of create react app?

Configuring webpack provides complete control over the development environment, while initializing with Create React App prevents any custom configuration by default.


1 Answers

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.

like image 169
mrinalmech Avatar answered Oct 27 '22 09:10

mrinalmech