diff --git a/apps/web/src/shared/composables/maxkb.ts b/apps/web/src/shared/composables/maxkb.ts index d6d70df..480d009 100644 --- a/apps/web/src/shared/composables/maxkb.ts +++ b/apps/web/src/shared/composables/maxkb.ts @@ -43,6 +43,11 @@ export function useMaxKB() { if (!enableMaxkb) { return } + // 没配地址就什么都不做。这道判断原来在 vite 的 inject-maxkb 插件里, + // 插件删掉之后得挪过来,否则会拿 undefined 当 src 去请求一个 /undefined + if (!import.meta.env.PUBLIC_MAXKB_URL) { + return + } const existingScript = document.querySelector( `script[src="${import.meta.env.PUBLIC_MAXKB_URL}"]`, diff --git a/apps/web/src/shared/store/config.ts b/apps/web/src/shared/store/config.ts index faff9b2..8396a4c 100644 --- a/apps/web/src/shared/store/config.ts +++ b/apps/web/src/shared/store/config.ts @@ -10,7 +10,10 @@ export const useConfigStore = defineStore("config", () => { submissionListShowAll: true, allowRegister: false, classList: [], - enableMaxkb: true, + // 默认 false:这是给 useMaxKB 用的开关,而 MaxKB 是第三方脚本。 + // 默认 true 的话,getConfig() 还没回来挂件就已经加载执行了,服务端配置说 + // 「关」也只能事后删标签,等于开关失效。宁可晚一个来回出现,也不要关不掉。 + enableMaxkb: false, }) async function getConfig() { const res = await getWebsiteConfig() diff --git a/apps/web/vite.config.ts b/apps/web/vite.config.ts index 5ea553f..3d9893b 100644 --- a/apps/web/vite.config.ts +++ b/apps/web/vite.config.ts @@ -1,5 +1,5 @@ import { fileURLToPath, URL } from "node:url" -import { defineConfig, loadEnv, type Plugin } from "vite" +import { defineConfig, loadEnv } from "vite" import vue from "@vitejs/plugin-vue" import legacy from "@vitejs/plugin-legacy" import AutoImport from "unplugin-auto-import/vite" @@ -69,25 +69,15 @@ const polyfills = [ "web.url.can-parse", ] -// index.html 里按需注入 MaxKB 脚本(原 Rsbuild EJS 模板的等价实现) -function injectMaxkb(maxkbUrl: string | undefined): Plugin { - return { - name: "inject-maxkb", - transformIndexHtml(html) { - if (!maxkbUrl) return html - return { - html, - tags: [ - { - tag: "script", - attrs: { async: true, defer: true, src: maxkbUrl }, - injectTo: "head", - }, - ], - } - }, - } -} +// MaxKB 脚本**不要**在这里注入 index.html。 +// +// 原来有个 inject-maxkb 插件把