|
@@ -1,41 +1,126 @@
|
|
|
-import fs from 'node:fs'
|
|
|
|
|
-import path from 'node:path'
|
|
|
|
|
-import process from 'node:process'
|
|
|
|
|
-import dayjs from 'dayjs'
|
|
|
|
|
-import { defineConfig, loadEnv } from 'vite'
|
|
|
|
|
-import pkg from './package.json'
|
|
|
|
|
-import createVitePlugins from './vite/plugins'
|
|
|
|
|
|
|
+import fs from "node:fs";
|
|
|
|
|
+import path from "node:path";
|
|
|
|
|
+import process from "node:process";
|
|
|
|
|
+import dayjs from "dayjs";
|
|
|
|
|
+import { defineConfig, loadEnv } from "vite";
|
|
|
|
|
+import pkg from "./package.json";
|
|
|
|
|
+import createVitePlugins from "./vite/plugins";
|
|
|
|
|
|
|
|
// https://vitejs.dev/config/
|
|
// https://vitejs.dev/config/
|
|
|
export default defineConfig(({ mode, command }) => {
|
|
export default defineConfig(({ mode, command }) => {
|
|
|
- const env = loadEnv(mode, process.cwd())
|
|
|
|
|
|
|
+ const env = loadEnv(mode, process.cwd());
|
|
|
// 全局 scss 资源
|
|
// 全局 scss 资源
|
|
|
- const scssResources: string[] = []
|
|
|
|
|
- fs.readdirSync('src/assets/styles/resources').forEach((dirname) => {
|
|
|
|
|
|
|
+ const scssResources: string[] = [];
|
|
|
|
|
+ fs.readdirSync("src/assets/styles/resources").forEach((dirname) => {
|
|
|
if (fs.statSync(`src/assets/styles/resources/${dirname}`).isFile()) {
|
|
if (fs.statSync(`src/assets/styles/resources/${dirname}`).isFile()) {
|
|
|
- scssResources.push(`@use "/src/assets/styles/resources/${dirname}" as *;`)
|
|
|
|
|
|
|
+ scssResources.push(
|
|
|
|
|
+ `@use "/src/assets/styles/resources/${dirname}" as *;`
|
|
|
|
|
+ );
|
|
|
}
|
|
}
|
|
|
- })
|
|
|
|
|
|
|
+ });
|
|
|
return {
|
|
return {
|
|
|
// 静态资源基础路径
|
|
// 静态资源基础路径
|
|
|
- base: env.VITE_BASE_PATH || '/',
|
|
|
|
|
|
|
+ base: env.VITE_BASE_PATH || "/",
|
|
|
// 开发服务器选项 https://cn.vitejs.dev/config/server-options
|
|
// 开发服务器选项 https://cn.vitejs.dev/config/server-options
|
|
|
server: {
|
|
server: {
|
|
|
open: true,
|
|
open: true,
|
|
|
- host: '0.0.0.0', // 监听所有接口
|
|
|
|
|
|
|
+ host: "0.0.0.0", // 监听所有接口
|
|
|
port: 9000,
|
|
port: 9000,
|
|
|
proxy: {
|
|
proxy: {
|
|
|
- '/proxy': {
|
|
|
|
|
|
|
+ "/proxy": {
|
|
|
target: env.VITE_APP_API_BASEURL,
|
|
target: env.VITE_APP_API_BASEURL,
|
|
|
- changeOrigin: command === 'serve' && env.VITE_OPEN_PROXY === 'true',
|
|
|
|
|
- rewrite: path => path.replace(/\/proxy/, ''),
|
|
|
|
|
|
|
+ changeOrigin: command === "serve" && env.VITE_OPEN_PROXY === "true",
|
|
|
|
|
+ rewrite: (path) => path.replace(/\/proxy/, ""),
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
// 构建选项 https://cn.vitejs.dev/config/build-options
|
|
// 构建选项 https://cn.vitejs.dev/config/build-options
|
|
|
build: {
|
|
build: {
|
|
|
- outDir: mode === 'production' ? 'dist' : `dist-${mode}`,
|
|
|
|
|
- sourcemap: env.VITE_BUILD_SOURCEMAP === 'true',
|
|
|
|
|
|
|
+ outDir: mode === "production" ? "dist" : `dist-${mode}`,
|
|
|
|
|
+ sourcemap: env.VITE_BUILD_SOURCEMAP === "true",
|
|
|
|
|
+ minify: "terser",
|
|
|
|
|
+ terserOptions: {
|
|
|
|
|
+ compress: {
|
|
|
|
|
+ drop_console: true,
|
|
|
|
|
+ drop_debugger: true,
|
|
|
|
|
+ pure_funcs: ["console.log", "console.table"], // 可选
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ rollupOptions: {
|
|
|
|
|
+ output: {
|
|
|
|
|
+ manualChunks(id) {
|
|
|
|
|
+ // Vue 核心生态:稳定、基础、几乎不变
|
|
|
|
|
+ if (
|
|
|
|
|
+ id.includes("node_modules/vue") ||
|
|
|
|
|
+ id.includes("node_modules/pinia") ||
|
|
|
|
|
+ id.includes("node_modules/vue-router") ||
|
|
|
|
|
+ id.includes("node_modules/@vue/")
|
|
|
|
|
+ ) {
|
|
|
|
|
+ return "vendor-vue";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // Element Plus 及其关联 UI 组件
|
|
|
|
|
+ if (
|
|
|
|
|
+ id.includes("node_modules/element-plus") ||
|
|
|
|
|
+ id.includes("node_modules/@element-plus") ||
|
|
|
|
|
+ id.includes("node_modules/floating-vue") ||
|
|
|
|
|
+ id.includes("node_modules/@headlessui") ||
|
|
|
|
|
+ id.includes("node_modules/overlayscrollbars") ||
|
|
|
|
|
+ id.includes("node_modules/vue-m-message")
|
|
|
|
|
+ ) {
|
|
|
|
|
+ return "vendor-ui";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // VueUse 全家桶
|
|
|
|
|
+ if (id.includes("node_modules/@vueuse/")) {
|
|
|
|
|
+ return "vendor-vueuse";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // ECharts(独立大体积,按需更新)
|
|
|
|
|
+ if (
|
|
|
|
|
+ id.includes("node_modules/echarts") ||
|
|
|
|
|
+ id.includes("node_modules/zrender")
|
|
|
|
|
+ ) {
|
|
|
|
|
+ return "vendor-echarts";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 办公文档处理相关(一般只有特定页面用,可异步加载)
|
|
|
|
|
+ if (
|
|
|
|
|
+ id.includes("node_modules/@vue-office") ||
|
|
|
|
|
+ id.includes("node_modules/jszip") ||
|
|
|
|
|
+ id.includes("node_modules/html2canvas") ||
|
|
|
|
|
+ id.includes("node_modules/file-saver")
|
|
|
|
|
+ ) {
|
|
|
|
|
+ return "vendor-office";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 通用工具库:使用频繁、体积适中、变更少
|
|
|
|
|
+ if (
|
|
|
|
|
+ id.includes("node_modules/axios") ||
|
|
|
|
|
+ id.includes("node_modules/lodash-es") ||
|
|
|
|
|
+ id.includes("node_modules/dayjs") ||
|
|
|
|
|
+ id.includes("node_modules/qs") ||
|
|
|
|
|
+ id.includes("node_modules/mitt") ||
|
|
|
|
|
+ id.includes("node_modules/decimal.js") ||
|
|
|
|
|
+ id.includes("node_modules/defu") ||
|
|
|
|
|
+ id.includes("node_modules/scule") ||
|
|
|
|
|
+ id.includes("node_modules/path-to-regexp") ||
|
|
|
|
|
+ id.includes("node_modules/chinese-days") ||
|
|
|
|
|
+ id.includes("node_modules/js-pinyin") ||
|
|
|
|
|
+ id.includes("node_modules/hotkeys-js") ||
|
|
|
|
|
+ id.includes("node_modules/nprogress") ||
|
|
|
|
|
+ id.includes("node_modules/mockjs")
|
|
|
|
|
+ ) {
|
|
|
|
|
+ return "vendor-utils";
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 其它第三方库(较小的、非核心)
|
|
|
|
|
+ if (id.includes("node_modules")) {
|
|
|
|
|
+ return "vendor-misc";
|
|
|
|
|
+ }
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
|
|
+ },
|
|
|
},
|
|
},
|
|
|
define: {
|
|
define: {
|
|
|
__SYSTEM_INFO__: JSON.stringify({
|
|
__SYSTEM_INFO__: JSON.stringify({
|
|
@@ -44,26 +129,26 @@ export default defineConfig(({ mode, command }) => {
|
|
|
dependencies: pkg.dependencies,
|
|
dependencies: pkg.dependencies,
|
|
|
devDependencies: pkg.devDependencies,
|
|
devDependencies: pkg.devDependencies,
|
|
|
},
|
|
},
|
|
|
- lastBuildTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
|
|
|
|
|
|
|
+ lastBuildTime: dayjs().format("YYYY-MM-DD HH:mm:ss"),
|
|
|
}),
|
|
}),
|
|
|
},
|
|
},
|
|
|
- plugins: createVitePlugins(mode, command === 'build'),
|
|
|
|
|
|
|
+ plugins: createVitePlugins(mode, command === "build"),
|
|
|
resolve: {
|
|
resolve: {
|
|
|
alias: {
|
|
alias: {
|
|
|
- '@': path.resolve(__dirname, 'src'),
|
|
|
|
|
- '#': path.resolve(__dirname, 'src/types'),
|
|
|
|
|
|
|
+ "@": path.resolve(__dirname, "src"),
|
|
|
|
|
+ "#": path.resolve(__dirname, "src/types"),
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
optimizeDeps: {
|
|
optimizeDeps: {
|
|
|
- include: ['@vue-office/docx', 'vue-demi'],
|
|
|
|
|
|
|
+ include: ["@vue-office/docx", "vue-demi"],
|
|
|
},
|
|
},
|
|
|
css: {
|
|
css: {
|
|
|
preprocessorOptions: {
|
|
preprocessorOptions: {
|
|
|
scss: {
|
|
scss: {
|
|
|
- api: 'modern-compiler',
|
|
|
|
|
- additionalData: scssResources.join(''),
|
|
|
|
|
|
|
+ api: "modern-compiler",
|
|
|
|
|
+ additionalData: scssResources.join(""),
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
},
|
|
},
|
|
|
- }
|
|
|
|
|
-})
|
|
|
|
|
|
|
+ };
|
|
|
|
|
+});
|