From 05804f41a91abe6a84b2c49b6e7b68e39578d5ae Mon Sep 17 00:00:00 2001 From: chenxing Date: Tue, 29 Sep 2026 11:38:31 +0800 Subject: [PATCH] =?UTF-8?q?theme:=20=E5=88=87=20A=20=E7=B1=BB=E5=85=8D?= =?UTF-8?q?=E6=8F=92=E4=BB=B6=E6=8E=A5=E5=85=A5=EF=BC=88YschTheme=20?= =?UTF-8?q?=E6=96=B9=E6=A1=88=20=C2=A711=EF=BC=89=EF=BC=8C=E5=88=A0=20vend?= =?UTF-8?q?ored=20vite=20=E6=8F=92=E4=BB=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - 接入点收敛为 index.html 内一段同步 loader(env-config 引导之后、title/入口之前), document.write 保 parser-blocking;通道 init 已吸收 FOUC 门 + manifest 预取 + DCL 挂 + href 去重交棒,主题逻辑升级全走 /static,不再需要重新构建本应用 - 域名四档:staticHost > baseHost > VITE_THEME_HOST(dev 跨源直连专用,需通道 CORS)> 同源相对。 不复用 VITE_BASE_HOST:它与 SSO/API 共用、.env.dev 里本就非空,复用会让 dev 立刻跨源被 CORS 拦; build 产物不读 .env,占位符留字面量 → 置空 → 同源(产物零环境值烧入,与 2f423c2 口径一致) - 删 plugins/vite-plugin-theme(-420 行 vendor)+ package.json/lock 的 file: 依赖, 根治 CI 容器解析不到 file:../../YschTheme 那类 npm ci 秒失败 - vite.config:保留 dev /static 代理(联调便利,changeOrigin 顺带改写 Host,等价旧插件的 headers.Host 补偿),注释端口纠错 5174 → 9527;theme.ts 同步到通道版本 20260929-1112-1b1724d - 已验:npm run build 通过,dist/index.html 注入段存活且无 B 类痕迹, YschTheme npm run smoke 断言 3 张主题表按序挂载、FOUC 门先于首帧、manifest 只拉一次 --- index.html | 22 +++ package-lock.json | 14 -- package.json | 1 - plugins/vite-plugin-theme/lib/index.cjs | 166 ---------------------- plugins/vite-plugin-theme/lib/index.d.cts | 44 ------ plugins/vite-plugin-theme/lib/index.d.ts | 44 ------ plugins/vite-plugin-theme/lib/index.js | 132 ----------------- plugins/vite-plugin-theme/package.json | 34 ----- src/main.ts | 4 +- src/utils/theme.ts | 2 +- vite.config.ts | 17 ++- 11 files changed, 37 insertions(+), 443 deletions(-) delete mode 100644 plugins/vite-plugin-theme/lib/index.cjs delete mode 100644 plugins/vite-plugin-theme/lib/index.d.cts delete mode 100644 plugins/vite-plugin-theme/lib/index.d.ts delete mode 100644 plugins/vite-plugin-theme/lib/index.js delete mode 100644 plugins/vite-plugin-theme/package.json diff --git a/index.html b/index.html index 5d7555f..188e452 100644 --- a/index.html +++ b/index.html @@ -29,6 +29,28 @@ } })(); + + <%- title %> diff --git a/package-lock.json b/package-lock.json index 0130ac0..59c17ee 100644 --- a/package-lock.json +++ b/package-lock.json @@ -33,7 +33,6 @@ "@unocss/preset-rem-to-px": "^66.6.0", "@unocss/preset-uno": "^66.6.0", "@vitejs/plugin-vue": "^5.0.4", - "@yunhai/vite-plugin-theme": "file:./plugins/vite-plugin-theme", "fast-glob": "^3.3.2", "typescript": "^5.2.2", "unocss": "^66.6.0", @@ -3002,10 +3001,6 @@ "node": ">=10.0.0" } }, - "node_modules/@yunhai/vite-plugin-theme": { - "resolved": "plugins/vite-plugin-theme", - "link": true - }, "node_modules/acorn": { "version": "8.18.0", "resolved": "https://registry.npmmirror.com/acorn/-/acorn-8.18.0.tgz", @@ -12056,15 +12051,6 @@ "resolved": "https://registry.npmmirror.com/tslib/-/tslib-2.3.0.tgz", "integrity": "sha512-N82ooyxVNm6h1riLCoyS9e3fuJ3AMG2zIZs2Gd1ATcSFjSA23Q0fzjjZeh0jbJvWVDZ0cJT8yaNNaaXHzueNjg==", "license": "0BSD" - }, - "plugins/vite-plugin-theme": { - "name": "@yunhai/vite-plugin-theme", - "version": "0.1.0", - "dev": true, - "license": "UNLICENSED", - "peerDependencies": { - "vite": ">=4.0.0" - } } } } diff --git a/package.json b/package.json index 29d0452..31ff0a2 100644 --- a/package.json +++ b/package.json @@ -40,7 +40,6 @@ "@unocss/preset-rem-to-px": "^66.6.0", "@unocss/preset-uno": "^66.6.0", "@vitejs/plugin-vue": "^5.0.4", - "@yunhai/vite-plugin-theme": "file:./plugins/vite-plugin-theme", "fast-glob": "^3.3.2", "typescript": "^5.2.2", "unocss": "^66.6.0", diff --git a/plugins/vite-plugin-theme/lib/index.cjs b/plugins/vite-plugin-theme/lib/index.cjs deleted file mode 100644 index ec43093..0000000 --- a/plugins/vite-plugin-theme/lib/index.cjs +++ /dev/null @@ -1,166 +0,0 @@ -'use strict'; -"use strict"; -var __defProp = Object.defineProperty; -var __getOwnPropDesc = Object.getOwnPropertyDescriptor; -var __getOwnPropNames = Object.getOwnPropertyNames; -var __hasOwnProp = Object.prototype.hasOwnProperty; -var __export = (target, all) => { - for (var name in all) - __defProp(target, name, { get: all[name], enumerable: true }); -}; -var __copyProps = (to, from, except, desc) => { - if (from && typeof from === "object" || typeof from === "function") { - for (let key of __getOwnPropNames(from)) - if (!__hasOwnProp.call(to, key) && key !== except) - __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable }); - } - return to; -}; -var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod); - -// src/index.ts -var src_exports = {}; -__export(src_exports, { - DEFAULT_PROXY_TARGET: () => DEFAULT_PROXY_TARGET, - FALLBACK_STYLE: () => FALLBACK_STYLE, - MANIFEST: () => MANIFEST, - RESOLVED_VIRTUAL_ID: () => RESOLVED_VIRTUAL_ID, - VIRTUAL_ID: () => VIRTUAL_ID, - default: () => src_default, - initBootstrap: () => initBootstrap, - isValidStaticBase: () => isValidStaticBase, - loaderSource: () => loaderSource, - yhTheme: () => yhTheme -}); -module.exports = __toCommonJS(src_exports); -var DEFAULT_PROXY_TARGET = "http://base.yunhaixingtong.com"; -var VIRTUAL_ID = "virtual:yh-theme-loader"; -var RESOLVED_VIRTUAL_ID = `\0${VIRTUAL_ID}`; -var MANIFEST = "manifest.json"; -var FALLBACK_STYLE = `html:not(.yh-theme-ready) body { opacity: 0; } -html.yh-theme-ready body { opacity: 1; transition: opacity .15s; }`; -function isValidStaticBase(v) { - return v === "" || /^\//.test(v) || /^https?:\/\//.test(v); -} -function loaderSource(staticBase) { - return `// BASE\uFF1A\u6839\u76F8\u5BF9\uFF08\u4E09\u7AEF\u540C\u6E90\uFF09\u3002\u7981\u6B62\u7528 BASE_URL \u4E4B\u7C7B\u7684\u6784\u5EFA\u671F\u76F8\u5BF9\u57FA\u51C6\u2014\u2014 -// Notice \u7684 vite base \u662F './'\uFF0C\u4F1A\u89E3\u6790\u6210 /notice/front/static/... \u5BFC\u81F4 404 -const BASE = ${JSON.stringify(staticBase)} || (window.__APP_CONFIG__ && window.__APP_CONFIG__.staticHost != null ? window.__APP_CONFIG__.staticHost : '') -const markReady = () => document.documentElement.classList.add('yh-theme-ready') -const markFailed = (f) => { - console.warn(\`[yh-theme] \${f} \u52A0\u8F7D\u5931\u8D25\uFF0C\u964D\u7EA7\u4E3A\u7EC4\u4EF6\u5E93\u9ED8\u8BA4\u89C2\u611F\`) - document.documentElement.classList.add('yh-theme-failed', 'yh-theme-ready') -} -// \u4F18\u5148\u590D\u7528 init \u811A\u672C\u5728 \u91CC\u5DF2\u542F\u52A8\u7684 manifest \u9884\u53D6\uFF08\u542B\u5E26\u7248\u672C preload\uFF09 -;(window.__YH_THEME_MANIFEST__ ?? fetch(\`\${BASE}/static/${MANIFEST}\`).then(r => r.json())) - .then((m) => { - let loaded = 0 - m.files.forEach((f) => { - const l = document.createElement('link') - l.rel = 'stylesheet' - l.href = \`\${BASE}/static/\${f}?v=\${m.version}\` // \u4E0E init preload \u7684 URL \u4E00\u5B57\u4E0D\u5DEE - l.onload = () => { if (++loaded === m.files.length) markReady() } - l.onerror = () => markFailed(f) - document.head.appendChild(l) - }) - setTimeout(markReady, 500) // \u515C\u5E95\uFF1A500ms \u672A load \u5B8C\u4E5F\u653E\u884C - }) - .catch(() => markFailed('manifest')) -`; -} -function initBootstrap(staticBase) { - const url = `${staticBase.replace(/\/+$/, "")}/static/js/yh-theme-init.js`; - const setBase = staticBase ? `window.__YH_THEME_STATIC_BASE__=${JSON.stringify(staticBase)};` : ""; - return `(function(){${setBase}document.write('