将网络应用程序上传到 Firebase 的过程
Procedure uploading a web-app to Firebase
虽然我过去在 Firebase
上设置了几个网络应用程序。这次上传到服务器时遇到了问题
这个应用程序的特别之处在于我使用的是 React。
我关注 this tutorial,在终端中执行了以下操作:
$ npx create-react-app myapp
$ cd myapp/
$ npm install firebase --save
$ npm start
然后在花了很多时间在 React 方面工作以获得足够接近我口味的东西之后,此时我可以在端口 3000 (http:// localhost:3000/),如我所料,在浏览器中。它还可以根据需要访问服务器上的实时数据库。我的下一步是让应用程序本身 运行 在服务器上,而不仅仅是像现在这样在我的本地主机上。 我需要为此做什么?
我根据我以前使用 Firebase 的经验进行了一些试验,运行ning“firebase 部署”(+ 其他一些东西),但它不起作用。该应用程序不在服务器上。更准确地说,它显示了一个白页。
作为补充信息,这是我的 firebase.json 文件:
{
"database": {
"rules": "database.rules.json"
},
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
这就是 public 目录的样子:
...$ ls public/
404.html index.html logo512.png robots.txt
favicon.ico logo192.png manifest.json
...$
您必须构建您的 React 应用程序(npm run build
或您的构建命令),然后确保 firebase.json
中的 public
目录是您的 build
文件夹。
{
"hosting": {
"public": "build", // name of build output directory
}
}
在您的情况下,它被设置为 public
,因此正在部署该目录。
虽然我过去在 Firebase
上设置了几个网络应用程序。这次上传到服务器时遇到了问题
这个应用程序的特别之处在于我使用的是 React。
我关注 this tutorial,在终端中执行了以下操作:
$ npx create-react-app myapp
$ cd myapp/
$ npm install firebase --save
$ npm start
然后在花了很多时间在 React 方面工作以获得足够接近我口味的东西之后,此时我可以在端口 3000 (http:// localhost:3000/),如我所料,在浏览器中。它还可以根据需要访问服务器上的实时数据库。我的下一步是让应用程序本身 运行 在服务器上,而不仅仅是像现在这样在我的本地主机上。 我需要为此做什么? 我根据我以前使用 Firebase 的经验进行了一些试验,运行ning“firebase 部署”(+ 其他一些东西),但它不起作用。该应用程序不在服务器上。更准确地说,它显示了一个白页。
作为补充信息,这是我的 firebase.json 文件:
{
"database": {
"rules": "database.rules.json"
},
"hosting": {
"public": "public",
"ignore": [
"firebase.json",
"**/.*",
"**/node_modules/**"
]
}
}
这就是 public 目录的样子:
...$ ls public/
404.html index.html logo512.png robots.txt
favicon.ico logo192.png manifest.json
...$
您必须构建您的 React 应用程序(npm run build
或您的构建命令),然后确保 firebase.json
中的 public
目录是您的 build
文件夹。
{
"hosting": {
"public": "build", // name of build output directory
}
}
在您的情况下,它被设置为 public
,因此正在部署该目录。