use-vp-config
Compare original and translation side by side
🇺🇸
Original
English🇨🇳
Translation
ChineseUse Liangmi VP Config
使用 Liangmi VP Config
Configure projects with , an opinionated preset for Vite+, the united JavaScript toolchain. Treat Vite+ as distinct from Vite.
@liangmi/vp-config使用 配置项目。它是一套面向 Vite+ 的强约定预设,而 Vite+ 是统一的 JavaScript 工具链。请将 Vite+ 与 Vite 视为不同工具。
@liangmi/vp-configInspect the project
检查项目
Before editing:
- Read the repository's and existing
AGENTS.md.vite.config.ts - Inspect , source entry points, workspace layout, and browser or Node.js signals.
package.json - Check local Vite+ documentation in when an option is uncertain. Use https://viteplus.dev/guide/ only when local docs are unavailable or outdated.
node_modules/vite-plus/docs - Preserve project-specific overrides instead of replacing them blindly.
编辑前:
- 阅读仓库的 和现有的
AGENTS.md。vite.config.ts - 检查 、源码入口、工作区布局,以及浏览器端或 Node.js 端的使用信号。
package.json - 如果不确定某个选项,请查阅 中的本地 Vite+ 文档。仅当本地文档不可用或已过期时,才使用 https://viteplus.dev/guide/。
node_modules/vite-plus/docs - 保留项目特定的覆盖配置,不要盲目替换。
Select a preset
选择预设
Choose one category for each :
vite.config.ts| Category | Use for | Included parts |
|---|---|---|
| Workspace roots and projects without a clearer role | |
| Node.js CLI, TUI, React Ink, or Vue TUI projects | |
| Published or reusable libraries | |
| Browser applications and websites | |
In a monorepo, use at the workspace root and choose , , or for member projects. Do not mix library and website signals in one project.
baseclilibwebsiteTreat as experimental. It supports browser and component linting, but Vue template linting depends on improved upstream Oxlint support.
website为每个 选择一个类别:
vite.config.ts| 类别 | 适用场景 | 包含的部件 |
|---|---|---|
| 工作区根目录,以及没有更明确角色的项目 | |
| Node.js CLI、TUI、React Ink 或 Vue TUI 项目 | |
| 已发布或可复用的库 | |
| 浏览器应用和网站 | |
在 monorepo 中,工作区根目录使用 ,成员项目则选择 、 或 。不要在同一个项目中混用库和网站信号。
baseclilibwebsite将 视为实验性功能。它支持浏览器代码和组件的 lint,但 Vue 模板 lint 依赖上游 Oxlint 支持的改进。
websiteInstall with Vite+
使用 Vite+ 安装
Use Vite+ for package management:
bash
vp install -D @liangmi/vp-configDo not use or directly when the project is managed by Vite+.
npmpnpmThis preset requires . Align the installed version with the preset's peer dependency; keep any alias to on the same version.
vite-plus@1.0.0-rc.1vite@voidzero-dev/vite-plus-core使用 Vite+ 进行包管理:
bash
vp install -D @liangmi/vp-config当项目由 Vite+ 管理时,不要直接使用 或 。
npmpnpm此预设要求 。安装版本应与预设的 peer dependency 保持一致;如果保留了指向 的 别名,也应使用相同版本。
vite-plus@1.0.0-rc.1@voidzero-dev/vite-plus-coreviteConfigure vite.config.ts
vite.config.ts配置 vite.config.ts
vite.config.tsWrap the configuration with the selected named export:
typescript
import { lib } from '@liangmi/vp-config'
export default lib({
pack: {
entry: './src/index.ts'
}
})The wrapper accepts the same object, function, or promise shapes as Vite+'s . User values deeply override the preset while untouched nested defaults remain enabled.
defineConfigFor and , define explicitly from the project's real source entry points. The preset cannot infer the package's intended public entries.
libclipack.entryOnly select parts provided by the chosen category. Do not import a preset outside .
vite.config.tsSince we already use vp config preset, most of the config items can be omiited. For example, we do not need to define , , and config most of the time, generation, , generation or in are also set by default. If you are doing migration works, please handle them as well.
lintstagedfmtdtsfixedExtendionsexportminifypack使用选定的命名导出包装配置:
typescript
import { lib } from '@liangmi/vp-config'
export default lib({
pack: {
entry: './src/index.ts'
}
})该 wrapper 接受与 Vite+ 的 相同的对象、函数或 Promise 形态。用户提供的值会深度覆盖预设,而未修改的嵌套默认值仍保持启用。
defineConfig对于 和 ,应根据项目真实的源码入口显式定义 。预设无法推断包预期的公共入口。
libclipack.entry仅使用所选类别提供的部件。不要在 之外导入 preset。
vite.config.ts由于已经使用 vp config preset,大多数配置项都可以省略。例如,通常不需要定义 、 和 配置; 中的 生成、、 生成和 也已默认设置。如果正在进行迁移,也请一并处理这些配置。
lintstagedfmtpackdtsfixedExtendionsexportminifyWork with preset defaults
使用预设默认值
Assume these defaults unless the project explicitly overrides them:
- Linting uses strict, type-aware Oxlint with type checking and warnings denied. Do not add a separate check solely for type checking.
tsc - Style rules are explicitly allowlisted to keep lint behavior stable across Oxlint upgrades. New upstream style rules stay disabled until they are reviewed and added.
- is rejected except in the
console.logcategory and Node.js script overrides.cli - Formatting uses Oxfmt with single quotes, no semicolons, no unnecessary trailing commas, sorted imports, and sorted fields.
package.json - packaging generates declarations with
liband package exports with fixed extensions.dts.generator: 'tsgo' - packaging targets Node.js, minifies, strips
cliprefixes, and disables declaration generation.node: - Staged files run .
vp check --fix
Put task cache options (, , , and ) inside .
inputoutputenvuntrackedEnvrun.tasks.<name>.cacheUse the generated cached tasks when suitable:
| Task | Underlying command |
|---|---|
| |
| |
| |
| |
| |
| |
| |
Run them with or . Package scripts may call them, for example . If there is existing scripts calling inside package.json, you are supposed to change them to (Only for commands listed above.).
vp run <task>vpr <task>"build": "vp run cpack"vp <command>vp run c<xxx>除非项目明确覆盖,否则应使用以下默认值:
- Lint 使用严格且类型感知的 Oxlint,启用类型检查并禁止警告。不要仅为类型检查而额外添加 检查。
tsc - 样式规则采用显式允许列表,以保持 lint 行为在 Oxlint 升级前后保持稳定。新的上游样式规则在经过审查并加入允许列表前保持禁用。
- 除 类别和 Node.js 脚本覆盖配置外,不允许使用
cli。console.log - 格式化使用 Oxfmt,采用单引号、不使用分号、不添加不必要的尾随逗号,并排序 imports 和 字段。
package.json - 打包通过
lib生成类型声明,并生成使用固定扩展名的 package exports。dts.generator: 'tsgo' - 打包以 Node.js 为目标,执行压缩、去除
cli前缀,并禁用类型声明生成。node: - 已暂存的文件会运行 。
vp check --fix
将任务缓存选项(、、 和 )放在 中。
inputoutputenvuntrackedEnvrun.tasks.<name>.cache适用时,使用以下已生成的缓存任务:
| 任务 | 底层命令 |
|---|---|
| |
| |
| |
| |
| |
| |
| |
通过 或 运行它们。Package scripts 也可以调用这些任务,例如 。如果 中已有脚本调用 ,应将其改为 (仅限上述列出的命令)。
vp run <task>vpr <task>"build": "vp run cpack"package.jsonvp <command>vp run <c<xxx>>Migration
迁移
@liangmi/vp-configIf you meet cases that can't fix easily, we prefer than disabling one rules global in .
// oxlint-disable-xxxxvite.config.ts@liangmi/vp-config如果遇到难以修复的情况,我们更倾向于使用 ,而不是在 中全局禁用某条规则。
// oxlint-disable-xxxxvite.config.tsValidate changes
验证更改
After editing:
- Run when commit-hook configuration needs to be installed or refreshed.
vp config - Run .
vp check - Run the relevant build, package, or test task for the changed project.
- Fix preset-plugin errors rather than disabling them. They detect orphan configs, imports outside , missing preset wrappers, improper root or project categories, and mixed library and website signals.
vite.config.ts
编辑后:
- 需要安装或刷新 commit hook 配置时,运行 。
vp config - 运行 。
vp check - 针对发生更改的项目,运行相关的构建、打包或测试任务。
- 修复 preset 插件报告的错误,而不是禁用这些检查。它们能够检测孤立配置、之外的导入、缺失的 preset wrapper、不正确的根项目或项目类别,以及库与网站信号混用。
vite.config.ts