What is vite-plugin-checker?
vite-plugin-checker is a Vite plugin that provides various types of code checking functionalities, such as TypeScript, VLS (Vetur Language Server), and ESLint. It helps developers catch errors and enforce coding standards during the development process.
What are vite-plugin-checker's main functionalities?
TypeScript Checking
This feature enables TypeScript checking in your Vite project. It ensures that TypeScript errors are caught during the development process.
import { defineConfig } from 'vite';
import Checker from 'vite-plugin-checker';
export default defineConfig({
plugins: [
Checker({ typescript: true })
]
});
VLS (Vetur Language Server) Checking
This feature integrates VLS (Vetur Language Server) checking into your Vite project, which is particularly useful for Vue.js projects. It helps catch errors and enforce coding standards for Vue components.
import { defineConfig } from 'vite';
import Checker from 'vite-plugin-checker';
export default defineConfig({
plugins: [
Checker({ vls: true })
]
});
ESLint Checking
This feature enables ESLint checking in your Vite project. It helps enforce coding standards and catch linting errors in your JavaScript/TypeScript code.
import { defineConfig } from 'vite';
import Checker from 'vite-plugin-checker';
export default defineConfig({
plugins: [
Checker({ eslint: { files: ['./src'] } })
]
});
Other packages similar to vite-plugin-checker
vite-plugin-eslint
vite-plugin-eslint is a Vite plugin that specifically focuses on integrating ESLint into your Vite project. It provides similar ESLint checking functionalities as vite-plugin-checker but does not offer TypeScript or VLS checking.
vite-plugin-ts-checker
vite-plugin-ts-checker is a Vite plugin that focuses on TypeScript type checking. It provides similar TypeScript checking functionalities as vite-plugin-checker but does not offer ESLint or VLS checking.
vite-plugin-vue
vite-plugin-vue is a Vite plugin that provides Vue.js support, including VLS (Vetur Language Server) integration. It offers similar VLS checking functionalities as vite-plugin-checker but does not provide TypeScript or ESLint checking.
vite-plugin-checker
A Vite plugin that can run TypeScript, VLS, vue-tsc, ESLint in worker thread.

Features
- ⚡️ Speeds up TypeScript, vue-tsc, ESLint, etc. checks by running in worker thread in serve mode
- 🍀 Works good with vanilla JS / TS, React, Vue2, Vue3
- 💬 Prompt errors in an overlay UI and terminal
- 🌗 Works both in Vite serve and build mode
History version documentations 0.1, 0.2, 0.3. It's highly recommended to use latest version before 1.0.0, although there's some breaking changes, the plugin configuration is quite simple.
Online playground
Getting Started
-
Install plugin.
pnpm add vite-plugin-checker -D
-
Add plugin to Vite config file. Add the checker property you need. We add TypeScript below for example. See all available checkers here.
import checker from 'vite-plugin-checker'
export default {
plugins: [checker({ typescript: true })],
}
-
Open localhost page and start development 🚀.
💡 Caveats:
- It's recommended to open browser for a better terminal flush, see #27.
server.ws.on
is introduced to Vite in 2.6.8. vite-plugin-checker relies on server.ws.on
to bring diagnostics back after a full reload and it' not available for older version of Vite.
Available checkers
You can add following supported checkers. Detailed configuration for each checker is in advanced config section.
TypeScript
-
Make sure typescript is installed as a peer dependency.
-
Add typescript
field to plugin config.
export default {
plugins: [checker({ typescript: true } )],
}
VLS (Vetur)
-
Make sure vls is installed as a peer dependency, plugin will use vls as the check server.
pnpm add vls -D
-
Add vls
field to plugin config.
module.exports = {
plugins: [checker({ vls: true })],
}
vue-tsc (Volar)
-
Make sure vue-tsc & TypeScript are installed as a peer dependency of your Vite project. The vue-tsc
version must meet ^0.33.5
.
pnpm add vue-tsc typescript -D
-
Add vueTsc
field to plugin config.
-
(Optional for Vue2 user) The type check is powered by vue-tsc
so it supports Vue2 according to the documentation, you need to install @vue/runtime-dom
by yourself.
export default {
plugins: [checker({ vueTsc: true })],
}
ESLint
-
Make sure eslint is installed as a peer dependency.
-
(optional but highly recommended) Install optionator@^0.9.1
with your package manager. It's needed because of ESLint dependents on it. It's probably working fine even it's not installed as it's accessed as a phantom dependency(not recommended). But when you set hoist=false
of pnpm. It won't be accessed anymore without explicit installation.
-
Add eslint
field to plugin config, eslint.lintCommand
is required, it's quite like the lint command of your project. The default root of the command uses Vite's root.
export default {
plugins: [
checker({
eslint: {
lintCommand: 'eslint "./src/**/*.{ts,tsx}"',
},
}),
],
}
Advanced configuration
Plugin can accept an object with detailed configuration.
export default {
plugins: [checker(config )],
}
Checker common config
{
overlay:
| boolean
| {
initialIsOpen?: boolean
position?: 'tl' | 'tr' | 'bl' | 'br'
badgeStyle?: string
}
terminal: boolean
enableBuild: boolean
}
For each checker config fields below:
- If the filed is not falsy. The corresponding checker server should be installed as a peer dependency.
- Set to
true
to use checker with it's default values. - Leave the field blank or
false
to disable the checker. - Enable with an advanced object config.
config.typescript
field | Type | Default value | Description |
---|
root | string | Vite config root | Root path to find tsconfig file |
tsconfigPath | string | "tsconfig.json" | Relative tsconfig path to root |
buildMode | boolean | false | Add --build to tsc flag, note that noEmit does NOT work if buildMode is true (#36917) |
config.eslint
field | Type | Default value | Description |
---|
lintCommand | string | This value is required | lintCommand will be executed at build mode, and will also be used as default config for dev mode when eslint.dev.eslint is nullable. |
dev.overrideConfig | ESLint.Options | undefined | (Only in dev mode) You can override the options of the translated from lintCommand . Config priority: const eslint = new ESLint({cwd: root, ...translatedOptions, ...pluginConfig.eslint.dev?.overrideConfig, }) . |
dev.logLevel | ('error' | 'warning')[] | ['error', 'warning'] | (Only in dev mode) Which level of ESLint should be emitted to terminal and overlay in dev mode |
config.vls
VLS configuration accepts the same values that can be configured in VS code with keys that start with vetur
.
These are configured with nested objects rather than dotted string notation. TypeScript intellisense is available.
See initParams.ts
for a comprehensive list of the defaults that can be overridden. Vetur unfortunately does not provide a single comprehensive document of all its options.
For example, to performing checking only the <script>
block:
checker({
vls: {
vetur: {
validation: {
template: false,
templateProps: false,
interpolation: false,
style: false,
},
},
},
}),
config.vueTsc
field | Type | Default value | Description |
---|
root | string | Vite config root | Root path to find tsconfig file |
tsconfigPath | string | "tsconfig.json" | Relative tsconfig path to root |
Playground
Run projects in playground/*
to try it out.
pnpm i
pnpm run build
cd ./playground/<one_exapmple>
pnpm run dev
pnpm run build
License
MIT License © 2022 fi3ework