[英]reactjs create-react-app missing index.html in src folder
I am using create-react-app
command to create an empty app, I got these file in src
folder:我正在使用
create-react-app
命令创建一个空的应用程序,我在src
文件夹中得到了这些文件:
App.css
App.js
App.test.js
index.css
index.js
logo.svg
serviceWorker.js
setupTests.js
After I make a build via npm run build
, index.html
is generated in build
folder.通过
npm run build
,会在build
文件夹中生成index.html
。
I created one manually in src
folder, but the build doesn't take it.我在
src
文件夹中手动创建了一个,但构建不接受它。
The index.js
content is: index.js
内容是:
ReactDOM.render(
<React.StrictMode>
<App />
</React.StrictMode>,
document.getElementById('root')
);
There is no root
element at all.根本没有
root
元素。
I need to add in some <script>
tag inside index.html
to include some third party scripts (which cannot be installed by nodejs), where can I add them since it is not existed in src
folder?我需要在
index.html
添加一些<script>
标签以包含一些第三方脚本(无法由 nodejs 安装),我可以在哪里添加它们,因为它不存在于src
文件夹中?
You have to check public folder in the root directory only.您只需检查根目录中的公用文件夹。 You will get your index.html would be there.
你会得到你的 index.html 会在那里。 and your index.js file which is in src folder is the single point of connection between them(main index.html in public folder and all Javascript code which is in src folder).
src 文件夹中的 index.js 文件是它们之间的单点连接(公共文件夹中的主 index.html 和 src 文件夹中的所有 Javascript 代码)。
You should download that third party lybrairie and put it inside of the public directory and include a script
tag inside of the index.html
file which is inside of the public
directory of your project.你应该下载第三方lybrairie并把它里面的公共目录中,包括一个
script
中的标签中index.html
文件,该文件是内部public
项目的目录。
The configuration of the create-react-app
is using webpack which is preconfigure to load the public\\index.html
file as the template in which the compiled bundle will be injected. create-react-app
的配置是使用预先配置好的 webpack 来加载public\\index.html
文件作为模板,编译后的包将被注入到其中。
If you want to use the index.html
file which you have create inside of the src
folder you should run npm run eject
which will put all create-react-app configuration at your disposal in your project directory and you could perform changes to webpack figuration file to load src/index.html
file as the template in which the compiled bundle will be injected.如果你想使用你在
src
文件夹中创建的index.html
文件,你应该运行npm run eject
这会将所有 create-react-app 配置放在你的项目目录中,你可以对 webpack 配置进行更改文件加载src/index.html
文件作为模板,编译包将被注入到其中。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.