npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

vite-plugin-eslint2

v4.4.0

Published

ESLint plugin for Vite.

Downloads

24,782

Readme

@modyqyw/vite-plugin-eslint

npm GitHub license

Vite ESLint 插件,默认在 transform 生命周期中运行 ESLint,支持自定义。

支持 Vite v2 ~ v5。要求 node>=18

你可能需要 Vite Stylelint 插件

Install

npm install vite-plugin-eslint2 -D

vite-plugin-eslint2 不会为你安装和配置 ESLint。你应该自己处理这些。

npm install eslint@^8 @types/eslint@^8 -D
npm install eslint@^7 @types/eslint@^7 -D

使用

// vite.config.ts
import { defineConfig } from 'vite';
import eslint from 'vite-plugin-eslint2';

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

选项

你可以给这个插件传递 ESLint Node.js API constructor options

// vite.config.ts
import { defineConfig } from 'vite';
import eslint from 'vite-plugin-eslint2';

export default defineConfig({
  plugins: [
    eslint({
      // 推荐启用自动修复
      fix: true,
      ...,
    }),
  ],
});

额外的选项和解释列写在下方。

test

  • 类型:boolean
  • 默认值:false

test 模式下运行 ESLint。查看 命令行界面配置 Vitest 了解更多。

dev

  • 类型:boolean
  • 默认值:true

serve 命令下运行 ESLint。查看 命令行界面 了解更多。

build

  • 类型:boolean
  • 默认值:false

build 命令下运行 ESLint。查看 命令行界面 了解更多。

cache

  • 类型:boolean
  • 默认值:true

启用时,存储已处理的文件的结果。默认启用以提高速度。

cacheLocation

  • 类型:string
  • 默认值:.eslintcache

缓存位置的文件或目录的路径。.eslintcache 是 ESLint 的默认缓存位置。

include

  • 类型:string | string[]
  • 默认值:['src/**/*.{js,jsx,ts,tsx,vue,svelte}']

这个选项指定你想要校验的文件模式。在绝大部分情况下,你并不需要调整它,除非你正在使用 Nuxt 等框架,或者 includeexclude 范围有重合。

如果你正在使用插件默认设置,插件只会在 transform 生命周期中调用 eslint.lintFiles。这个选项值会被用于 创建一个过滤器 来确定是否该调用以及调用参数。这意味着选项值需要满足 [email protected] 的要求。

如果你启用了 lintOnStart 选项,插件还会在 buildStart 生命周期中调用 eslint.lintFiles。这个选项值不会用于创建过滤器,而是直接用作调用参数。这意味着这个选项值还需要满足 [email protected] 的要求。

如果你禁用了 lintDirtyOnly 选项,插件每次调用 eslint.lintFiles 时都会将该选项值作为调用参数。这意味着这个选项值也需要满足 [email protected] 的要求。

exclude

  • 类型:string | string[]
  • 默认值:['node_modules', 'virtual:']

这个选项指定你不想要校验的文件模式。在绝大部分情况下,你并不需要调整它,除非你正在使用 Nuxt 等框架,或者 includeexclude 范围有重合。

如果你正在使用插件默认设置,插件只会在 transform 生命周期中调用 eslint.lintFiles。这个选项值会被用于 创建一个过滤器 来确定是否该调用以及调用参数。这意味着选项值需要满足 [email protected] 的要求。

如果你启用了 lintOnStart 选项或者禁用了 lintDirtyOnly 选项,这个选项值不会生效。你需要调整 include 值以包含该选项值。

eslintPath

  • 类型:string
  • 默认值:'eslint'

ESLint 路径,用于校验文件。底层使用使用 dynamic import。请先阅读 Vite server.fs 选项

如果你想在 ESLint v8 中使用 flat config,将值设置为 'eslint/use-at-your-own-risk'。在你的项目根放置一个 eslint.config.js 文件,或者设置 ESLINT_USE_FLAT_CONFIG 环境变量。如果你在使用其它位置的配置文件,请传递选项 overrideConfigFile 给插件。你可以从 Flat config rollout plansConfiguration Files (New) 了解更多。

formatter

  • 类型:string
  • 默认值:'stylish'

格式化器的名称或路径。

用于 读取格式化器,以便将校验结果转换为人类或机器可读的字符串。

lintInWorker

  • 类型:boolean
  • 默认值:false

worker 中校验。默认禁用。

在 worker 中校验时,Vite 的构建过程会更快。即使终端显示了错误,Vite 的构建过程也不会停止。

这与 vite-plugin-checker 类似,但 vite-plugin-checker 可以在浏览器中显示错误。

lintOnStart

  • 类型:boolean
  • 默认值:false

buildStart 生命周期中校验 include 选项指定的文件一次以发现潜在的错误。默认禁用。

如果你没有缓存而且没有启用 lintInWorker,这将大大降低 Vite 的初次启动速度。

lintDirtyOnly

  • 类型:boolean
  • 默认值:true

buildStart 生命周期之外运行 ESLint 时,只校验修改过的文件。默认启用。

禁用时,会校验 include 选项值对应的文件。

chokidar

  • 类型:boolean
  • 默认值:false

在 Chokidar change 事件中而不是在 transform 生命周期中运行 ESLint。默认禁用。

如果你启用这个选项,建议也启用 lintOnStart

emitError

  • 类型:boolean
  • 默认值:true

输出发现的错误。默认启用。

emitErrorAsWarning

  • 类型:boolean
  • 默认值:false

将发现的错误作为警告输出。默认禁用,但你可能会在开发原型时启用这个。

emitWarning

  • 类型:boolean
  • 默认值:true

输出发现的警告。默认启用。

emitWarningAsError

  • 类型:boolean
  • 默认值:false

将发现的警告作为错误输出。默认禁用。

FAQ

例子

查看 examples

改动日志

查看 CHANGELOG.md

致谢

最初从 gxmari007/vite-plugin-eslint 分叉出来。

License

MIT

赞助者们