Bootstrap your Firebase + React project
- Create a Firebase account
- Create a new project
- Go to
Hosting
- Select
Get started
and follow the steps (install the CLI, create a directory for your project and initialize it with firebase CLI) firebase init
- Chose all options (database, hosting, and functions).
- Select the project you created in step 2
- Select the default for the database rules file
- Select Y to install dependencies now
- When asked about the public directory use
app/build
(this is important for React. - For the index.html option I chose
Y
to have a single page app. firebase deploy
the default files so that you can test it. You will replace this with your files later.- Now you can go to the custom Firebase URL (printed in the console) to look at your site.
Configure Firebase Hosting to use your domain
Assuming you already purchased your domain name (no need for hosting since you will use that from Firebase). If you don’t have one you can get it from somewhere like godaddy.com.
- In the Firebase console site press the
CONNECT DOMAIN
button - Enter your domain (e.g. crelit.com)
- Firebase will prompt you to create a
TXT
record to prove that you own the domain - Go to your domain management site (e.g. godaddy.com)
- Create a
TXT
record as instructed in the Firebase page - While you wait for the record to propagate, remove all
CNAME
andA
records in your domain management service. - Now try to verify (there is a button in the Firebase console for it) the domain. When verified you will get more instructions.
- Create an
A
record (it will actually be 2 that Firebase gives you) for your domain (for example crelit.com). - Firebase now will show you a banner saying something like “Would you like to connect www.crelit.com too?” Go ahead and press
CONNECT
and then pressCONTINUE
. The defaults will make it so that all traffic is redirected to crelit.com. - Follow the instructions to add another A record (2 again) for the www. (example www.crelit.com). This will make it so that regardless of what you type (www.crelit.com or crelit.com) the user will always end up in crelit.com. This also helps with page ranking.
- Try visiting your site. It may take up to an hour for the domain to properly work until the SSL certificates (what makes HTTPS secure) propagate. Sometimes it is very fast. Both (www.yoursite.com and yoursite.com) should end at yoursite.com. If not there is something configured wrong.
- Now you have the same website that does nothing, but with your own domain. The simplest HTTPS configuration I’ve ever seen.
Bootstrap React
yarn global add create-react-app
- Go to the directory where you initialized Firebase
- Delete the
app
directory create-react-app app
cd app
- The
README.md
file included has information on the generated project. Also see the links below to learn more about React
Run a test server
Use yarn start
. This will start the React project in your server. Save changes to your project files and the web page will reload.
Generate a build optimized build
Use yarn build
. The optimized version will be in app/build
ready to be deployed.
Deploy the optimized version to Firebase
Use firebase deploy
which will deploy the content of app/build
to the server.
What’s Next?
- To learn more about React — https://facebook.github.io/react/
- To learn more about Firebase — https://firebase.google.com/products/
Like this article? Press the heart below and share it! Know a better way to do things or just want to say hi? Great! I love learning new and better ways :) Write me at hey at itsmeeric.com.