Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

239
Views
¿Dónde está la conexión entre index.html e index.js en una aplicación Create-React-App?

Estoy empezando a jugar con la aplicación Create React, pero no puedo entender cómo se carga index.js dentro de index.html . Este es el código html:

 <!doctype html> <html lang="en"> <head> <meta charset="utf-8"> <meta name="viewport" content="width=device-width, initial-scale=1"> <link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico"> <!-- Notice the use of %PUBLIC_URL% in the tag above. It will be replaced with the URL of the `public` folder during the build. Only files inside the `public` folder can be referenced from the HTML. Unlike "/favicon.ico" or "favicon.ico", "%PUBLIC_URL%/favicon.ico" will work correctly both with client-side routing and a non-root public URL. Learn how to configure a non-root public URL by running `npm run build`. --> <title>React App</title> </head> <body> <div id="root"></div> <!-- This HTML file is a template. If you open it directly in the browser, you will see an empty page. You can add webfonts, meta tags, or analytics to this file. The build step will place the bundled scripts into the <body> tag. To begin the development, run `npm start`. To create a production bundle, use `npm run build`. --> </body> </html>

Pero no puedo ver en ninguna parte la importación de index.js . ¿Dónde está la conexión? ¿Qué me estoy perdiendo?

over 4 years ago · Santiago Trujillo
1 answers
Answer question

0

Debajo del capó, Create React App usa Webpack con html-webpack-plugin .

Nuestra configuración especifica que Webpack usa src/index.js como un "punto de entrada" . Así que ese es el primer módulo que lee, y sigue a otros módulos para compilarlos en un solo paquete.

Cuando webpack compila los activos, produce un solo paquete (o varios si usa la división de código). Hace que sus rutas finales estén disponibles para todos los complementos. Estamos usando uno de esos complementos para inyectar scripts en HTML.

Hemos habilitado html-webpack-plugin para generar el archivo HTML. En nuestra configuración, especificamos que debería leer public/index.html como plantilla. También hemos establecido la opción de inject en true . Con esa opción, html-webpack-plugin agrega un <script> con la ruta proporcionada por Webpack directamente en la página HTML final. Esta página final es la que obtiene en build/index.html después de ejecutar npm run build , y la que se sirve desde / cuando ejecuta npm start .

¡Espero que esto ayude! La belleza de la aplicación Create React es que en realidad no necesitas pensar en ello.

over 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!