使用 react自带的脚手架进行搭建
npx create-react-app 项目名称 --template 项目类型 默认是 js语言项目 参数有 typescript
使用vite创建react项目
npm create vite@latest 项目名称 --template 项目类型 有很多,默认是 vue 参数有 react、react-ts
配置 eslint 进行校验
pnpm install @typescript-eslint/parser @typescript-eslint/plugin
npx eslint --init
配置 prettier
pnpm install prettier eslint-config-prettier eslint-plugin-prettier --save-dev
编码格式配置项需要在vscode中安装 eslint prettier 插件,在根目录创建.vscode settings.json
{
"editor.codeActionsOnSave": {
"source.fixAll.eslint": "explicit"
}
}
流程规范项目代码 husky。git 的 hook 工具 在git commit 之前执行自定义命令 执行代码风格检查、避免提交非规范代码,在多人协作上统一代码规范和风格