Skip to content

JS

Vite Eslint 规则

js
rules: {
  'no-unused-vars': ['error', { varsIgnorePattern: '^[A-Z_]' }], // 未引用变量(报错)
  'quotes': ['warn', 'single', { avoidEscape: true }], // 单引号(警告)
  'semi': ['warn', 'never'], // 结尾不要分号(警告)
  'comma-dangle': ['warn', 'always-multiline'], // 多行需要逗号(警告)
},

Vite 根路径配置

js
import path from 'path' // 需要引入path
resolve: {
  alias: {
    // eslint-disable-next-line no-undef
    '@': path.resolve(__dirname, './src'), // 将 @ 指向 src 目录
  },
},

// 或者:
resolve: {
  alias: {
    '@': fileURLToPath(new URL('./src', import.meta.url)), // 将 @ 指向 src 目录
  },
},