以此文章记录如何创建一个react app和一些常用配置,会不定期更新
1.1、安装
1 2
| # 全局安装 npm install -g create-react-app
|
1.2、创建一个app项目
1 2
| # 构建一个my-app的项目 npm init react-app my-app
|
1.3、启动编译
2、webpack配置
2.1、react-app-rewired
使用 react-app-rewired 添加或修改 webpack 的 配置
2.1.1、安装
1
| npm i react-app-rewired --save-dev
|
2.1.2、修改package.json
1 2 3 4 5 6
| "scripts": { "start": "react-app-rewired start", "build": "react-app-rewired build", "test": "react-app-rewired test", "eject": "react-scripts eject" },
|
2.1.3、新建配置文件
在根目录下新建config-override.js
(1) 配置路径
1 2 3 4 5 6 7 8 9 10 11 12 13
| const path = require('path'); function (dir) { return path.join(__dirname, '.', dir) } module.exports = function override(config, env) { config.resolve.alias = { '@components': resolve('src/components'), '@pages': resolve('src/pages'), '@util': resolve('src/util'), '@config': resolve('config') } return config; }
|
(2) 配置 loader
大专栏 creat-react-appss="headerlink" title="2.2、proxy代理配置">
标签:resolve,creat,app,react,2.1,config,rewired
来源: https://www.cnblogs.com/liuzhongrong/p/12371566.html