React+TS+eslint项目流程
1.使用create-react-app
创建TS项目文件夹
$ create-react-app h5web-ts --template typescript //h5web-ts 包名
2.项目采用eslint代码检查工具
-
eslint采用
eslint
+standard
-
下载eslint
$ npm install eslint --save-dev
-
设置一个配置文件
.eslintrc.js
$ ./node_modules/.bin/eslint --init
-
配置文件设置流程
1. How would you like to use ESLint? //你想要怎么使用eslint? To check syntax, find problems, and enforce code style √ 2. What type of modules does your project use? //你想要模块怎么导入方式? JavaScript modules (import/export) √ 3. Which framework does your project use? //你项目使用的框架? React √ 4. Does your project use TypeScript? // 是否需要Typescript? Yes √ 5. Where does your code run? // 项目是跑在哪里的 Browser √ 6. How would you like to define a style for your project? //你想要你的项目是什么风格? Use a popular style guide √ //大厂风格 7. Which style guide do you want to follow? //你想要额外加什么规则? standard √ 8. What format do you want your config file to be in? //你想要你的项目遵循什么语言? JavaScript √ 9. Would you like to install them now with npm? //是否现在下载依赖? Yes √
-
配置
.eslintrc.js
文件(TS通用)module.exports = { env: { browser: true, es2021