From f625fe8e8ba0af10e25226a19367d160f9651d00 Mon Sep 17 00:00:00 2001 From: kdletters Date: Sat, 18 Jul 2026 15:12:09 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E9=80=80=E5=BD=B9=E6=A0=B7?= =?UTF-8?q?=E5=BC=8F=E5=BC=80=E5=8F=91=E6=80=81=E5=8A=A0=E8=BD=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 将退役 CSS 源码过滤调整到 Tailwind 转换前执行 新增 Vite 插件顺序回归测试 补充退役方案与开发态白屏排障记录 --- docs/project-memory/shared-memory/pitfalls.md | 8 +++++++ ...构下线】旧创作模板业务退役方案-2026-07-17.md | 1 + scripts/vite-retired-css-plugin.test.ts | 24 +++++++++++++++++++ vite.config.ts | 2 +- 4 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 scripts/vite-retired-css-plugin.test.ts diff --git a/docs/project-memory/shared-memory/pitfalls.md b/docs/project-memory/shared-memory/pitfalls.md index 2b91e6ed7..11fe41d28 100644 --- a/docs/project-memory/shared-memory/pitfalls.md +++ b/docs/project-memory/shared-memory/pitfalls.md @@ -14,6 +14,14 @@ - 关联:相关文件、文档、提交或 Issue ``` +## Vite 源码 CSS 清理插件必须早于 Tailwind 执行 + +- 现象:生产构建通过,但本地 dev 打开主站后全页白屏,`/src/index.css` 返回 500,Vite 报 `Unknown word updateStyle`。 +- 原因:自定义 CSS 插件使用 `enforce: 'post'`,在 Tailwind/Vite 已把 CSS 转为包含 `updateStyle` import 的 JavaScript 模块后,仍调用 `postcss.parse`。 +- 处理:需要改写原始 CSS 的 transform 固定使用 `enforce: 'pre'`;最终构建产物清理继续放在 `generateBundle`,不要混用两个阶段的输入格式。 +- 验证:真实启动 `npm run dev` 后请求 `/src/index.css` 必须返回 200,并在浏览器确认 `#root` 已挂载且控制台无 CSS transform 错误。 +- 关联:`vite.config.ts`、`scripts/vite-retired-css-plugin.test.ts`。 + ## phase 上报的业务拒绝与传输失败不能共用字符串错误 - 现象:provider 已经返回并保存原图,worker 上报 `processing` 时一次断连或超时就直接把任务判为失败;或者为了规避误杀而重试所有错误,导致 stale lease 的旧 worker 继续执行后处理。 diff --git a/docs/technical/【架构下线】旧创作模板业务退役方案-2026-07-17.md b/docs/technical/【架构下线】旧创作模板业务退役方案-2026-07-17.md index 0ed249f9e..142e30330 100644 --- a/docs/technical/【架构下线】旧创作模板业务退役方案-2026-07-17.md +++ b/docs/technical/【架构下线】旧创作模板业务退役方案-2026-07-17.md @@ -35,6 +35,7 @@ - 正式应用入口使用 `active-main.tsx`、`ActiveApp.tsx`、`routing/activeAppRoutes.tsx`、`routing/activeAppPageRoutes.ts`、`services/activeAppTitle.ts`、`platform-entry/PlatformEntryActiveFlowShell.tsx` 和 `platformEntryActiveTypes.ts`;原同名非 active 文件保持历史源码原貌并退出 Vite、TypeScript、ESLint 和 Vitest。 - 旧业务源码与素材保留在仓库中;Vite 不得再引用入口或动态 import,TypeScript、ESLint、Vitest 必须明确排除旧目录和专属测试。退役源码只用于历史追溯,不允许从在运代码重新导入。 - 原 `main.tsx`、`App.tsx`、旧路由、旧标题映射、`PlatformEntryFlowShellImpl.tsx` 与旧入口类型保持原样;正式链路由 `active-main.tsx`、`ActiveApp.tsx`、`activeApp*`、`PlatformEntryActiveFlowShell.tsx` 和 `platformEntryActiveTypes.ts` 承载,只包含项目、编辑器、账号、设置与钱包公共能力。`retired/legacy-creation-templates/frontend/original/` 另保留逐文件原样快照。 +- 退役 CSS 的源码过滤必须在 Tailwind/Vite 转换前执行,产物过滤留在 `generateBundle`;禁止在 `post` transform 中把 Vite 已生成的 JavaScript 样式模块重新交给 PostCSS 解析。 - 旧 URL 统一回落到当前平台公共首页,不再提供旧业务错误页、详情页或兼容壳。 ### Rust diff --git a/scripts/vite-retired-css-plugin.test.ts b/scripts/vite-retired-css-plugin.test.ts new file mode 100644 index 000000000..e85af3d46 --- /dev/null +++ b/scripts/vite-retired-css-plugin.test.ts @@ -0,0 +1,24 @@ +import type { Plugin } from 'vite'; +import { describe, expect, it } from 'vitest'; + +import viteConfig from '../vite.config'; + +async function resolveRetiredCssPlugin() { + const resolvedConfig = + typeof viteConfig === 'function' + ? await viteConfig({ command: 'serve', mode: 'test' }) + : viteConfig; + const plugins = (resolvedConfig.plugins ?? []).flat(Infinity) as Plugin[]; + return plugins.find( + (plugin) => plugin?.name === 'retired-creation-template-css', + ); +} + +describe('retired creation template CSS plugin', () => { + it('runs before Tailwind turns source CSS into a Vite JavaScript module', async () => { + const plugin = await resolveRetiredCssPlugin(); + + expect(plugin).toBeDefined(); + expect(plugin?.enforce).toBe('pre'); + }); +}); diff --git a/vite.config.ts b/vite.config.ts index 4a7d80e56..5f840758f 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -115,7 +115,7 @@ function retiredCreationTemplateCssPlugin(): Plugin { return { name: 'retired-creation-template-css', - enforce: 'post', + enforce: 'pre', transform(code, id) { if ( !id.endsWith('/src/index.css') &&