Where's the connection between index.html and index.js in a Create-React-App application?

前端 未结 1 1351
野性不改
野性不改 2020-12-02 07:42

I\'m starting to play with the Create React App, but I can\'t understand how the index.js is loaded inside index.html. This is the html code:

<
相关标签:
1条回答
  • 2020-12-02 07:54

    Under the hood, Create React App uses Webpack with html-webpack-plugin.

    Our configuration specifies that Webpack uses src/index.js as an “entry point”. So that’s the first module it reads, and it follows from it to other modules to compile them into a single bundle.

    When webpack compiles the assets, it produces a single (or several if you use code splitting) bundles. It makes their final paths available to all plugins. We are using one such plugin for injecting scripts into HTML.

    We have enabled html-webpack-plugin to generate the HTML file. In our configuration, we specified that it should read public/index.html as a template. We have also set inject option to true. With that option, html-webpack-plugin adds a <script> with the path provided by Webpack right into the final HTML page. This final page is the one you get in build/index.html after running npm run build, and the one that gets served from / when you run npm start.

    Hope this helps! The beauty of Create React App is you don’t actually need to think about it.

    0 讨论(0)
提交回复
热议问题