瀏覽代碼

[Pref 0000] 依赖项优化,打包体积削减

houzekong 3 天之前
父節點
當前提交
1900bc9571

+ 4 - 0
build/vite/plugin/index.ts

@@ -16,6 +16,7 @@ import { configVisualizerConfig } from './visualizer';
 import { configThemePlugin } from './theme';
 import { configSvgIconsPlugin } from './svgSprite';
 import { configServerPlugin } from './serveStatic';
+import { configImageminPlugin } from './imagemin';
 // //预编译加载插件(不支持vite3作废)
 // import OptimizationPersist from 'vite-plugin-optimize-persist';
 import topLevelAwait from 'vite-plugin-top-level-await';
@@ -72,6 +73,9 @@ export function createVitePlugins(viteEnv: ViteEnv, isBuild: boolean) {
   if (isBuild) {
     // rollup-plugin-gzip
     vitePlugins.push(configCompressPlugin(VITE_BUILD_COMPRESS, VITE_BUILD_COMPRESS_DELETE_ORIGIN_FILE));
+
+    // vite-plugin-imagemin: 图片压缩 (仅生产环境)
+    vitePlugins.push(configImageminPlugin());
   }
 
   // //vite-plugin-theme【预编译加载插件,解决vite首次打开界面加载慢问题】

+ 1 - 18
package.json

@@ -30,7 +30,6 @@
     "@logicflow/core": "^1.2.12",
     "@logicflow/extension": "^1.2.13",
     "@qiaoqiaoyun/drag-free": "^1.1.4",
-    "@types/markdown-it": "^14.1.2",
     "@vue-office/docx": "^1.6.3",
     "@vue-office/excel": "^1.7.14",
     "@vue-office/pdf": "^2.0.10",
@@ -54,40 +53,29 @@
     "dom-align": "^1.12.4",
     "echarts": "^6.0.0",
     "emoji-mart-vue-fast": "^15.0.0",
-    "enquire.js": "^2.1.6",
     "gsap": "^3.11.3",
     "highlight.js": "^11.11.1",
     "hls.js": "^1.6.15",
     "html2canvas": "^1.4.1",
-    "intro.js": "^7.2.0",
     "katex": "^0.16.25",
     "lodash-es": "^4.17.21",
-    "lodash.get": "^4.4.2",
-    "markdown-it": "^14.3.0",
     "marked": "^17.0.1",
-    "md5": "^2.3.0",
     "mky-svg": "^1.0.2",
-    "moment": "^2.29.4",
     "nprogress": "^0.2.0",
     "path-to-regexp": "^6.2.1",
     "pinia": "2.1.6",
     "plyr": "^3.7.8",
-    "pnpm": "^10.32.1",
     "print-js": "^1.6.0",
     "qiankun": "^2.10.16",
     "qrcode": "^1.5.3",
-    "qrcodejs2": "0.0.2",
     "qs": "^6.11.2",
     "resize-observer-polyfill": "^1.5.1",
-    "showdown": "^2.1.0",
     "sortablejs": "^1.15.0",
     "three": "^0.162.0",
     "three.path": "^1.0.1",
     "tinymce": "^5.10.3",
     "vditor": "^3.9.5",
     "vue": "^3.2.0",
-    "vue-cropper": "^0.6.2",
-    "vue-cropperjs": "^5.0.0",
     "vue-draggable-resizable": "^3.0.0",
     "vue-i18n": "9.2.2",
     "vue-infinite-scroll": "^2.0.2",
@@ -117,7 +105,6 @@
     "@types/crypto-js": "^4.1.1",
     "@types/fs-extra": "^11.0.1",
     "@types/inquirer": "^9.0.3",
-    "@types/intro.js": "^5.1.1",
     "@types/jest": "^29.5.4",
     "@types/lodash-es": "^4.17.8",
     "@types/mockjs": "^1.0.7",
@@ -125,16 +112,12 @@
     "@types/nprogress": "^0.2.0",
     "@types/qrcode": "^1.5.1",
     "@types/qs": "^6.9.7",
-    "@types/showdown": "^2.0.1",
     "@types/sortablejs": "^1.15.1",
     "@types/three": "^0.162.0",
     "@typescript-eslint/eslint-plugin": "^6.4.1",
     "@typescript-eslint/parser": "^6.5.0",
-    "@vitejs/plugin-legacy": "^2.0.0",
     "@vitejs/plugin-vue": "^4.3.3",
     "@vitejs/plugin-vue-jsx": "^3.0.2",
-    "@vue-office/docx": "^1.6.3",
-    "@vue-office/pdf": "^2.0.10",
     "@vue/compiler-sfc": "^3.3.4",
     "@vue/test-utils": "^2.4.1",
     "autoprefixer": "^10.4.16",
@@ -182,10 +165,10 @@
     "typescript": "^4.9.5",
     "unocss": "^0.55.3",
     "video.js": "^8.23.4",
-    "videojs-flvjs-es6": "^1.0.1",
     "vite": "^4.4.9",
     "vite-plugin-compression": "^0.5.1",
     "vite-plugin-html": "^3.2.0",
+    "vite-plugin-imagemin": "^0.6.1",
     "vite-plugin-mkcert": "^1.16.0",
     "vite-plugin-mock": "^2.9.6",
     "vite-plugin-purge-icons": "^0.9.2",

文件差異過大導致無法顯示
+ 575 - 150
pnpm-lock.yaml


+ 1 - 1
src/components/AIChat/MiniChat.vue

@@ -476,7 +476,7 @@
   const parseMarkdownWithLatex = (mdStr) => {
     if (!mdStr) return '';
     try {
-      let html = marked(mdStr); // Markdown → HTML
+      let html = marked.parse(mdStr); // Markdown → HTML
       html = renderLatexInHtml(html); // 替换公式
       return html;
     } catch (error) {

+ 2 - 4
src/components/Markdown/src/MarkdownViewer.vue

@@ -4,15 +4,13 @@
 
 <script lang="ts" setup>
   import { computed } from 'vue';
-  import showdown from 'showdown';
+  import { marked } from 'marked';
 
-  const converter = new showdown.Converter();
-  converter.setOption('tables', true);
   const props = defineProps({
     value: { type: String },
     class: { type: String },
   });
-  const getHtmlData = computed(() => converter.makeHtml(props.value || ''));
+  const getHtmlData = computed(() => marked.parse(props.value || '', { gfm: true }));
 </script>
 
 <style scoped>

+ 4 - 2
src/utils/encryption/signMd5Utils.js

@@ -1,4 +1,4 @@
-import md5 from 'md5';
+import md5 from 'crypto-js/md5';
 import { fromEnvCharCodes } from '/@/utils/env';
 
 // 签名密钥串(前后端要一致,正式发布请自行修改,通过环境变量配置)
@@ -35,7 +35,9 @@ export default class signMd5Utils {
     let jsonObj = this.mergeObject(urlParams, requestParams);
     let requestBody = this.sortAsc(jsonObj);
     delete requestBody._t;
-    return md5(JSON.stringify(requestBody) + signatureSecret).toUpperCase();
+    return md5(JSON.stringify(requestBody) + signatureSecret)
+      .toString()
+      .toUpperCase();
   }
 
   /**

+ 1 - 1
src/views/monitor/trace/trace.data.ts

@@ -1,6 +1,6 @@
 import { BasicColumn } from '/@/components/Table';
 import dayjs from 'dayjs';
-import _get from 'lodash.get';
+import { get as _get } from 'lodash-es';
 import { h } from 'vue';
 import { Tag } from 'ant-design-vue';
 

+ 4 - 4
src/views/vent/monitorManager/alarmMonitor/common/predictionCurve.vue

@@ -10,7 +10,7 @@
 </template>
 
 <script lang="ts" setup>
-  import moment from 'moment';
+  import dayjs from 'dayjs';
   import { ref, watch } from 'vue';
   import EchartLine3 from './echartLine3.vue';
 
@@ -87,14 +87,14 @@
         // indexMark为0表示还没插入过数据,初始化数据
         if (chartConfig.value.indexMark === 0) {
           const arr = new Array(20).fill(0);
-          const startFrom = moment(el.time);
+          const startFrom = dayjs(el.time);
           chartConfig.value = {
             // label: el.label,
             label: '',
             indexMark: 1,
             x: arr.map(() => {
               const str = startFrom.format('HH:mm:ss');
-              startFrom.add(props.timeout || 3000);
+              startFrom.add(props.timeout || 3000, 'millisecond');
               return str;
             }),
             y1: arr.map(() => {
@@ -123,7 +123,7 @@
             val.y4.shift();
             val.indexMark = 19;
           }
-          val.x[val.indexMark] = moment(el.time).format('HH:mm:ss');
+          val.x[val.indexMark] = dayjs(el.time).format('HH:mm:ss');
           val.y1[val.indexMark] = el.data[0];
           val.y2[val.indexMark] = el.data[1];
           val.y3[val.indexMark] = el.data[2];

+ 2 - 1
src/views/ventAI/dataPicker/components/DataPickerModal.vue

@@ -124,7 +124,8 @@
 
   const renderedText = computed(() => {
     if (!props.streamingText) return '';
-    return marked.parse(props.streamingText.replace(/<br\s*\/?>/gi, '  \n')) as string;
+    const processed = props.streamingText.replace(/<br\s*\/?>/gi, '  \n');
+    return marked.parse(processed);
   });
 </script>
 

+ 6 - 10
vite.config.ts

@@ -54,7 +54,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
           find: /@\//,
           replacement: pathResolve('src') + '/',
         },
-        // /#/xxxx => types/xxxx
+        // #/xxxx => types/xxxx
         {
           find: /#\//,
           replacement: pathResolve('types') + '/',
@@ -92,6 +92,8 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
             // 将 Lodash 库的代码单独打包 (lodash 已废弃,仅保留 lodash-es)
             'lodash-es-vendor': ['lodash-es'],
             'html2canvas-vendor': ['html2canvas'],
+            'd3-vendor': ['d3'],
+            'datav-vendor': ['@kjgl77/datav-vue3'],
             // vue vue-router合并打包
             vue: ['vue', 'vue-router'],
             'cron-parser-vendor': ['cron-parser'],
@@ -109,8 +111,8 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
 
       // 关闭brotliSize显示可以稍微减少打包时间
       reportCompressedSize: false,
-      // 提高超大静态资源警告大小
-      chunkSizeWarningLimit: 2500,
+      // 超大静态资源警告阈值
+      chunkSizeWarningLimit: 500,
     },
     esbuild: {
       //清除全局的console.log和debug
@@ -138,10 +140,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
       esbuildOptions: {
         target: 'es2020',
       },
-      exclude: [
-        //升级vite4后,需要排除online依赖
-        '@jeecg/online',
-      ],
+      exclude: [],
       // 提前预加载依赖,缩短首屏访问时间
       include: [
         '@vue/runtime-core',
@@ -193,9 +192,7 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
         'echarts/core',
         'echarts/renderers',
         'emoji-mart-vue-fast/src',
-        'intro.js',
         'lodash-es',
-        'md5',
         'nprogress',
         'path-to-regexp',
         'pinia',
@@ -203,7 +200,6 @@ export default ({ command, mode }: ConfigEnv): UserConfig => {
         'qrcode',
         'qs',
         'resize-observer-polyfill',
-        'showdown',
         'sortablejs',
         'tinymce/icons/default/icons',
         'tinymce/plugins/advlist',

部分文件因文件數量過多而無法顯示