简体   繁体   English

如何使用 create-react-app 部署 React 应用程序

[英]How to deploy a react app using create-react-app

I am new to react.js and trying to convert my websites content into react components as a way to learn it with friends.我是react.js的新手,并试图将我的网站内容转换为 react 组件,作为与朋友一起学习的一种方式。 I am using npx create-react-app and want to put the app online with Google Firebase .我正在使用npx create-react-app并希望通过Google Firebase将该应用程序联机。 The deploying was successful - but I could not see the localhost page with the components I am seeing when I run npm start .部署成功 - 但是当我运行npm start时,我看不到包含组件的 localhost 页面。 Instead there is an empty page.取而代之的是一个空白页面。

I followed some online guides and run npm run build .我遵循了一些在线指南并运行npm run build

Than, I tried to add "homepage:" to package.json and set it as "mydomain.com" or "."然后,我尝试将"homepage:"添加到package.json并将其设置为"mydomain.com""." . .

I have also changed my Firebase public directory to the build folder (instead of public ).我还将我的Firebase公共目录更改为构建文件夹(而不是public )。

Nothing yet worked.还没有任何工作。 does anyone has an idea why?有人知道为什么吗?

Thanks to goto1 I looked again in react documentations and found out about issue #2440.感谢 goto1,我再次查看了 react 文档并发现了问题 #2440。 Adding:添加:

"headers": [
  {"source": "/service-worker.js", "headers": [{"key": "Cache-Control", "value": "no-cache"}]}
]

in firebase.json solved it for me.firebase.json中为我解决了这个问题。

See more at: https://create-react-app.dev/docs/deployment/#firebase在以下位置查看更多信息: https://create-react-app.dev/docs/deployment/#firebase

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM