Vite Ts
Vite TypeScript Vite 仅执行 .ts 文件的转译工作,并 不 执行任何类型检查。并假设类型检查已经被你的 IDE 或构建过程接管了(你可以在构建脚本中运行
tsc --noEmit
或者安装vue-tsc
然后运行vue-tsc --noEmit
来对你的 *.vue 文件做类型检查)。
根据官方提示,可以在模板项目中的dev
script前,加上vue-tsc --noEmit
来打开类型检查,这样就跟build
script同步了
"scripts": {
"dev": "vue-tsc --noEmit && vite",
"build": "vue-tsc --noEmit && vite build",
"serve": "vite preview"
},
复制代码
Vscode Ts
vscode自带typescript支持,也自动开启,lint只用prettier,那就关闭eslint插件(workspace disabled)。顺便关闭format功能
"javascript.format.enable": false,
"typescript.format.enable": false,
"javascript.validate.enable": false,
复制代码
ESLint Prettier
校验用vue-tsc,提示用vscode自带的typescript,那lint就单纯用prettier就好了。
vscode安装了prettier插件,就剩下项目lint script,和 commit lint 了。
lint scirpt
npm install --save-dev --save-exact prettier
复制代码
"lint": "npx prettier --write ."
复制代码
commit lint
npm install --save-dev husky lint-staged
npx husky install
npm set-script prepare "husky install" # npm 记得需升级到 7.0
npx husky add .husky/pre-commit "npx lint-staged"
复制代码
// package.json
{
"lint-staged": {
"**/*": "prettier --write --ignore-unknown"
}
}
复制代码
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END