Skip to content

Commit 0c39698

Browse files
Lokins577claude
andcommitted
build: 图集产物入库,构建不再生成
改用 GitHub + Cloudflare 自动部署后,图集生成不该留在构建链路里: sharp 与 minecraft-assets 是两个重包,每次部署都装它们只为产出 240KB 的 静态文件,很不划算。改为产物入库,更新 Minecraft 版本时手动 pnpm atlas。 同时把 D1 迁移必须手动执行这点写进文档 —— 自动部署只做构建与发布, 漏了迁移部署照样成功,但接口一碰数据库就 500,不容易联想到原因。 Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent e512e49 commit 0c39698

5 files changed

Lines changed: 48 additions & 5 deletions

File tree

.gitignore

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,10 @@ debug-*.md
4343
# 数据文件(历史遗留,不再入库)
4444
data/
4545

46-
# 构建期生成的 Minecraft 资源(由 scripts/build-atlas.mjs 产出)
47-
public/mc/
46+
# 注意:public/mc/ 的图集产物**是入库的**(约 240KB)。
47+
# 它由 scripts/build-atlas.mjs 生成,但生成依赖 sharp + minecraft-assets 两个重包,
48+
# 放进 CI 会让每次自动部署都白装几十 MB。产物本身很小,直接提交更划算。
49+
# 更新 Minecraft 版本时手动跑 `pnpm atlas` 重新生成并提交。
4850
public/vendor/mc/
4951
app/public/vendor/mc/
5052
.playwright-mcp/

docs/deployment.md

Lines changed: 41 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -218,13 +218,53 @@ webhook 本地收不到(Prism 打不到 localhost),留到线上验。
218218

219219
## 五、建表与部署
220220

221+
### 5.1 建表(**必须手动,自动部署不会做**
222+
221223
```bash
224+
pnpm install
222225
pnpm db:migrate:remote
223-
pnpm deploy
224226
```
225227

228+
在本地跑,通过 wrangler 连远程 D1。**Cloudflare 的 Git 自动部署只做构建与发布,
229+
不会执行数据库迁移** —— 漏了这步部署照样成功,但接口一碰数据库就 500,
230+
`/api/_ping` 会返回 `dbError: true`
231+
232+
以后每次新增 migration 文件,合并后也都要手动跑一次。
233+
226234
不需要迁移旧数据 —— 旧库已放弃,空库起步。
227235

236+
### 5.2 部署
237+
238+
**方式 A:GitHub + Cloudflare 自动部署(当前采用)**
239+
240+
Dashboard → Workers → 该 Worker → Settings → Build:
241+
242+
|||
243+
|---|---|
244+
| Git repository | `New-Sim-U-Kraft/homepage` |
245+
| Branch | `refactor/homepage`(正式切换后改 `main`|
246+
| Build command | `pnpm build` |
247+
| Deploy command | `npx wrangler deploy` |
248+
| Root directory | 留空 |
249+
250+
仓库有 `pnpm-lock.yaml``packageManager` 字段,Cloudflare 会自动选用 pnpm。
251+
252+
两点需要知道:
253+
254+
- **纹理图集是入库的**`public/mc/`,约 240KB)。生成它需要 `sharp` +
255+
`minecraft-assets` 两个重包,放进 CI 会让每次部署白装几十 MB,而产物本身很小。
256+
所以 `pnpm build` **不生成图集**,只在更新 Minecraft 版本时手动
257+
`pnpm atlas` 并提交产物。
258+
- secret 独立存储,不随部署更新;`[vars]` 则跟着 `wrangler.toml` 一起生效。
259+
260+
**方式 B:本地手动部署**
261+
262+
```bash
263+
pnpm deploy
264+
```
265+
266+
两种方式可混用,同一个 Worker。
267+
228268
### 第一个管理员
229269

230270
角色由 Prism 身份组决定,官网没有提权入口,所以**第一个管理员必须在 Prism 侧

package.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,12 +9,12 @@
99
},
1010
"scripts": {
1111
"dev": "nuxt dev",
12-
"build": "node scripts/build-atlas.mjs && nuxt build",
12+
"build": "nuxt build",
1313
"preview": "wrangler dev",
1414
"deploy": "pnpm build && wrangler deploy",
1515
"atlas": "node scripts/build-atlas.mjs",
1616
"gen:key": "node scripts/gen-license-key.mjs",
17-
"postinstall": "nuxt prepare && node scripts/build-atlas.mjs",
17+
"postinstall": "nuxt prepare",
1818
"typecheck": "nuxt typecheck",
1919
"lint": "eslint .",
2020
"lint:fix": "eslint . --fix",

public/mc/atlas.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

public/mc/atlas.png

152 KB
Loading

0 commit comments

Comments
 (0)