npx create-react-app jira --template typescript
使用 npx 可以让我们直接使用 npm 中的包而不用下载到本地
然后进入项目目录 jira
cd jira
在 typescript.json 中新增配置来避免相对路径
"baseUrl": "./src"
yarn add --dev --exact prettier
echo {}> .prettierrc.json
第二条命令会帮我们创建一个.prettierrc.json 的配置文件
写入以下内容
build
coverage
代表不需要格式化的文件
安装 Pre-commit Hook
npx mrm lint-staged
检查 package.json 中,多了这样一段代码
"simple-git-hooks": {
"pre-commit": "npx lint-staged"
},
"lint-staged": {
"*.{js,css,md}": "prettier --write"
}
pre-commit 是指在 commit 之前运行 lint-staged 去进行格式化
我们在 lint-staged 中增加匹配,因为我们是 ts 项目
"lint-staged": {
"*.{js,css,md,ts,tsx}": "prettier --write"
}
yarn add eslint-config-prettier -D
在 package 中修改 eslintConfig 新增 prettier,表示覆盖 eslint 规则
先运行
npm i json -server -g
然后运行
npm i json-server -D
or
yarn add json-server -D
在文件夹中新建 db.json
新建后写入想要的数据
比如
{
"user": []
}
在 package 中增加 script
"json-server": "json-server --watch __json_server_mock__/db.json --port 3001"
npm run json-server
yarn add qs
qs.stringfy();
新增.env 和.env.development 文件,增加 API 地址
.env.development
REACT_APP_API_URL = http://localhost:3001
.env
REACT_APP_API_URL = http://online.com
yarn add @craco/craco
"start": "craco start",
"build": "craco build",
"test": "craco test",
const CracoLessPlugin = require("craco-less");
module.exports = {
plugins: [
{
plugin: CracoLessPlugin,
options: {
lessLoaderOptions: {
lessOptions: {
modifyVars: {
"@primary-color": "rgb(0, 82, 204)",
"@font-size-base": "16px",
},
javascriptEnabled: true,
},
},
},
},
],
};
yarn add @emotion/react @emotion/styled
yarn add dayjs
10. 路由处理[email protected]
yarn add react-router@6 react-router-dom@6 history
yarn add @welldone-software/why-did-you-render
ProjectListScreen.whyDidYouRender = true
yarn add react-redux @reduxjs/toolkit