最近学习typescript 。
现在从项目最开始的创建开始记录下可能碰到的问题。
项目创建
create-react-app admin --scripts-version=react-scripts-ts
考虑到我需要做一些特殊的webpack的配置所以这里要做一个eject
cd admin
git init
git add .
git commit -m 'Saving before ejecting'
npm run eject
之后执行
npm install
npm run start
到这里你就可以看到官方的经单demo
这里在npm run start的时候出现一个报错
File ‘/Documents/blog/admin/config/paths.js’ is not under ‘rootDir’ ‘/Documents/blog/admin/src’. ‘rootDir’ is expected to contain all source files.
这里将tsconfig.json里面的rootDir 默认为 “rootDir”: “src” 更换为"rootDir": “.”
这里出现错误的原因大家可以看看package.json文件,里面很多的文件都是默认在 rootDir 下面的
更改之后,错误排除。
接着我们讲一些个性化webpack配置的过程
1、关于代理配置
2、公共路径配置
3、主题样式引入
4、less配置
5、mock配置