[英]Why index.js is necessary even if I change my main entry point to app.js in package.json?
In my react application I've changed my main entry point from index.js to app.js.在我的反应应用程序中,我已将我的主要入口点从 index.js 更改为 app.js。 But somehow, if I don't import the app.js to my index.js, the program crashes.但不知何故,如果我不将 app.js 导入我的 index.js,程序就会崩溃。 Is there anyone who know the reason?有谁知道原因吗?
in the index.js
it searchs for an html
element with a specific id
most probably app
and put it inside the main
tag, and in the other hand if you notice that the root component div
id
is the same id
that the index.js
tries to search for在index.js
中,它会搜索html
元素,其中最有可能是app
的特定id
并将其放在main
标记中,另一方面,如果您注意到根组件div
id
与index.js
尝试的id
相同寻找
if you are using Create React App template then entry for your app is defined as src/index
in webpack config by default.如果您使用的是Create React App模板,则默认情况下,您的应用程序的条目在 webpack 配置中定义为src/index
。 check here: https://github.com/facebook/create-react-app/tree/master/packages/react-dev-utils#webpackhotdevclient在这里检查: https://github.com/facebook/create-react-app/tree/master/packages/react-dev-utils#webpackhotdevclient
Or if you are building your app from scratch then you can set your entry anything else in the webpack config file.或者,如果您从头开始构建您的应用程序,那么您可以在 webpack 配置文件中设置您的条目。
what if you want to change entry point in a create react app ?如果您想在创建反应应用程序中更改入口点怎么办?
at first Eject from CRA .首先从CRA弹出。 then create your own configuration including webpack然后创建您自己的配置,包括 webpack
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.