Files
lijing c2a1f16915
deploy-bschclass-front / build-and-deploy (push) Failing after 3m2s
build / build (push) Successful in 3m24s
fix(theme): appearance 走同源 ctx 前缀,不被跨源跳过
主题通道 yh-theme-init.js 的 appearance 有硬性同源限制
(appearanceSameOrigin 不通过直接 return,连请求都不发)。

- host.config.ts:仅当最终 serviceUrl 与当前页面同源时,才回写
  __APP_CONFIG__.serviceHost;dev 的绝对地址(跨源)不回写,保持
  '/api/appearance' 同源相对,交由 vite 代理转发,避免被整段跳过。
- prod:serviceUrl = 同域 ctx(https://base.../userclass),回写后
  appearance 命中 https://base.../userclass/api/appearance。
- vite.config.ts:/api 代理支持 YH_API_PROXY_TARGET 指向真实后端
  (target 带 /userclass 前缀即可,无需 rewrite)。
2026-10-20 15:16:55 +08:00

91 lines
3.4 KiB
TypeScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { defineConfig } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
import { createHtmlPlugin } from "vite-plugin-html";
/**
* 构建基线对齐 NoticeFront(云海子应用前端接入规范 v1.12):
* Vue3 + TS + view-ui-plus(1.3.24) + Vite;主题/皮肤/图标由 /static 通道下发。
*/
export default defineConfig(({ mode }) => {
const root = process.cwd();
return {
plugins: [
vue(),
createHtmlPlugin({
minify: true,
pages: [
{
entry: "src/main.ts",
template: "index.html",
filename: "index.html",
injectOptions: {
data: {
title: "学校管理",
injectScript: ``,
},
},
},
],
}),
],
resolve: {
alias: {
"@": path.resolve(root, "src"),
"@public": path.resolve(root, "public"),
},
extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"],
},
server: {
host: "localhost",
port: 8088,
open: false,
proxy: {
// 本地后端:serviceUrl 在 dev 下为空 → /api/* 同源相对,由本代理转发
// 想直接连真实后端(含主题通道「同源」的 appearance):
// YH_API_PROXY_TARGET=http://base.yunhaixingtong.com/userclass npm run dev
// 注意 target 要带上下文前缀 /userclass,http-proxy 会把它拼在 /api 前
"/api": {
target: process.env.YH_API_PROXY_TARGET || "http://localhost:8101",
changeOrigin: true,
},
// 主题通道本地联调:默认线上通道,联调本地通道源用
// YH_THEME_PROXY_TARGET=http://localhost:9527 npm run dev
"/static": {
target: process.env.YH_THEME_PROXY_TARGET || "http://base.yunhaixingtong.com",
changeOrigin: true,
},
},
},
base: "./",
build: {
target: "modules",
outDir: "dist",
assetsDir: "assets",
sourcemap: false,
minify: "esbuild",
chunkSizeWarningLimit: 1500,
cssTarget: "chrome61",
rollupOptions: {
input: {
main: path.resolve(root, "index.html"),
},
output: {
chunkFileNames: "static/js/[name]-[hash].js",
entryFileNames: "static/js/[name]-[hash].js",
assetFileNames: (assetInfo: any) => {
if (assetInfo.type === "asset" && /\.(jpe?g|png|gif|svg)$/i.test(assetInfo.name)) {
return "static/img/[name].[hash][ext]";
}
if (assetInfo.type === "asset" && /\.(ttf|woff|woff2|eot)$/i.test(assetInfo.name)) {
return "static/fonts/[name].[hash][ext]";
}
return "static/[ext]/[name]-[hash].[ext]";
},
},
},
},
};
});