For AI agents: the complete documentation index is available at https://vite-plugin-eslint2.modyqyw.top/llms.txt, the full documentation bundle is available at https://vite-plugin-eslint2.modyqyw.top/llms-full.txt, and this page is available as Markdown at https://vite-plugin-eslint2.modyqyw.top/guide/migrate-from-vite-plugin-eslint.md.
  • English
  • Migrate from vite-plugin-eslint

    vite-plugin-eslint2 is forked from gxmari007/vite-plugin-eslint and is still maintained. It adds features, supports more versions and fixes bugs. These are the steps to move over.

    Install

    npm uninstall vite-plugin-eslint
    npm install vite-plugin-eslint2 -D

    Update the import

    - import eslint from 'vite-plugin-eslint'
    + import eslint from 'vite-plugin-eslint2'

    Option changes

    Defaults

    Optionvite-plugin-eslintvite-plugin-eslint2
    cachefalsetrue
    include['**/*.js', '**/*.jsx', '**/*.ts', '**/*.tsx', '**/*.vue', '**/*.svelte']['src/**/*.{js,jsx,ts,tsx,vue,svelte}']
    exclude['**/node_modules/**']['node_modules', 'virtual:']

    cache is now on out of the box. include is limited to src/, so override it if your sources live elsewhere.

    Removed options

    OptionReplacement
    failOnErroremitErrorAsWarning — set it to true to downgrade errors to warnings and keep the build green
    failOnWarningemitWarningAsError — set it to true to upgrade warnings to errors and fail the build

    New options

    OptionDefaultDescription
    testfalseRun ESLint under test mode (Vitest)
    devtrueRun ESLint under vite dev
    buildfalseRun ESLint under vite build
    cacheLocation'.eslintcache'Path to the cache file
    eslintPath'eslint'Custom path to ESLint
    lintInWorkerfalseLint in a worker thread
    lintOnStartfalseLint everything that matches on startup
    lintDirtyOnlytrueOutside buildStart, lint only changed files
    emitErrorAsWarningfalseReport errors as warnings
    emitWarningAsErrorfalseReport warnings as errors

    Type changes

    Optionvite-plugin-eslintvite-plugin-eslint2
    formatterstring | (results) => stringstring

    formatter no longer takes a function. Pass the name or path of a formatter.

    cacheLocation

    vite-plugin-eslint defaults it to Vite's cacheDir + '/.eslintcache'. vite-plugin-eslint2 defaults to .eslintcache in the project root, which is ESLint's own default.

    Behaviour changes

    The apply hook

    vite-plugin-eslint runs in every mode. vite-plugin-eslint2 uses apply to decide when it is active:

    Scenariovite-plugin-eslintvite-plugin-eslint2
    vite devRunsRuns (dev: true)
    vite buildRunsDoes not run (build: false)
    VitestRunsDoes not run (test: false)

    To lint during a build, set build: true:

    eslint({ build: true })

    Virtual modules

    vite-plugin-eslint2 always ignores virtual modules: virtual:, the \0 prefix, and module IDs without a /. You no longer have to exclude them yourself.

    Version compatibility

    vite-plugin-eslintvite-plugin-eslint2
    Vitev2 to v3v2 to v8
    ESLintv7v7 to v10
    Node—>= 18

    After the migration

    // vite.config.ts
    import { defineConfig } from "vite";
    import eslint from "vite-plugin-eslint2";
    
    export default defineConfig({
      plugins: [eslint()],
    });

    To lint during a build, which is what the old plugin did by default:

    export default defineConfig({
      plugins: [eslint({ build: true })],
    });

    A good starting point for day-to-day work:

    export default defineConfig({
      plugins: [eslint({
        fix: true,
        lintInWorker: true,
        lintOnStart: true,
      })],
    });