【发布时间】:2020-12-19 19:30:19
【问题描述】:
我是 react.j 的新手,仍在学习。我制作了一个测试网站,并希望将其托管在 firebase 上。当我部署我的应用程序时,只呈现了我的 index.html 文件夹(背景显示,因为它是在 index.html 中声明的),但我在 src 中的任何 javascript 文件都没有被呈现。我的网站在本地运行文件,但无法进行部署。
Here is my public folder with my index.html
Here is my src folder with my index.js and other js files
这是我的 index.html 代码
<html lang="en">
<head>
<meta charset="utf-8" />
<link rel="icon" href="%PUBLIC_URL%/favicon.ico" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<meta name="theme-color" content="#000000" />
<meta name="description" content="Web site created using create-react-app" />
<link rel="apple-touch-icon" href="%PUBLIC_URL%/logo192.png" />
<link rel="manifest" href="%PUBLIC_URL%/manifest.json" />
<title>React App</title>
</head>
<body
style="
text-align: center;
background-image: url('https://www.treehugger.com/thmb/7KYmuAKvOj3cDpRK47BMO8rwUDU=/768x0/filters:no_upscale():max_bytes(150000):strip_icc():format(webp)/__opt__aboutcom__coeus__resources__content_migration__treehugger__images__2019__08__clouds-2dcb0f4cf2934a48bd173b6474c4784c.jpg');
background-position: center;
background-repeat: no-repeat;
background-size: 100%;
background-attachment: fixed;
"
>
<div id="root"></div>
这是我的 index.js 代码
import React from 'react';
import ReactDOM from 'react-dom';
import App from './App';
import * as serviceWorker from './serviceWorker';
// import './index.css';
ReactDOM.render(
<div className="Outer">
<App />
</div>,
document.getElementById('root')
);
serviceWorker.unregister();
我的构建中的 index.html 与上面显示的我的公用文件夹中的相同。
这是现在的网站:https://weatherman-9860a.web.app/
我想我错过了一步,因为我只是在学习。请帮我。谢谢!
【问题讨论】:
-
你附上了相同的截图
-
很抱歉。我更新了。
-
我不了解您的环境以及您如何部署项目。但是你在 build/dist 目录中看到了什么?通常你在部署之前(或自动)构建你的应用程序。您的主机从 build/dist 文件夹中提供静态文件
-
我更新了帖子以包含我的构建文件夹。如果您还需要什么,请告诉我。
-
您需要在构建文件夹中配置您的网站。现在你提供公用文件夹
标签: javascript html reactjs firebase-hosting