【发布时间】:2021-10-21 13:24:03
【问题描述】:
我开始使用 Create React 应用程序,但我不明白 index.js 是如何加载到 index.html 中的。这是html代码:
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico">
<!--
Notice the use of %PUBLIC_URL% in the tag above.
It will be replaced with the URL of the `public` folder during the build.
Only files inside the `public` folder can be referenced from the HTML.
Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will
work correctly both with client-side routing and a non-root public URL.
Learn how to configure a non-root public URL by running `npm run build`.
-->
<title>React App</title>
</head>
<body>
<div id="root"></div>
<!--
This HTML file is a template.
If you open it directly in the browser, you will see an empty page.
You can add webfonts, meta tags, or analytics to this file.
The build step will place the bundled scripts into the <body> tag.
To begin the development, run `npm start`.
To create a production bundle, use `npm run build`.
-->
</body>
</html>
但我在任何地方都看不到index.js 的导入。连接在哪里?我错过了什么?
【问题讨论】:
-
你如何提供你的内容?
-
我没有更改任何默认值,我只是这样做:
create-react-app my-app并使用 webstorm 打开项目,然后我执行 npm start,但我的问题是 index.html 如何知道必须加载 index.js?写在哪里? -
webpack.github.io/docs/webpack-dev-server.html Webpack-dev-server 在开发中为你处理这个问题。
-
@NicklasWinger 哪里可以找到配置文件了解机制?
-
您可以运行
npm run eject来手动控制配置。我建议从头开始做一个更基本的设置,以完全了解发生了什么:)
标签: javascript html reactjs create-react-app