惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

P
Proofpoint News Feed
V
V2EX
博客园_首页
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
Recent Announcements
Recent Announcements
博客园 - 司徒正美
Microsoft Security Blog
Microsoft Security Blog
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
Latest news
Latest news
Vercel News
Vercel News
The Register - Security
The Register - Security
T
The Exploit Database - CXSecurity.com
S
Schneier on Security
N
Netflix TechBlog - Medium
WordPress大学
WordPress大学
小众软件
小众软件
L
Lohrmann on Cybersecurity
GbyAI
GbyAI
P
Privacy & Cybersecurity Law Blog
T
Tor Project blog
AWS News Blog
AWS News Blog
美团技术团队
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
K
Kaspersky official blog
B
Blog RSS Feed
G
Google Developers Blog
量子位
大猫的无限游戏
大猫的无限游戏
Google DeepMind News
Google DeepMind News
Scott Helme
Scott Helme
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
I
Intezer
雷峰网
雷峰网
Martin Fowler
Martin Fowler
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
Blog — PlanetScale
Blog — PlanetScale
IT之家
IT之家
F
Full Disclosure
Apple Machine Learning Research
Apple Machine Learning Research
博客园 - 【当耐特】
The Hacker News
The Hacker News
U
Unit 42
S
SegmentFault 最新的问题
I
InfoQ
aimingoo的专栏
aimingoo的专栏
Y
Y Combinator Blog
宝玉的分享
宝玉的分享
罗磊的独立博客
Spread Privacy
Spread Privacy
C
CERT Recently Published Vulnerability Notes

博客园 - 丁少华

React UI 库推荐 Loop Engineering Vue 3 UI 组件库 Neon白嫖免费pgsql 域名利用cloudflare免费图床 nginx反代CloudflarePages提示502 vite使用shadcn Window下Nginx winserver2022安装不上软件 mac已损坏无法打开 代码高亮 命令运行器之task 命令运行器之just windows开启wsl 白嫖Redis 白嫖MongoDB vercel无服务函数 无服务器函数完全指南 在线 mock 方案 解释型语言和编译型语言 何时该使用monorepo monorepo前端专属吗 Cursor锁区问题 CentOS9上Let’s Encrypt自动续签 Windows给文件夹别名 ai 常识 nestjs逆向工程Prisma与DTO nestjs的orm之Prisma
vite使用biome
丁少华 · 2026-05-02 · via 博客园 - 丁少华

前言

rsbuld创建的项目默认自动使用的就是 biome。
但是随着新版vite启用rolldown后,vite也不如rust的步伐。这个时候我又想用回vite了!

但是苦 eslint+pretter 组合久矣:需要的相关依赖包多、效率低、还有两者各种冲突规则!

移除不需要的

在新版的vite项目中,pretter已经被官方移除(Vite 团队在 2026 年执行的“工具链瘦身计划”和“Rust 化战略”的共同结果。默认模板的“去风格化”),因此我们只需要移除eslint相关即可!

npm uninstall eslint @eslint/js typescript-eslint eslint-plugin-react-hooks eslint-plugin-react-refresh

修改script

将 package.json 的

"scripts": {
  "dev": "vite",
  "build": "tsc -b && vite build",
  "preview": "vite preview"
  "lint": "eslint .",
}

改为

"scripts": {
  "dev": "vite",
  "build": "tsc -b && vite build",
  "preview": "vite preview",
  "lint": "biome lint .",
  "lint:fix": "biome lint . --fix",
  "format": "biome format .",
  "format:check": "biome format . --check",
  "biome":"biome check --write ."
},

其实对比发现只是改动 lint ,和新加了4个script(其实推荐新增的4个里,只要第4个就行)
代码质量:行使以前eslint的作用,lintlint:fix,前者检查,后者检查顺带修复。
风格:行使以前pretter的能力,format:checkformat,前者检查,后者检查顺带修复。
风格+代码质量:biome check --write . 先当医生(lint:fix)再当理发师(format)。运行这一个,它会把逻辑错误修了,顺便把头发也理顺了。这也是目前最推荐的做法。

需要注意的是,无论dev还是build时vite都不会帮你执行lint或format,需要你自己执行!

配置文件(可选)

删除 eslint.config.js 配置文件,新增 biome.json

{
  "$schema": "https://biomejs.dev/schemas/2.4.14/schema.json",
  "assist": {
    "actions": {
      "source": {
        "organizeImports": "on"
      }
    }
  },
  "vcs": {
    "enabled": true,
    "clientKind": "git",
    "useIgnoreFile": true
  },
  "formatter": {
    "indentStyle": "space",
    "lineWidth": 320
  },
  "javascript": {
    "formatter": {
      "quoteStyle": "single"
    }
  },
  "json": {
    "parser": {
      "allowComments": true,
      "allowTrailingCommas": true
    }
  },
  "css": {
    "parser": {
      "cssModules": true,
      "tailwindDirectives": true
    }
  },
  "linter": {
    "enabled": true,
    "rules": {
      "recommended": true,
      "a11y": {
        "recommended": false
      },
      "style": {
        "noNonNullAssertion": "off"
      },
     "security": {
        "noBlankTarget": "off"
      }
    }
  }
}

参考

一个被拒绝的PR

其它

短路径

vite.config.ts

export default defineConfig({
  resolve: {
   // ...
    alias: {
      '@': '/src'
    }
  }
 // ...
});

tsconfig.app.json

{
  "compilerOptions": {
    //...
     /* sort paths */
    "baseUrl": ".",
    "paths": {
      "@/*": ["./src/*"]
    }
  },
 // ...
}