create-react-app(v5) 需要node版本>=14 npm start 文档地址:https://create-react-app.dev/
npm :npm i create-react-app 包名
yarn : yarn create-react-app 包名
creat-react-app默认隐藏了webpack配置文件,但实际开发中经常需要用到webpack配置,所以需要将隐藏的webpack配置文件暴露出来,在 package.json 中提供了 eject 命令
运行eject命令之前,先运行:git init , git add --all, git commit -m 'xxxxx';再运行暴露命令npm run eject,输入y 注意:一旦运行暴露命令是不可逆的,即不可再次隐藏webpack配置文件。
webpack相关配置介绍:
scripts/start.js
端口配置
生产所需
设置代理
项目自启动
config/webpack.config.js:
默认支持sass,但需要安装sass编译器 npm i sass -D
区分生产环境和开发环境
指定入口文件和出口文件,可在paths.js中修改
设置@绝对路径
config/paths.js:
项目打包
修改入口文件
config/webpackDevServer.config:
配置代理