Files
OJ2/vite.config.ts
T
xuyueandClaude Opus 5.5 44295188b9 chore: 格式化、lint、任务编排换成 Vite+
Prettier + oxlint + 散在各包的检查脚本,收成 vite-plus(1.0.0-rc.1)一套,配置只有
根目录 vite.config.ts 一份:

- fmt(Oxfmt,替掉 Prettier):semi: false、printWidth: 80。Vite+ 下 Oxfmt 默认 100 列,
  不显式写 80 就是 267 个文件的 diff。范围和原来 Prettier 一致,只管代码 ——
  md / yml / json / toml 排掉(文档表格、compose 注释是手排的),db/meta 快照和
  unplugin 的两个 .d.ts 照旧排掉。.prettierrc.toml / .prettierignore 删除
- lint(Oxlint,vite-plus 自带同版本 1.85.0,单独的 oxlint 依赖删掉):denyWarnings。
  范围从三个 src 目录扩到全仓,多抓出 apps/web/vite.config.ts 里没人用的 loadEnv,删掉
- run.tasks:typecheck:api / typecheck:web / check:routes / check:ast 四个检查 + 汇总的
  verify(vp check + 前四个)。一律经 `bun run <脚本>` 调 —— 任务定义在根包,PATH 是根
  目录的 node_modules/.bin,直接写 tsc 拿到的是根目录的 TS 5.9 而不是 apps/api 的 TS 7,
  实测报一堆假错
- 根脚本:fmt → vp fmt,lint → vp lint,新增 check → vp check。verify 不设同名脚本
  (Vite+ 不许任务和脚本重名),用 `bunx vp run verify`
- dev 仍是 bun run --parallel:常驻进程,缓存用不上

实测:verify 首跑全过;第二遍 5/5 命中缓存、0.25 秒;往 apps/api 塞一个类型错误,
只有 typecheck:api 和 check:routes 重跑并失败、前端直接命中缓存;.vue 里塞类型错误
同样被抓到;denyWarnings 下有一条 warning 退出码就是 1。前端构建、后端单二进制编译照常。

代价:vite-plus 带 vitest、tsgolint 等约 120MB 依赖,只进 Docker builder 阶段、不进运行
镜像,CI 的 --prebuilt 部署不受影响。

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-09-27 15:37:23 +08:00

65 lines
2.5 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { defineConfig } from "vite-plus"
/**
* 全仓的格式化(Oxfmt)、lint(Oxlint)和任务编排(vp run)都在这一份里。
* 前端自己的构建配置在 apps/web/vite.config.ts,和这里无关。
*/
export default defineConfig({
fmt: {
semi: false,
// Oxfmt 在 Vite+ 下默认 100 列,全仓一直是 80 —— 不写的话一格式化就是几百个文件的 diff
printWidth: 80,
ignorePatterns: [
// drizzle-kit 生成的迁移快照。内容等价的重排也别做 —— 这些文件是
// db:generate 拿来比对上一版结构的输入,只该由 drizzle-kit 写。
"apps/api/src/db/meta/",
// unplugin 每次 dev 都会重写,格式化了也留不住
"apps/web/src/auto-imports.d.ts",
"apps/web/src/components.d.ts",
// 只管代码,和原来 Prettier 的范围一致:文档里的中文表格、compose / workflow
// 里逐行写的注释都是手排的,别让格式化器重排
"**/*.md",
"**/*.yml",
"**/*.yaml",
"**/*.json",
"**/*.toml",
],
},
lint: {
options: {
// 有一条 warning 就算失败:放任 warning 攒起来,等于没有 lint
denyWarnings: true,
},
ignorePatterns: [
"apps/api/src/db/meta/",
"apps/web/src/auto-imports.d.ts",
"apps/web/src/components.d.ts",
],
},
/**
* `vp run <任务>`。定义在这里的任务默认带缓存:读到的文件没变就直接复用上次的结果,
* 改了哪个包只重跑哪个包的检查。cwd 相对仓库根。
*/
run: {
tasks: {
// 一律经 `bun run <脚本>` 调,不直接写 tsc:任务定义在根包里,PATH 是根目录的
// node_modules/.bin,直接写 tsc 拿到的是根目录的 TS 5.9 而不是 apps/api 的 TS 7,
// 报一堆假错(实测)。经脚本走,用的是各包自己的依赖,命令也只在 package.json 写一份
"typecheck:api": { command: "bun run typecheck", cwd: "apps/api" },
"typecheck:web": { command: "bun run type-check", cwd: "apps/web" },
"check:routes": { command: "bun run check:routes", cwd: "apps/api" },
"check:ast": { command: "bun run check:ast", cwd: "apps/api" },
// 提交前、CI 里跑这一条:格式 + lint + 两边类型检查 + 路由遮蔽 + AST 节点
verify: {
command: "vp check",
dependsOn: [
"typecheck:api",
"typecheck:web",
"check:routes",
"check:ast",
],
},
},
},
})