Under the hood, the Create React application uses Webpack with the html-webpack-plugin .
Our configuration indicates that Webpack uses src/index.js as the "entry clause" . Thus, this is the first module that it reads, and it follows other modules from it in order to compile them into one package.
When webpack compiles assets, it creates single ones (or several if you use code splitting). This makes their final paths accessible to all plugins. We use one such plugin to enter scripts in HTML.
We created html-webpack-plugin to create the HTML file. In our configuration, we indicated that it should read public/index.html as a template. We also set the inject parameter to true . With this option, html-webpack-plugin adds <script> using the path provided by Webpack directly to the final HTML page. This final page is the one you got in build/index.html after starting npm run build , and the one that gets from / when starting npm start .
Hope this helps! The beauty of the Create React app - you really don't need to think about it.
Dan abramov
source share