apps/web preview overwrites newly built dist/index.html with stale dist/index.html.bak across builds

未关闭 适合新手
#1,938 0 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

维护者通常 1 天内回复

还没有人认领这个 Issue。

评估

难度
2/5
预计耗时
1-3 小时
新手友好度
82/100
Issue 类型
缺陷
描述清晰度
描述清楚
活跃度
活跃
技术栈
node.js, typescript, vite

调研方向

从 apps/web/package.json:8(build)和 apps/web/package.json:11(preview)开始,然后查看 apps/web/vite.config.ts:43,其中设置了 emptyOutDir: false;对比 apps/api/package.json 和 apps/gateway/package.json 的 build 脚本,寻找清理模式。注意 turbo.json:11 会缓存 dist/**,这就是过期的 .bak 得以保留的原因。完成标准是:代码变更后第二次运行 pnpm test:e2e 时,能提供新生成的带哈希的 chunks,并通过检查 <script> 标签(在 apps/web/dist/index.html 中)来验证。

由索引模型根据 Issue 内容生成。

描述

Area: Infrastructure Area: Web Bug Difficulty: Low Priority: Medium

apps/web/vite.config.ts:43 sets build.emptyOutDir: false, and apps/web/package.json:8 ("build": "tsc && NODE_ENV=production NODE_OPTIONS='--import=tsx' pnpm exec vite build") does not remove dist before building.

When pnpm test:e2e starts apps/web's preview script (apps/web/package.json:11):

env-cmd -f ../../.env -- pnpm exec import-meta-env -x .env.public -p dist/index.html && NODE_OPTIONS='--import=tsx' env-cmd -f ../../.env pnpm exec vite preview

@import-meta-env/cli saves a backup of dist/index.html to dist/index.html.bak on the first run and, whenever dist/index.html.bak already exists, reads dist/index.html.bak as its template and overwrites dist/index.html with it.

Because vite build has emptyOutDir: false:

  1. Subsequent pnpm build runs write a new dist/index.html and new content-hashed dist/assets/*.js chunks, while leaving the old dist/index.html.bak and old dist/assets/*.js files in apps/web/dist/.
  2. Turbo caches dist/** (turbo.json:11), including the stale dist/index.html.bak.
  3. On the next pnpm test:e2e run, import-meta-env overwrites the newly built dist/index.html with the stale dist/index.html.bak, so vite preview serves the old hashed JS chunks from an earlier build or branch instead of the current apps/web code.
Reproduction
  1. Run pnpm test:e2e (which creates apps/web/dist/index.html.bak via pnpm preview).
  2. Change code in apps/web (or switch branches) and run pnpm test:e2e again without rm -rf apps/web/dist.
  3. Inspect apps/web/dist/index.html after pnpm preview starts: its <script> and <link rel="modulepreload"> tags match apps/web/dist/index.html.bak from step 1 rather than the newly emitted chunks from step 2.
Possible fix

Clean dist before vite build in apps/web/package.json (matching apps/api/package.json and apps/gateway/package.json, or enable emptyOutDir: true if runtime plugin ordering allows it) or remove dist/index.html.bak during apps/web build.

主要语言
TypeScript
星标
119
派生
19
平均合并
1 天 18 小时
30 天内合并 PR
60

环境准备

  • 提供 Dockerfile 或 Docker Compose 文件
  • 没有 Pull Request 模板
  • 阅读贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

DouglasNeuroInformatics/OpenDataCapture 的其他 Issue

查看 DouglasNeuroInformatics/OpenDataCapture 的全部 Issue

相似的 Issue

更多 TypeScript Issue

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。