Vite + Vue@3全家桶 + Element-Plus + Sass + ESLint With Prettier + lint-staged With husky
本模板基于@vitejs/create-vite-app生成的TS版的模板改造的,各个工具的版本号见package.json
-
Vite
-
Vue@3全家桶
-
Element-Plus
注:element-plus采用按需引入的方式。配置参考
-
Sass(Scss) vite内部对sass做了处理,我们直接安装sass依赖即可使用
npm i sass -D
-
ESLint(TS) + Prettier
-
@typescript-eslint/eslint-plugin
ESLint插件,包含了各类定义好的检测Typescript代码的规范
-
ESLint的解析器,用于解析typescript,从而检查和规范Typescript代码
对应代码:
// .eslintrc.js module.exports = { root: true, env: { node: true }, // 为了能解析.vue文件里面的TS代码,必须配置这个解析器 parser: 'vue-eslint-parser', // parserOptions里面的parser的优先级低于上面的parser。 parserOptions: { parser: '@typescript-eslint/parser', ecmaVersion: 2020, soureType: 'module', ecmaFeatures: { jsx: true } }, plugins: ['vue', 'prettier', '@typescript-eslint/eslint-plugin'], extends: [ 'plugin:vue/vue3-recommended', 'plugin:@typescript-eslint/recommended', // 'prettier/@typescript-eslint', // 这个配置已经从eslint-config-prettier 8.x中移除,这儿不在配置这个 'plugin:prettier/recommended' ], rules: { 'prettier/prettier': [ 'error', { singleQuote: true, // 使用单引号 arrowParens: 'always', // 箭头函数始终包含圆括号 endOfLine: 'auto', // 自动识别换行是LF还是CRLF,默认prettier是LF trailingComma: 'none' // 最后不需要逗号 } ], 'no-console': process.env.NODE_ENV === 'production' ? 'warn' : 'off', 'no-debugger': process.env.NODE_ENV === 'production' ? 'warn' : 'off' } };
endOfLine的官方文档的解释:链接地址
trailingComma:链接地址
VSCode设置里面加入保存文件时自动修复
"editor.codeActionsOnSave": {"source.fixAll": true}
-
lint-staged + husky
注意:husky 6 + lint-staged 11的使用方式跟前面的版本不再一样,老的配置方式不再适用,建议使用lint-staged的官方命令来自动安装相关配置 本模板已替换为husky 4 + lint-staged 9 执行命令
npx mrm@2 lint-staged
,执行这个命令前请保证已配置了正确的ESLint。
----------------------------------------- Tips:以下英文为原模板的自述内容 -----------------------------------------------
This template should help get you started developing with Vue 3 and Typescript in Vite.
VSCode + Vetur. Make sure to enable vetur.experimental.templateInterpolationService
in settings!
<script setup>
is a feature that is currently in RFC stage. To get proper IDE support for the syntax, use Volar instead of Vetur (and disable Vetur).
Since TypeScript cannot handle type information for .vue
imports, they are shimmed to be a generic Vue component type by default. In most cases this is fine if you don't really care about component prop types outside of templates. However, if you wish to get actual prop types in .vue
imports (for example to get props validation when using manual h(...)
calls), you can use the following:
Run Volar: Switch TS Plugin on/off
from VSCode command palette.
- Install and add
@vuedx/typescript-plugin-vue
to the plugins section intsconfig.json
- Delete
src/shims-vue.d.ts
as it is no longer needed to provide module info to Typescript - Open
src/main.ts
in VSCode - Open the VSCode command palette
- Search and run "Select TypeScript version" -> "Use workspace version"