- Progressive Web Apps with React
- Scott Domes
- 469字
- 2021-07-08 09:36:23
Deploying Firebase
As I mentioned earlier, Firebase comes with a baked-in deployment solution. Let's get our app up and working on the real live web! Here's how to do it:
- To do so, we'll first need to install the Firebase command-line tools:
npm install -g firebase-tools
Don’t forget the -g. This flag installs the tools globally on your machine.
- The next step is to log in to our Firebase tools:
firebase login
- To complete our Firebase tools setup, we can now initialize our app as a Firebase project, similar to what we did with npm. Ensure that you run this from the root of the project folder:
firebase init
In the first question it then prompts you for, use the arrow keys and the Spacebar to select both Functions and Hosting. We will use Firebase's Cloud Functions later on. Don't select Database, that's for configuring database rules locally; we'll rely on the Firebase console instead.
Your selections should look like this:

When it asks for a default Firebase project, select chatastrophe(or whatever you named this project in the Firebase console).
For the question Do you want to install dependencies with npm now?, enter y.
Next, it'll ask you what folder you want to use as your public directory. Enter build, not public. Firebase is asking what folder to use to deploy your project; we want our final compiled build, including our transpiled JavaScript and therefore, we want the build folder.
Let's move to the next question now! Do we want to configure our app as a single-page application? Heck yes. Decline overwriting index.html though (however, no worries if you say yes; we regenerate our build/index.html every time we run our build command).
Okay, we're all set up to deploy. Let's make an npm script to make our lives easier.
Every time we deploy, we'll want to rerun our build command to ensure that we have the freshest build of our project. Our npm script will thus combine both, added into our package.json:
"scripts": {
"build": "node scripts/copy_assets.js && node_modules/.bin/webpack --config webpack.config.prod.js",
"start": "node_modules/.bin/webpack-dev-server",
"deploy": "npm run build && firebase deploy"
},
Run the script with yarn deploy, and then check out the URL it displays in the Terminal. If all goes well, your app should look exactly like it does in development. Open up the console and check for warnings; if you see any, skim the Webpack chapter and see whether you missed any of the settings for our webpack.config.prod.js (you can take a peek at the final file in the branch here: https://github.com/scottdomes/chatastrophe/tree/chapter4):

Awesome! We have a deployed app ready to share with our friends. The only problem is what we discussed at the end of the last chapter; it doesn't actually do much yet.
Let's get started with using Firebase by adding an authentication process.
- Getting Started with ResearchKit
- Unity 2020 Mobile Game Development
- 我的第一本算法書
- C語言程序設(shè)計(jì)實(shí)訓(xùn)教程
- 基于免疫進(jìn)化的算法及應(yīng)用研究
- aelf區(qū)塊鏈應(yīng)用架構(gòu)指南
- Python Geospatial Development(Second Edition)
- Spring快速入門
- Visual C++開發(fā)入行真功夫
- 零基礎(chǔ)入門學(xué)習(xí)Python(第2版)
- 從零開始學(xué)Linux編程
- Java SE實(shí)踐教程
- ASP.NET 4.0 Web程序設(shè)計(jì)
- HTML5移動(dòng)前端開發(fā)基礎(chǔ)與實(shí)戰(zhàn)(微課版)
- Unity虛擬現(xiàn)實(shí)開發(fā)圣典