1
0
Files
DiAL/openspec/specs/vite-frontend-bundling/spec.md
lanyuanxiaoyao d6a77b2c6e feat: 迁移前端构建从 Bun fullstack 到 Vite
前端性能问题根因在于 Bun bundler 无法有效 code split、CSS
tree-shake 和产出优化的前端资源。经多轮 Bun 原生优化尝试
均无明显效果后,决定将前端构建迁回 Vite。

主要变更:

- 前端构建:从 Bun HTML import bundling 切换为 Vite build
  (Rolldown code splitting、vendor chunk、CSS 优化)
- 开发模式:从 Bun fullstack 单进程 HMR 切换为 Vite dev
  server + Bun API server 双进程(:5173 + :3000)
- 生产构建:三步流水线(Vite build → code generation →
  Bun compile),通过 `import with { type: "file" }` 嵌入前端资源
- 静态资源服务:从 Bun HTML import manifest 切换为自定义
  serveStaticAsset 函数,支持 SPA fallback 和正确的 Cache-Control
- Server 接口:BootstrapOptions 和 StartServerOptions 增加
  staticAssets? 可选参数
- 文档更新:DEVELOPMENT.md 和 README.md 反映新的开发模式,
  主 specs 同步 delta 变更

新增能力:
- static-asset-embedding: 构建时资源扫描与 code generation、
  运行时静态资源服务
- vite-frontend-bundling: Vite 构建配置、code splitting 策略、
  CSS 处理
2026-05-15 11:26:46 +08:00

47 lines
1.9 KiB
Markdown
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.
# Vite Frontend Bundling
定义 Vite 作为前端构建工具的配置、产出结构和优化策略。
## Purpose
使用 Vite 的 Rolldown 引擎完成前端打包,实现 code splitting、vendor chunk 分离和 CSS 优化,解决 Bun bundler 前端性能问题。
## Requirements
### Requirement: Vite 前端构建配置
系统 SHALL 使用 Vite 作为前端构建工具,配置文件位于项目根目录 `vite.config.ts`,以 `src/web` 为 root产出到 `dist/web/`
#### Scenario: 运行 Vite 生产构建
- **WHEN** 构建脚本执行 `bunx --bun vite build`
- **THEN** Vite SHALL 将 `src/web/index.html` 及其引用的所有模块构建到 `dist/web/` 目录,包含 `index.html``assets/` 子目录
#### Scenario: 产出文件名包含 content hash
- **WHEN** Vite 构建完成
- **THEN** `assets/` 目录下的 JS 和 CSS 文件名 SHALL 包含 content hash`index-a1b2c3.js`
### Requirement: Code Splitting 策略
系统 SHALL 配置 Vite 的 Rolldown code splitting将 vendor 库分离为独立 chunks。
#### Scenario: React 相关库分离
- **WHEN** Vite 构建完成
- **THEN** `react``react-dom``scheduler` SHALL 被打包到名为 `vendor-react` 的独立 chunk
#### Scenario: TDesign 相关库分离
- **WHEN** Vite 构建完成
- **THEN** `tdesign-react``tdesign-icons-react` 相关模块 SHALL 被打包到名为 `vendor-tdesign` 的独立 chunk
#### Scenario: 图表库分离
- **WHEN** Vite 构建完成
- **THEN** `recharts``d3-*` 相关模块 SHALL 被打包到名为 `vendor-chart` 的独立 chunk
### Requirement: CSS 处理
系统 SHALL 通过 Vite 处理 CSS 导入,产出独立的 CSS 文件。
#### Scenario: CSS 文件产出
- **WHEN** Vite 构建完成
- **THEN** 所有 CSS 导入 SHALL 被提取为独立的 `.css` 文件到 `assets/` 目录
#### Scenario: CSS 压缩
- **WHEN** Vite 执行生产构建
- **THEN** 产出的 CSS 文件 SHALL 经过压缩处理