React进阶(十):React项目结构启动原理详解
React调用顺序: index.html → index.js → components/组件 一般项目创建好后会有二个文件:index.html、index.js 现在我们看 my-app文件夹下的 public/index.html 和 src/index.js 的源码,我们可以在这里编写项目代码,但是注意 public/index.html 是启动http服务器的首页,src/index.js是编译的入口文件,只能叫index这个名字,改别的名字不行(除非你改配置文件,继续往下看)。 利用脚手架工具create-react-ap创建并启动项目后,打开 http://localhost:3000 ,F12查看 网页源码,你会看到 <script type="text/javascript" src="/static/js/bundle.js"></script> 在你的项目my-app你是看不到 /static/js/bundle.js 这个文件路径的,你也没有写配置文件 webpack.config.js 。 http服务器配置, 自动代开浏览器窗口, react, es6语法编译, babel-core, webpack等等这些 你都没下载、配置。其实,这些活,react-scripts 都帮你做了。 我们通过 npm run start 命令启动服, 运行项目。