From 7c08e83f384fd228d10b22c1b183dd783732c134 Mon Sep 17 00:00:00 2001 From: zzh <1368735060@qq.com> Date: Mon, 24 Aug 2026 19:44:31 +0800 Subject: [PATCH] =?UTF-8?q?fix:=20=E5=AE=98=E7=BD=91=E9=9D=99=E6=80=81?= =?UTF-8?q?=E8=B5=84=E6=BA=90=E6=94=B9=E5=8F=91=E5=B8=83=E5=88=B0=20/site/?= =?UTF-8?q?assets=EF=BC=8C=E4=BF=AE=E5=A4=8D=E7=BA=BF=E4=B8=8A=20404?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit postbuild 不再合并到 dist/assets(与 Vite 产物冲突且 Windows 下 cpSync 失败),改为完整复制 IDE官网 到 dist/site 并注入 base href;nginx 增加 /site/ 静态路由。 Co-authored-by: Cursor --- IDE官网/assets/js/stage-globe.js | 2 +- nginx-default.conf | 8 ++++++ nginx-docker.conf | 7 +++++ scripts/postbuild-cleanup-dist.js | 48 ++++++++++++++++++++++++------- 4 files changed, 54 insertions(+), 11 deletions(-) diff --git a/IDE官网/assets/js/stage-globe.js b/IDE官网/assets/js/stage-globe.js index 97873f7..4f12cbd 100644 --- a/IDE官网/assets/js/stage-globe.js +++ b/IDE官网/assets/js/stage-globe.js @@ -5,7 +5,7 @@ (function (global) { 'use strict'; - const WORLD_URL = '/assets/data/world-110m.json'; + const WORLD_URL = 'assets/data/world-110m.json'; const HUB = [114.06, 22.55]; const LABELS = { diff --git a/nginx-default.conf b/nginx-default.conf index 64cebd5..5b54f4c 100644 --- a/nginx-default.conf +++ b/nginx-default.conf @@ -55,6 +55,14 @@ server { add_header Cache-Control "no-cache, no-store, must-revalidate"; } + # 官网静态资源(/site/index.html 通过 base href 引用 /site/assets/...) + location ^~ /site/ { + try_files $uri =404; + expires 7d; + add_header Cache-Control "public"; + access_log off; + } + # ============ 客户 / 管理端登录入口 ============ location = /login { try_files /index.html =200; diff --git a/nginx-docker.conf b/nginx-docker.conf index b96462d..45c16d5 100644 --- a/nginx-docker.conf +++ b/nginx-docker.conf @@ -22,6 +22,13 @@ server { add_header Cache-Control "no-cache, no-store, must-revalidate"; } + location ^~ /site/ { + try_files $uri =404; + expires 7d; + add_header Cache-Control "public"; + access_log off; + } + location = /login { try_files /index.html =200; } diff --git a/scripts/postbuild-cleanup-dist.js b/scripts/postbuild-cleanup-dist.js index 635bd01..2d1d3d8 100644 --- a/scripts/postbuild-cleanup-dist.js +++ b/scripts/postbuild-cleanup-dist.js @@ -6,6 +6,30 @@ const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), '..'); const dist = path.join(root, 'dist'); const siteSrc = path.join(root, 'IDE官网'); const legacyLoginDir = path.join(dist, 'login'); +const siteDir = path.join(dist, 'site'); + +/** Avoid fs.cpSync merge into dist/assets (conflicts with Vite + can crash on Windows). */ +function copyDirSync(src, dest, options = {}) { + const { skipDirNames = new Set() } = options; + fs.mkdirSync(dest, { recursive: true }); + for (const entry of fs.readdirSync(src, { withFileTypes: true })) { + if (entry.isDirectory() && skipDirNames.has(entry.name)) continue; + const srcPath = path.join(src, entry.name); + const destPath = path.join(dest, entry.name); + if (entry.isDirectory()) { + copyDirSync(srcPath, destPath, options); + continue; + } + if (entry.isFile()) { + fs.copyFileSync(srcPath, destPath); + } + } +} + +function injectSiteBaseHref(html) { + if (html.includes('', '\n '); +} if (fs.existsSync(legacyLoginDir)) { fs.rmSync(legacyLoginDir, { recursive: true, force: true }); @@ -17,22 +41,26 @@ function copyOfficialSite() { return; } - const siteDir = path.join(dist, 'site'); - fs.mkdirSync(siteDir, { recursive: true }); - fs.copyFileSync(path.join(siteSrc, 'index.html'), path.join(siteDir, 'index.html')); + if (fs.existsSync(siteDir)) { + fs.rmSync(siteDir, { recursive: true, force: true }); + } + + copyDirSync(siteSrc, siteDir, { + skipDirNames: new Set(['.well-known']), + }); + + const siteIndex = path.join(siteDir, 'index.html'); + if (fs.existsSync(siteIndex)) { + const html = fs.readFileSync(siteIndex, 'utf8'); + fs.writeFileSync(siteIndex, injectSiteBaseHref(html), 'utf8'); + } const src9610 = path.join(siteSrc, '9610.html'); if (fs.existsSync(src9610)) { fs.copyFileSync(src9610, path.join(dist, '9610.html')); } - const srcAssets = path.join(siteSrc, 'assets'); - const destAssets = path.join(dist, 'assets'); - if (fs.existsSync(srcAssets)) { - fs.cpSync(srcAssets, destAssets, { recursive: true }); - } - - console.log('[postbuild] copied official site to dist/site + 9610.html + assets'); + console.log('[postbuild] copied official site to dist/site (assets under /site/assets)'); } copyOfficialSite();