简体   繁体   中英

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. It creates a simple and generic app with the React logo. 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.

While studying the code for reverse engineering purposes I noticed that some projects have a file called 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 ). 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. Your bundler's (Webpack, Parcel, etc) configuration will determine which file it looks for.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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