chore: 合并 gitee 上游 master(依赖/配置)并保留本地定制
This commit is contained in:
commit
0293f804a9
263 files changed
+9387
-8459
No files matched your search
+106
-154
@@ -1,6 +1,5 @@
|
||||
import vue from "@vitejs/plugin-vue";
|
||||
import type { PluginOption } from "vite";
|
||||
import { type ConfigEnv, type UserConfig, loadEnv, defineConfig } from "vite";
|
||||
import { type ConfigEnv, type Plugin, type UserConfig, loadEnv, defineConfig } from "vite";
|
||||
|
||||
import AutoImport from "unplugin-auto-import/vite";
|
||||
import Components from "unplugin-vue-components/vite";
|
||||
@@ -9,24 +8,26 @@ import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
|
||||
import { mockDevServerPlugin } from "vite-plugin-mock-dev-server";
|
||||
|
||||
import UnoCSS from "unocss/vite";
|
||||
import { join, resolve } from "path";
|
||||
import { existsSync, mkdirSync, writeFileSync } from "fs";
|
||||
import { name, version } from "./package.json" with { type: "json" };
|
||||
import { existsSync, readdirSync } from "node:fs";
|
||||
import { resolve } from "node:path";
|
||||
import packageInfo from "./package.json" with { type: "json" };
|
||||
|
||||
// 平台名称、版本信息
|
||||
const __APP_INFO__ = {
|
||||
pkg: { name, version },
|
||||
pkg: { name: packageInfo.name, version: packageInfo.version },
|
||||
buildTimestamp: Date.now(),
|
||||
};
|
||||
|
||||
// ESM 模式下使用 import.meta.dirname(Node 20.11+)
|
||||
const pathSrc = resolve(import.meta.dirname, "src");
|
||||
|
||||
// Vite配置 https://cn.vitejs.dev/config
|
||||
export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
|
||||
const env = loadEnv(mode, process.cwd());
|
||||
const env = loadEnv(mode, import.meta.dirname, "");
|
||||
const port = Number(env.APP_PORT) || Number(env.VITE_APP_PORT) || 3000;
|
||||
const proxyTarget = env.API_PROXY_TARGET || env.VITE_APP_API_URL;
|
||||
|
||||
return {
|
||||
// 部署在子路径时由环境变量 VITE_BASE_URL 指定,缺省用站点根路径
|
||||
base: env.VITE_BASE_URL || "/",
|
||||
resolve: {
|
||||
alias: {
|
||||
"@": pathSrc,
|
||||
@@ -42,74 +43,63 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
|
||||
},
|
||||
server: {
|
||||
host: "0.0.0.0",
|
||||
port: +env.VITE_APP_PORT,
|
||||
port,
|
||||
open: true,
|
||||
proxy: {
|
||||
[env.VITE_APP_BASE_API]: {
|
||||
[env.VITE_API_BASE]: {
|
||||
changeOrigin: true,
|
||||
target: env.VITE_APP_API_URL,
|
||||
rewrite: (path: string) => path.replace(new RegExp(`^${env.VITE_APP_BASE_API}`), ""),
|
||||
// 大文件上传放宽代理超时(默认 2 分钟,apks 等大文件易中断)
|
||||
timeout: 600000,
|
||||
proxyTimeout: 600000,
|
||||
target: proxyTarget,
|
||||
rewrite: (path: string) => path.slice(env.VITE_API_BASE.length),
|
||||
},
|
||||
// 静态资源(安装包图标/截图/分类图标等由后端以 /static/** 提供)需代理到后端,
|
||||
// 否则 dev server 会返回 SPA 兜底 index.html(text/html),导致图片 304/不显示。
|
||||
// 否则 dev server 会返回 SPA 兜底 index.html(text/html),导致图片不显示。
|
||||
"/static": {
|
||||
changeOrigin: true,
|
||||
target: env.VITE_APP_API_URL,
|
||||
target: proxyTarget,
|
||||
},
|
||||
// 通知中心 WebSocket,单独代理以转发握手请求
|
||||
"/api/v1/realtime/ws": {
|
||||
changeOrigin: true,
|
||||
rewriteWsOrigin: true,
|
||||
target: proxyTarget,
|
||||
ws: true,
|
||||
},
|
||||
// 统一认证登录的授权跳转与回调,路径不改写,跳转回当前开发地址
|
||||
"^/(oauth2|login/oauth2)": {
|
||||
changeOrigin: true,
|
||||
xfwd: true,
|
||||
target: proxyTarget,
|
||||
},
|
||||
},
|
||||
},
|
||||
plugins: [
|
||||
vue(),
|
||||
...(env.VITE_MOCK_DEV_SERVER === "true" ? [mockDevServerPlugin()] : []),
|
||||
...(env.VITE_MOCK_ENABLED === "true" ? [mockDevServerPlugin()] : []),
|
||||
UnoCSS(),
|
||||
// API 自动导入
|
||||
// 函数自动导入
|
||||
AutoImport({
|
||||
// 导入 Vue 函数,如:ref, reactive, toRef 等
|
||||
imports: ["vue", "@vueuse/core", "pinia", "vue-router", "vue-i18n"],
|
||||
resolvers: [
|
||||
// 导入 Element Plus函数,如:ElMessage, ElMessageBox 等
|
||||
ElementPlusResolver({ importStyle: "sass" }),
|
||||
],
|
||||
eslintrc: {
|
||||
enabled: false,
|
||||
filepath: "./.eslintrc-auto-import.json",
|
||||
globalsPropValue: true,
|
||||
},
|
||||
// Element Plus 函数按需导入
|
||||
resolvers: [ElementPlusResolver({ importStyle: "sass" })],
|
||||
vueTemplate: true,
|
||||
// 导入函数类型声明文件路径 (false:关闭自动生成)
|
||||
// 默认不生成类型声明,需要时改用下面的 dts 路径
|
||||
dts: false,
|
||||
// dts: "types/auto-imports.d.ts",
|
||||
}),
|
||||
// 组件自动导入
|
||||
Components({
|
||||
resolvers: [
|
||||
// 导入 Element Plus 组件
|
||||
// Element Plus 组件按需导入
|
||||
ElementPlusResolver({ importStyle: "sass" }),
|
||||
],
|
||||
// 指定自定义组件位置(默认:src/components)
|
||||
// 全局组件与页面内组件目录
|
||||
dirs: ["src/components", "src/**/components"],
|
||||
// 导入组件类型声明文件路径 (false:关闭自动生成)
|
||||
// 默认不生成类型声明,需要时改用下面的 dts 路径
|
||||
dts: false,
|
||||
//dts: "types/components.d.ts",
|
||||
// dts: "types/components.d.ts",
|
||||
}),
|
||||
// 生成版本号文件
|
||||
{
|
||||
name: "dist-version",
|
||||
closeBundle() {
|
||||
const distDir = resolve(__dirname, "dist");
|
||||
if (!existsSync(distDir)) {
|
||||
mkdirSync(distDir, { recursive: true });
|
||||
}
|
||||
writeFileSync(
|
||||
join(distDir, "version.json"),
|
||||
JSON.stringify({ version: __APP_INFO__.buildTimestamp })
|
||||
);
|
||||
},
|
||||
},
|
||||
] as PluginOption[],
|
||||
distVersionPlugin,
|
||||
],
|
||||
// 预加载项目必需的依赖
|
||||
optimizeDeps: {
|
||||
include: [
|
||||
@@ -133,89 +123,14 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
|
||||
"vxe-table",
|
||||
"path-browserify",
|
||||
"lodash-es",
|
||||
"dompurify",
|
||||
"@element-plus/icons-vue",
|
||||
"element-plus/es",
|
||||
"element-plus/es/locale/lang/en",
|
||||
"element-plus/es/locale/lang/zh-cn",
|
||||
// Element Plus 组件样式预构建:按 src 实际用到的组件清单硬编码,首启即预加载,
|
||||
// 避免首次使用某组件时触发依赖重优化导致页面刷新
|
||||
...[
|
||||
"alert",
|
||||
"avatar",
|
||||
"backtop",
|
||||
"badge",
|
||||
"base",
|
||||
"breadcrumb",
|
||||
"breadcrumb-item",
|
||||
"button",
|
||||
"card",
|
||||
"cascader",
|
||||
"checkbox",
|
||||
"checkbox-group",
|
||||
"checkbox-button",
|
||||
"col",
|
||||
"color-picker",
|
||||
"config-provider",
|
||||
"collapse-transition",
|
||||
"date-picker",
|
||||
"descriptions",
|
||||
"descriptions-item",
|
||||
"dialog",
|
||||
"divider",
|
||||
"drawer",
|
||||
"dropdown",
|
||||
"dropdown-item",
|
||||
"dropdown-menu",
|
||||
"empty",
|
||||
"form",
|
||||
"form-item",
|
||||
"icon",
|
||||
"image",
|
||||
"image-viewer",
|
||||
"input",
|
||||
"input-number",
|
||||
"input-tag",
|
||||
"link",
|
||||
"loading",
|
||||
"menu",
|
||||
"menu-item",
|
||||
"message",
|
||||
"message-box",
|
||||
"notification",
|
||||
"option",
|
||||
"pagination",
|
||||
"popover",
|
||||
"progress",
|
||||
"radio",
|
||||
"radio-button",
|
||||
"radio-group",
|
||||
"row",
|
||||
"scrollbar",
|
||||
"select",
|
||||
"skeleton",
|
||||
"skeleton-item",
|
||||
"space",
|
||||
"step",
|
||||
"steps",
|
||||
"sub-menu",
|
||||
"switch",
|
||||
"tab-pane",
|
||||
"table",
|
||||
"table-column",
|
||||
"tabs",
|
||||
"tag",
|
||||
"text",
|
||||
"time-picker",
|
||||
"time-select",
|
||||
"timeline",
|
||||
"timeline-item",
|
||||
"tooltip",
|
||||
"tree",
|
||||
"tree-select",
|
||||
"upload",
|
||||
"watermark",
|
||||
].map((c) => `element-plus/es/components/${c}/style/index`),
|
||||
// 流程设计器与预览器为路由懒加载,bpmn-js 体积大,首启预构建避免进入页面时重优化刷新
|
||||
// Element Plus 组件样式:按组件目录枚举,新增组件时不会在运行期补优化并刷新页面
|
||||
...getElementPlusStyleDeps(),
|
||||
// 流程设计器与预览器为路由懒加载,首启预构建,避免进入页面时重优化刷新
|
||||
"bpmn-js/lib/Modeler",
|
||||
"bpmn-js/lib/NavigatedViewer",
|
||||
"bpmn-js/lib/util/ModelUtil",
|
||||
@@ -223,37 +138,49 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
|
||||
},
|
||||
// 构建配置(Vite 8 使用 Rolldown + Oxc)
|
||||
build: {
|
||||
chunkSizeWarningLimit: 1200, // chunk 大小警告阈值
|
||||
// 单个 chunk 告警阈值(kB),取略高于最大 vendor 包的值
|
||||
chunkSizeWarningLimit: 1200,
|
||||
// 跳过 gzip 体积统计,加快构建
|
||||
reportCompressedSize: false,
|
||||
cssMinify: "lightningcss", // Vite 8 默认使用 Lightning CSS 压缩
|
||||
// minify 默认使用 'oxc',压缩速度比 terser 快 30-90 倍
|
||||
// CSS 压缩默认 Lightning CSS、JS 压缩默认 Oxc,无需显式配置
|
||||
rolldownOptions: {
|
||||
checks: {
|
||||
pluginTimings: false,
|
||||
},
|
||||
output: {
|
||||
// 用于从入口点创建的块的打包输出格式
|
||||
entryFileNames: "js/[name].[hash].js",
|
||||
// 用于命名代码拆分时创建的共享块的输出命名
|
||||
chunkFileNames: "js/[name].[hash].js",
|
||||
// 用于输出静态资源的命名
|
||||
// 产物按 assets/、css/、img/、fonts/、media/ 分类输出;资源目录避开 nginx 已占用的 /js/ 子路径
|
||||
entryFileNames: "assets/[name].[hash].js",
|
||||
chunkFileNames: "assets/[name].[hash].js",
|
||||
assetFileNames: (assetInfo) => {
|
||||
const assetName = assetInfo.names[0];
|
||||
if (!assetName) return "assets/[name].[hash][extname]";
|
||||
|
||||
if (!assetName) {
|
||||
return "assets/[name].[hash][extname]";
|
||||
}
|
||||
|
||||
const info = assetName.split(".");
|
||||
let extType = info[info.length - 1];
|
||||
if (/\.(mp4|webm|ogg|mp3|wav|flac|aac)(\?.*)?$/i.test(assetName)) {
|
||||
extType = "media";
|
||||
} else if (/\.(png|jpe?g|gif|svg)(\?.*)?$/.test(assetName)) {
|
||||
extType = "img";
|
||||
} else if (/\.(woff2?|eot|ttf|otf)(\?.*)?$/i.test(assetName)) {
|
||||
extType = "fonts";
|
||||
}
|
||||
return `${extType}/[name].[hash].[ext]`;
|
||||
const ext = assetName.split(".").pop()?.split("?")[0] ?? "";
|
||||
if (/^(mp4|webm|ogg|mp3|wav|flac|aac)$/i.test(ext)) return `media/[name].[hash].[ext]`;
|
||||
if (/^(png|jpe?g|gif|svg|webp|avif)$/i.test(ext)) return `img/[name].[hash].[ext]`;
|
||||
if (/^(woff2?|eot|ttf|otf)$/i.test(ext)) return `fonts/[name].[hash].[ext]`;
|
||||
return `${ext}/[name].[hash].[ext]`;
|
||||
},
|
||||
codeSplitting: {
|
||||
groups: [
|
||||
// 框架核心,每个页面都依赖
|
||||
{
|
||||
name: "vendor-vue",
|
||||
test: /node_modules[\\/](vue|@vue|vue-router|pinia|vue-i18n|@vueuse)[\\/]/,
|
||||
},
|
||||
// 图表:大屏与报表页共用
|
||||
{
|
||||
name: "vendor-echarts",
|
||||
test: /node_modules[\\/](echarts|zrender)[\\/]/,
|
||||
},
|
||||
// vxe 表格体系
|
||||
{
|
||||
name: "vendor-table",
|
||||
test: /node_modules[\\/](vxe-table|vxe-pc-ui|xe-utils|@vxe-ui)[\\/]/,
|
||||
},
|
||||
// 流程设计器:仅工作流页面加载
|
||||
{
|
||||
name: "vendor-bpmn",
|
||||
test: /node_modules[\\/](bpmn-js|diagram-js|bpmn-moddle|moddle|moddle-xml)[\\/]/,
|
||||
},
|
||||
],
|
||||
},
|
||||
},
|
||||
},
|
||||
@@ -263,3 +190,28 @@ export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
|
||||
},
|
||||
};
|
||||
});
|
||||
|
||||
// 按组件目录枚举 Element Plus 样式入口,避免手写清单漏项后运行期补优化并刷新页面
|
||||
function getElementPlusStyleDeps(): string[] {
|
||||
const componentsDir = resolve(import.meta.dirname, "node_modules/element-plus/es/components");
|
||||
if (!existsSync(componentsDir)) return [];
|
||||
return readdirSync(componentsDir, { withFileTypes: true })
|
||||
.filter(
|
||||
(entry) =>
|
||||
entry.isDirectory() && existsSync(resolve(componentsDir, entry.name, "style/index.mjs")),
|
||||
)
|
||||
.map((entry) => `element-plus/es/components/${entry.name}/style/index`);
|
||||
}
|
||||
|
||||
// 生成 version.json,供前端检测版本更新
|
||||
const distVersionPlugin: Plugin = {
|
||||
name: "dist-version",
|
||||
apply: "build",
|
||||
generateBundle() {
|
||||
this.emitFile({
|
||||
type: "asset",
|
||||
fileName: "version.json",
|
||||
source: JSON.stringify({ version: __APP_INFO__.buildTimestamp }),
|
||||
});
|
||||
},
|
||||
};
|
||||
Reference in new issue
Block a user