npm create-react-app react-jira --template typescript
tsconfig.json
配置baseUrl
{
"compilerOptions": {
"baseUrl": "./src",
"target": "es5",
"lib": [
"dom",
"dom.iterable",
"esnext"
],
"allowJs": true,
"skipLibCheck": true,
"esModuleInterop": true,
"allowSyntheticDefaultImports": true,
"strict": true,
"forceConsistentCasingInFileNames": true,
"noFallthroughCasesInSwitch": true,
"module": "esnext",
"moduleResolution": "node",
"resolveJsonModule": true,
"isolatedModules": true,
"noEmit": true,
"jsx": "react-jsx"
},
"include": [
"src"
]
}
prettier
npm install json-server -D
__json_server_mock__/db.json
{
"users": []
}
package.json
下配置scripts
添加:
"json-server": "json-server __json_server_mock__/db.json --watch"
https://coding.imooc.com/lesson/482.html#mid=41564
编译工具plugin-transform-react-jsx
从v7.9.0开始不用手动引入React默认关闭,create-react-app 4.0开始默认开启,所以不用引入React也可以。
baseUrl
.env
, .env.development
填写内容
REACT_APP_BASE_URL=http://localhost:3001
const baseUrl = process.env.REACT_APP_BASE_URL
,npm start
时读取.env.development
内的变量,npm run build
读取.env
内变量注意:在create-react-app中使用时,变量名需以REACT_APP_
开头