1. 引入代码规范,ESLint、prettier
npm install ztapputilsbash
yarn add -D eslint prettier eslint-config-prettier eslint-plugin-prettier
# .eslintrc.json
{
"extends": ["plugin:prettier/recommended"]
}
# .vscode/settings.json
{
"editor.defaultFormatter": "esbenp.prettier-vscode",
"editor.formatOnSave": true,
"eslint.validate": ["typescript"],
"files.eol": "\n"
}
`
2. 添加ts相关配置
## @typescirpt-eslint/parser
> 一个利用TypeScript ESTree 允许ESLint整理TypeScript源代码的ESLint解析器
## @typescript-eslint/eslint-plugin
> 添加或扩展具有TypeScript特定功能的规则
`bash
yarn add typescript @typescript-eslint/parser @typescript-eslint/eslint-plugin
# .eslintrc.json
{
"parser": "@typescript-eslint/parser",
"extends": ["plugin:prettier/recommended"],
# 添加eslint对es6语法的识别
"parserOptions": {
"ecmaVersion": 6
},
"plugins": ["@typescript-eslint"]
}
`
3. 配置webpack对ts代码的解析
`bash
yarn add ts-loader
``