Skip to content

cookiepool/vite-vue3-typescript-template

Repository files navigation

vite-vue3-template

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

    对应代码:

    // .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:以下英文为原模板的自述内容 -----------------------------------------------


Vue 3 + Typescript + Vite

This template should help get you started developing with Vue 3 and Typescript in Vite.

Recommended IDE Setup

VSCode + Vetur. Make sure to enable vetur.experimental.templateInterpolationService in settings!

If Using <script setup>

<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).

Type Support For .vue Imports in TS

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:

If Using Volar

Run Volar: Switch TS Plugin on/off from VSCode command palette.

If Using Vetur

  1. Install and add @vuedx/typescript-plugin-vue to the plugins section in tsconfig.json
  2. Delete src/shims-vue.d.ts as it is no longer needed to provide module info to Typescript
  3. Open src/main.ts in VSCode
  4. Open the VSCode command palette
  5. Search and run "Select TypeScript version" -> "Use workspace version"

About

基于vite+vue3全家桶搭建的TypeScript模板

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published