简体   繁体   English

当我们 create-react-app 时,BUILD DIR 中的 HTML 如何链接到 SRC DIR 中的 JS?

[英]How HTML in BUILD DIR is linked to JS in SRC DIR when we create-react-app?

When we run command create-react-app to configure our initial react app.当我们运行命令create-react-app来配置我们的初始反应应用程序时。 Then it creates the app directory with the given name with sub-directories in it.然后它创建具有给定名称的应用程序目录,其中包含子目录。 When we run the app by using npm start then it deploys the index.html file in the public directory within APP directory.当我们使用npm start运行应用程序时,它会在 APP 目录的公共目录中部署index.html文件。 My question is how index.js file in src directory is linked to index.html file while there is no <script> tag linking it?我的问题是src目录中的index.js文件如何链接到index.html文件,而没有<script>标记链接它?

The magic (logic) lies in the package “react-scripts”.神奇(逻辑)在于 package “react-scripts”。 It's a library of scripts which does the bundling of your source code and manipulate the HTML with bundled script.它是一个脚本库,可以捆绑您的源代码并使用捆绑的脚本操作 HTML。

By the way, if you want to study the code of the script, just run npm eject and you'll get scripts folder in root which will contain start and build script.顺便说一句,如果您想研究脚本的代码,只需运行npm eject ,您将在根目录中获得scripts文件夹,其中包含startbuild脚本。

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

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