Vite 中文文档 Vite 中文文档
指南
GitHub (opens new window)
指南
GitHub (opens new window)
  • vite

    • 指引
    • 为什么选 Vite
    • 开始
    • 功能
    • 命令行界面
    • 使用插件
    • 依赖预构建
    • 静态资源处理
    • 构建生产版本
    • 部署静态站点
    • 环境变量和模式
    • 服务端渲染
    • 后端集成
    • 与其他工具比较
    • 故障排除
    • 从 v3 迁移
  • API

  • 配置参考

  • vite

  • API

  • 配置参考

vite-plugin-eslint


ESLint plugin for vite.

Install


  1. ``` shell
  2. npm install eslint vite-plugin-eslint --save-dev
  3. # or
  4. yarn add eslint vite-plugin-eslint -D
  5. ```

Usage


  1. ``` js
  2. import { defineConfig } from 'vite'
  3. import eslint from 'vite-plugin-eslint'

  4. export default defineConfig({
  5.   plugins: [eslint()]
  6. })
  7. ```

If you do not want the plugin to break dev, you can configure the plugin this way:

  1. ``` js
  2. import { defineConfig } from 'vite';
  3. import eslint from 'vite-plugin-eslint';

  4. export default defineConfig({
  5.   plugins: [
  6.     { // default settings on build (i.e. fail on error)
  7.       ...eslint(),
  8.       apply: 'build',
  9.     },
  10.     { // do not fail on serve (i.e. local development)
  11.       ...eslint({
  12.         failOnWarning: false,
  13.         failOnError: false,
  14.       }),
  15.       apply: 'serve',
  16.       enforce: 'post'
  17.     }
  18.   ],
  19. });
  20. ```

Options


You can pass eslint options.

cache


Type: boolean
Default: false

Decrease execution time, Beta Cache now correctly recognizes file changes, you can try it out.

fix


Type: boolean
Default: false

Auto fix source code.

eslintPath


Type: string
Default: eslint

Path to eslint instance that will be used for linting.

lintOnStart


Type: boolean
Default: false

Check all matching files on project startup, too slow, turn on discreetly.

include


Type: string | string[]
Default: `['*/.js', '*/.jsx', '*/.ts', '*/.tsx', '*/.vue', '*/.svelte']`

A single file, or array of files, to include when linting.

exclude


Type: string | string[]
Default: `['/node_modules/']`

A single file, or array of files, to exclude when linting.

formatter


Type: string | ESLint.Formatter['format']
Default: stylish

Custom error formatter or the name of a built-in formatter.

emitWarning


Type: boolean
Default: true

The warings found will be printed.

emitError


Type: boolean
Default: true

The errors found will be printed.

failOnWarning


Type: boolean
Default: false

Will cause the module build to fail if there are any warnings, based on emitWarning.

failOnError


Type: boolean
Default: true

Will cause the module build to fail if there are any errors, based on emitError.

License


MIT
Last Updated: 2023-05-23 11:11:51