简体   繁体   English

即使我在 package.json 中将主入口点更改为 app.js,为什么还需要 index.js?

[英]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 forindex.js中,它会搜索html元素,其中最有可能是app的特定id并将其放在main标记中,另一方面,如果您注意到根组件div idindex.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.

相关问题 index.js 和 package.json 中的 Ember 名称不匹配 - Ember mismatch names in index.js and package.json 如何从 /dist/app.js 引用我的 package.json - How to refer my package.json from /dist/app.js 更改没有index.js的NPM入口点 - Change NPM entry point without an index.js 更改/添加 index.js 的 create-react-app 入口点或位置 - Change/add create-react-app entry point or location of index.js package.json中js浏览器库的入口点 - Entry point for a js browser lib in package.json 即使使用导出,Index.js 也不会导入 App.js - Index.js is not importing App.js even when when export is used 为什么webpack忽略index.js,尽管它与我的app.js位于同一目录中,但编译良好 - Why does webpack ignore the index.js although it's in the same directory of my app.js, which is compiled fine 在 app.js 中导入 js 文件时出现未知文件扩展名错误,使用类型:package.json 中的模块 - I am getting unknown file extension error while importing a js file in app.js, using type: module in package.json NextJs 中的 index.js 和 _app.js 有什么区别? - Whats is the difference between index.js and _app.js in NextJs? RequireJS搜索app.app而不是app.js(其中app.js是在data-main中指定的入口点) - RequireJS search for app.app instead of app.js (where app.js is entry point specified in data-main)
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM