简体   繁体   English

React:main.js 和 index.js 基本一样吗?

[英]React: Is main.js basically the same as index.js?

I have been using the command npx create-react-app my-app to build a new React app environment.我一直在使用命令npx create-react-app my-app来构建一个新的 React 应用程序环境。 It creates a simple and generic app with the React logo.它创建了一个带有 React 徽标的简单通用的应用程序。 It generates folders such as public with index.html and src with your typical files such as App.css , App.js , and index.js , among others.它使用您的典型文件(例如App.cssApp.jsindex.js等)生成带有index.html publicsrc文件夹。

While studying the code for reverse engineering purposes I noticed that some projects have a file called main.js .在研究用于逆向工程的代码时,我注意到有些项目有一个名为main.js的文件。 I assume people are manually creating this file and input code similar to pre-populated index.js code (automatically created by npx create-react-app my-app ).我假设人们正在手动创建此文件并输入类似于预先填充的index.js代码(由npx create-react-app my-app自动创建)的代码。 Essentially code for routing or calling components which gets rendered.本质上是用于路由或调用被渲染的组件的代码。

Are these two file names interchangeable or should they serve different purposes?这两个文件名是否可以互换或者它们应该用于不同的目的?

The file name for the JS file you use as your entry point is arbitrary.您用作入口点的 JS 文件的文件名是任意的。 Your bundler's (Webpack, Parcel, etc) configuration will determine which file it looks for.您的打包程序(Webpack、Parcel 等)的配置将决定它查找哪个文件。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM