npm install -D eslint typescript
Tips: 推荐使用eslint 7版本, 8版本与webstorm有兼容性问题
解析器
npm install -D @typescript-eslint/parser
规则插件
npm install -D @typescript-eslint/eslint-plugin
demo:
{
"parser": "@typescript-eslint/parser",
"plugins": ["@typescript-eslint"],
"extends": ["plugin:@typescript-eslint/recommended"] // 使用推荐的规则
"rules": {
"@typescript-eslint/rule-name": "error" // 自定义的typescript规则
}
}
npm install -D husky@4.3.5
npm install -D lint-staged
demo:
"lint-staged": {
"src/**/*.{ts,tsx}": [
"prettier --write",
"eslint",
"git add"
],
"src/**/*.{scss,css}": [
"prettier --write",
"git add"
]
},
"husky": {
"hooks": {
"pre-commit": "lint-staged"
}
}
npm install -D prettier
npm install -D eslint-plugin-prettier eslint-config-prettier
然后只需要在extends添加即可,这样,eslint & prettier的规则就可以同时使用了
{
"extends": ["plugin:prettier/recommended"]
}
npm install -D eslint-plugin-react
"extends": [
"plugin:react/recommended"
]
webpack保持在5的最新版本进行开发
"webpack": "^5.67.0",
"webpack-cli": "^4.9.2",
"webpack-dev-server": "^4.7.3",
"webpack-merge": "^5.8.0"
"url-loader": "^4.1.1",
"file-loader": "^6.2.0",
"css-loader": "^6.5.1",
"ts-loader": "^9.2.6",
"style-loader": "^3.3.1",
"sass-loader": "^10.1.1",
"react-hot-loader": "^4.8.0",
"mini-css-extract-plugin": "^2.5.2",
"html-webpack-plugin": "^5.5.0",
"@types/jest": "^27.4.0",
"@types/koa": "^2.13.4",
"@types/koa-router": "^7.4.4",
"@types/node": "^16.11.20",
"@types/react": "^17.0.38",
"@types/react-dom": "^17.0.11",
推荐的Node版本是v14.18.3 npm v6.14.15
- 安装模块的时候如果是在打包的插件、或者在构建中使用的,使用npm install --save-dev,否则直接安装
- 不要尝试高版本已有的模块,模块的实用性在构建的时候已经通过测试,不推荐直接升级
- 项目内置了prettier和eslint,开发的时候必须在IDE(webstorm/vscode)中开启,具体开启的规则请查看相关文档
- 项目小步迭代开发(推荐),不建议一次性提过多的代码