How to deploy a React app to Firebase
Here is how you can easily deploy your React app to Firebase.
In my example I used the create-react-app to get started, I'm going to assume that you are done with developing your react app and that you ran the npm run build command and that Webpack had bundle your development app into a optimized production build. That is actually what gets deploy - the bundled static resources, typically located in the build folder.
If you don't have one, you will need to register for a Firebase account, it's free. After registering just go the the Console and Add a new project, we will reference this project in Firebase CLI.
- Now just install Firebase tools by running: npm install -g firebase-tools this will install it globally so you can access it easily from your terminal in the future.
- Second, run the: firebase login command which will open up the login page in your browser prompting you to login into your Firebase account
- Third run: firebase init command which will prompt you to select which features do you want to use, in this case we want to use the hosting
- Firebase CLI will ask you about which directory do you want to use as your public directory, in our case we'll just set it to: build
- Depending on what kind of app are you building, single page or not, Firebase will ask you to chose, in my case I just choose no
- Firebase will prompt us that we already have an index.html file in our build directory, select "n" as we don't won't our file overridden
- Lastly just run Firebase deploy which will deploy our static assets and give us the live link where we will be able to see our app, and that's pretty much it!
Now that the setup is complete, any time you make any future updates to your app, all you need to do is to run two commands: npm run build and firebase deploy easy peasy!
Comments
Post a Comment