简体   繁体   English

reactjs create-react-app在src文件夹中缺少index.html

[英]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.

相关问题 create-react-app中的src / images文件夹 - src/images folder in create-react-app Create-React-App 应用程序中 index.html 和 index.js 之间的连接在哪里? - Where's the connection between index.html and index.js in a Create-React-App application? 我可以在没有 npm 启动和 npx create-react-app 的情况下使用 React 运行 index.html 吗? - Can I run index.html with React without npm start and npx create-react-app? React-snapshot 使用 create-react-app 和 serve 在所有路由上预渲染 index.html - React-snapshot pre-renders index.html on all routes with create-react-app and serve 如何将 create-react-app 与提供 index.html 的后端一起使用? - How to use create-react-app with a backend which serves index.html? 从 create-react-app 中的 service worker 缓存中排除 index.html - exclude index.html from service worker cache in create-react-app 如何使用 index.php 而不是 index.html 在 XAMP 上运行由 create-react-app 创建的 ReactApp? - How to run ReactApp created by create-react-app on XAMP using index.php rather than index.html? 我正在使用create-react-app,需要在没有服务器的情况下直接在浏览器中打开build / index.html - I'm using create-react-app and I need to open build/index.html in browser directly without a server 在位于 SRC 文件夹中的 index.html 文件中注册 service-worker - ReactJS - Register a service-worker in index.html file that's located in SRC folder - ReactJS 将create-react-app reactJs与mysql连接 - To connect create-react-app reactJs with mysql
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM