import { resolve } from "node:path";
|
import { loadEnv } from "vite";
|
import { defineConfig } from "./internal/vite-config/src";
|
import { companies } from "./company.config";
|
|
export default defineConfig(async ({ mode }) => {
|
const env = loadEnv(mode, process.cwd(), 'VITE_');
|
// deploy.bat 通过 set "VITE_COMPANY=xx" 传入,是进程环境变量,loadEnv 读不到,需优先取 process.env
|
const companyKey = process.env.VITE_COMPANY || env.VITE_COMPANY || '';
|
const company = companies[companyKey];
|
const appLogo = company?.logo ?? '';
|
const appFavicon = company?.favicon ?? '';
|
const appApiUrl = company?.apiUrl ?? '';
|
const appName = company?.name ?? '';
|
const isDev = mode === 'development';
|
if (appName) {
|
// 覆盖浏览器标签页标题:Vite 的 resolveEnv 优先读 process.env,从而替换 index.html 里的 %VITE_APP_TITLE%
|
process.env.VITE_APP_TITLE = appName;
|
}
|
console.log('[company]', companyKey, '-> name:', appName, 'logo:', appLogo, 'api:', appApiUrl || '(from env)');
|
|
const defineVars: Record<string, string> = {
|
__APP_LOGO__: JSON.stringify(appLogo),
|
__APP_FAVICON__: JSON.stringify(appFavicon),
|
__APP_NAME__: JSON.stringify(appName),
|
};
|
if (!isDev && appApiUrl) {
|
defineVars['import.meta.env.VITE_GLOB_API_URL'] = JSON.stringify(appApiUrl);
|
defineVars['import.meta.env.VITE_BASE_URL'] = JSON.stringify(new URL(appApiUrl).origin);
|
}
|
|
return {
|
application: {},
|
vite: {
|
define: defineVars,
|
resolve: {
|
alias: {
|
'@vue-office/pdf': resolve(__dirname, 'node_modules/@vue-office/pdf/lib/v3/vue-office-pdf.mjs'),
|
'@vue-office/docx': resolve(__dirname, 'node_modules/@vue-office/docx/lib/v3/vue-office-docx.mjs'),
|
'@vue-office/excel': resolve(__dirname, 'node_modules/@vue-office/excel/lib/v3/vue-office-excel.mjs'),
|
'@vue-office/excel-css': resolve(__dirname, 'node_modules/@vue-office/excel/lib/v3/index.css'),
|
'@vue-office/pptx': resolve(__dirname, 'node_modules/@vue-office/pptx/lib/v3/vue-office-pptx.mjs'),
|
},
|
},
|
oxc: {
|
enable: false,
|
},
|
optimizeDeps: {
|
include: ["vue", "vue-router", "pinia", "ant-design-vue", "dayjs", "@vueuse/core", "axios", "@vue-office/pdf", "@vue-office/docx", "@vue-office/excel", "@vue-office/pptx"],
|
exclude: ["dhtmlx-gantt", "tinymce", "bpmn-js", "bpmn-js-properties-panel", "video.js"],
|
},
|
build: {
|
rollupOptions: {
|
output: {
|
manualChunks: id => {
|
if (id.includes("node_modules")) {
|
if (["vue", "vue-router", "pinia"].some(dep => id.includes(dep))) {
|
return "vendor-vue";
|
}
|
if (["ant-design-vue", "@vueuse/core"].some(dep => id.includes(dep))) {
|
return "vendor-ui";
|
}
|
if (["dayjs", "axios", "@vee-validate/zod", "zod"].some(dep => id.includes(dep))) {
|
return "vendor-utils";
|
}
|
if (["tinymce", "@tinymce/tinymce-vue", "@form-create/ant-design-vue"].some(dep => id.includes(dep))) {
|
return "vendor-editor";
|
}
|
if (["@vue-office"].some(dep => id.includes(dep))) {
|
return "vendor-office-preview";
|
}
|
}
|
},
|
},
|
},
|
},
|
server: {
|
allowedHosts: true,
|
watch: {
|
ignored: ["**/node_modules/**", "**/dist/**", "**/.git/**"],
|
},
|
proxy: {
|
"/admin-api": {
|
changeOrigin: true,
|
target: "http://192.168.0.10:48080",
|
ws: true,
|
},
|
},
|
},
|
},
|
};
|
});
|