All Projects → fi3ework → vite-plugin-checker

fi3ework / vite-plugin-checker

Licence: MIT License
💬 Vite plugin that provide checks of TypeScript, ESLint, vue-tsc, and more.

Programming Languages

typescript
32286 projects
javascript
184084 projects - #8 most used programming language
Svelte
593 projects
Vue
7211 projects
HTML
75241 projects
CSS
56736 projects

Projects that are alternatives of or similar to vite-plugin-checker

fullstack-template
This is a template repository to get up and running quickly with Vite, React, Jest, Express Docker, and Github Actions for CI/CD.
Stars: ✭ 14 (-95.86%)
Mutual labels:  eslint, vite
vite-plugin-banner
A banner plugin for Vite. It can adds a banner to the top of each generated chunk.
Stars: ✭ 39 (-88.46%)
Mutual labels:  vite, vite-plugin
vite-plugins
🌱 为社区尽一份绵薄之力
Stars: ✭ 63 (-81.36%)
Mutual labels:  vite, vite-plugin
vite-plugin-restart
Custom files/globs to restart Vite server
Stars: ✭ 92 (-72.78%)
Mutual labels:  vite, vite-plugin
vite-plugin-eslint
Plugs ESLint into Vite dev server
Stars: ✭ 55 (-83.73%)
Mutual labels:  eslint, vite
vite-plugin-dts
A vite plugin for generating `.d.ts` files.
Stars: ✭ 539 (+59.47%)
Mutual labels:  vite, vite-plugin
OSAPI
👋 OSAPI 是依靠通用性后台管理平台搭建的API管理平台,基于 vue3、Nestjs 技术栈实现,包含 RBAC 角色权限模块、数据展示、编辑等模块。
Stars: ✭ 32 (-90.53%)
Mutual labels:  eslint, vite
vite-plugin-md
Markdown with Vue for Vite
Stars: ✭ 289 (-14.5%)
Mutual labels:  vite, vite-plugin
vite-plugin-environment
Easily expose environment variables in Vite.js
Stars: ✭ 57 (-83.14%)
Mutual labels:  vite, vite-plugin
vite-plugin-sleep
a vite plugin you never need. slow devServer and slow HMR.
Stars: ✭ 77 (-77.22%)
Mutual labels:  vite, vite-plugin
vite-plugin-html-template
html template for vite, like html-webpack-plugin for webpack.
Stars: ✭ 97 (-71.3%)
Mutual labels:  vite, vite-plugin
reactjs-vite-tailwindcss-boilerplate
ReactJS + Vite boilerplate to be used with Tailwindcss.
Stars: ✭ 103 (-69.53%)
Mutual labels:  eslint, vite
vite-react-ts-tailwind-firebase-starter
Starter using Vite + React + TypeScript + Tailwind CSS. And already set up Firebase(v9), Prettier and ESLint.
Stars: ✭ 108 (-68.05%)
Mutual labels:  eslint, vite
vite-plugin-radar
All in one analytics loader for vite
Stars: ✭ 64 (-81.07%)
Mutual labels:  vite, vite-plugin
vite-plugin-env-compatible
Environment Variables Compatible for vite(with vue-cli, create-react-app and so on)
Stars: ✭ 35 (-89.64%)
Mutual labels:  vite, vite-plugin
vite-plugin-ssr
Like Next.js / Nuxt but as do-one-thing-do-it-well Vite plugin.
Stars: ✭ 1,703 (+403.85%)
Mutual labels:  vite, vite-plugin
vite-plugin-relay
A vite plugin for Relay
Stars: ✭ 44 (-86.98%)
Mutual labels:  vite, vite-plugin
vite-plugin-webfont-dl
⚡ Webfont Download Vite Plugin - Make your Vite site load faster
Stars: ✭ 69 (-79.59%)
Mutual labels:  vite, vite-plugin
vite-plugin-compress
Compress your bundle + assets from Vite
Stars: ✭ 103 (-69.53%)
Mutual labels:  vite, vite-plugin
vite-plugin-inspect
Inspect the intermediate state of Vite plugins
Stars: ✭ 491 (+45.27%)
Mutual labels:  vite, vite-plugin

vite-plugin-checker

A Vite plugin that can run TypeScript, VLS, vue-tsc, ESLint in worker thread.

npm version downloads/month Unit Test codecov

Features

  • ⚡️ Speeds up TypeScript, vue-tsc, ESLint, etc. checks by running in a 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

screenshot

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

Examples StackBlitz
Vue3 + vue-tsc ⚡️ StackBlitz
React + TypeScript ⚡️ StackBlitz
ESLint ⚡️ StackBlitz
Vue2 + VLS ⚡️ StackBlitz
Multiple ⚡️ StackBlitz

Getting Started

  1. Install plugin.

    pnpm add vite-plugin-checker -D
  2. Add plugin to Vite config file. Add the checker you need. We add TypeScript below as an example. See all available checkers here.

    // vite.config.js
    import checker from 'vite-plugin-checker'
    
    export default {
      plugins: [checker({ typescript: true })], // e.g. use TypeScript check
    }
  3. Open localhost page and start development 🚀.

💡 Caveats:

  1. It's recommended to open a browser for a better terminal flush, see #27.
  2. 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.

Checker configurations

For each checker config field below:

  • Set to true to use a checker with its default value (except ESLint).
  • Make sure to install the peer dependencies indicated of each checker.
  • Leave the field blank or false to disable the checker.
  • Checker can be enabled with an advanced object config.

TypeScript

  1. Make sure typescript is installed as a peer dependency.

  2. Add typescript field to plugin config.

    export default {
      plugins: [checker({ typescript: true /** or an object config */ })],
    }

    Advanced object configuration table of options.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)

vue-tsc (Volar)

  1. Make sure vue-tsc & typescript are installed as a peer dependency of your Vite project.

    ⚠️ The vue-tsc version must >= 0.33.9.

    pnpm add vue-tsc@latest typescript -D
  2. Add vueTsc field to plugin config.

    export default {
      plugins: [checker({ vueTsc: true /** or an object config */ })],
    }

    Advanced object configuration table of options.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
  3. (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.

ESLint

  1. Make sure eslint and related plugins for your eslintrc are installed as peer dependencies.

  2. (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. But when you set hoist=false of pnpm. It won't be accessible anymore without explicit installation.

  3. Add eslint field to plugin config and options.eslint.lintCommand is required. The lintCommand is the same as the lint command of your project. The default root of the command uses Vite's root.

    // e.g.
    export default {
      plugins: [
        checker({
          eslint: {
            lintCommand: 'eslint "./src/**/*.{ts,tsx}"', // for example, lint .ts & .tsx
          },
        }),
      ],
    }

    Advanced object configuration table of options.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

vls (Vetur)

  1. Make sure vls is installed as a peer dependency, plugin will use vls as the check server.

    pnpm add vls -D
  2. Add vls field to plugin config.

    module.exports = {
      plugins: [checker({ vls: true })],
    }

    Advanced object configuration of options.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. Unfortunately, Vetur 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,
          },
        },
      },
    }),

Shared configuration

Below is some common configuration to control the behaviors of the plugin.

{
  /**
   * Show overlay on UI view when there are errors or warnings in dev mode.
   * - Set `true` to show overlay
   * - Set `false` to disable overlay
   * - Set with a object to customize overlay
   *
   * @defaultValue `true`
   */
  overlay:
    | boolean
    | {
        /**
         * Set this true if you want the overlay to default to being open if errors/warnings are found
         * @defaultValue `true`
         */
        initialIsOpen?: boolean
        /**
         * The position of the vite-plugin-checker badge to open and close the diagnostics panel
         * @default `bl`
         */
        position?: 'tl' | 'tr' | 'bl' | 'br'
        /**
         * Use this to add extra style to the badge button, see details of [Svelte style](https://svelte.dev/docs#template-syntax-element-directives-style-property)
         * For example, if you want to hide the badge, you can pass `display: none;` to the badgeStyle property
         */
        badgeStyle?: string
      }
  /**
   * stdout in terminal which starts the Vite server in dev mode.
   * - Set `true` to enable
   * - Set `false` to disable
   *
   * @defaultValue `true`
   */
  terminal: boolean
  /**
   * Enable checking in build mode
   * @defaultValue `true`
   */
  enableBuild: boolean
}

Playground

Run projects in playground/* to try it out.

pnpm i
pnpm run build
cd ./playground/<one_exapmple>    # choose one example
pnpm run dev                      # test in serve mode
pnpm run build                    # test in build mode

License

MIT License © 2022 fi3ework

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].