From 52257f061d95cf4a3b5a11e4a52c48774a6042be Mon Sep 17 00:00:00 2001
From: vben <anncwb@126.com>
Date: 星期二, 30 十一月 2021 01:01:19 +0800
Subject: [PATCH] refactor(tree): Refactor tree to support antv3.0

---
 vite.config.ts |   57 ++++++++++++++++++++++++++++++++-------------------------
 1 files changed, 32 insertions(+), 25 deletions(-)

diff --git a/vite.config.ts b/vite.config.ts
index 99c4e8c..3b64495 100644
--- a/vite.config.ts
+++ b/vite.config.ts
@@ -1,17 +1,23 @@
 import type { UserConfig, ConfigEnv } from 'vite';
-
+import pkg from './package.json';
+import dayjs from 'dayjs';
 import { loadEnv } from 'vite';
 import { resolve } from 'path';
-
-import { generateModifyVars } from './build/config/themeConfig';
+import { generateModifyVars } from './build/generate/generateModifyVars';
 import { createProxy } from './build/vite/proxy';
 import { wrapperEnv } from './build/utils';
 import { createVitePlugins } from './build/vite/plugin';
 import { OUTPUT_DIR } from './build/constant';
 
 function pathResolve(dir: string) {
-  return resolve(__dirname, '.', dir);
+  return resolve(process.cwd(), '.', dir);
 }
+
+const { dependencies, devDependencies, name, version } = pkg;
+const __APP_INFO__ = {
+  pkg: { dependencies, devDependencies, name, version },
+  lastBuildTime: dayjs().format('YYYY-MM-DD HH:mm:ss'),
+};
 
 export default ({ command, mode }: ConfigEnv): UserConfig => {
   const root = process.cwd();
@@ -21,7 +27,7 @@
   // The boolean type read by loadEnv is a string. This function can be converted to boolean type
   const viteEnv = wrapperEnv(env);
 
-  const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY, VITE_DROP_CONSOLE, VITE_LEGACY } = viteEnv;
+  const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY, VITE_DROP_CONSOLE } = viteEnv;
 
   const isBuild = command === 'build';
 
@@ -31,29 +37,31 @@
     resolve: {
       alias: [
         {
-          // /@/xxxx  =>  src/xxx
-          find: /^\/@\//,
+          find: 'vue-i18n',
+          replacement: 'vue-i18n/dist/vue-i18n.cjs.js',
+        },
+        // /@/xxxx => src/xxxx
+        {
+          find: /\/@\//,
           replacement: pathResolve('src') + '/',
         },
+        // /#/xxxx => types/xxxx
         {
-          // /@/xxxx  =>  src/xxx
-          find: /^\/#\//,
+          find: /\/#\//,
           replacement: pathResolve('types') + '/',
         },
       ],
     },
     server: {
+      // Listening on all local IPs
+      host: true,
       port: VITE_PORT,
       // Load proxy configuration from .env
       proxy: createProxy(VITE_PROXY),
-      hmr: {
-        overlay: true,
-      },
     },
-
     build: {
+      target: 'es2015',
       outDir: OUTPUT_DIR,
-      polyfillDynamicImport: VITE_LEGACY,
       terserOptions: {
         compress: {
           keep_infinity: true,
@@ -63,24 +71,19 @@
       },
       // Turning off brotliSize display can slightly reduce packaging time
       brotliSize: false,
-      chunkSizeWarningLimit: 1200,
+      chunkSizeWarningLimit: 2000,
     },
     define: {
       // setting vue-i18-next
       // Suppress warning
-      __VUE_I18N_LEGACY_API__: false,
-      __VUE_I18N_FULL_INSTALL__: false,
       __INTLIFY_PROD_DEVTOOLS__: false,
+      __APP_INFO__: JSON.stringify(__APP_INFO__),
     },
+
     css: {
       preprocessorOptions: {
         less: {
-          modifyVars: {
-            // Used for global import to avoid the need to import each style file separately
-            // reference:  Avoid repeated references
-            hack: `true; @import (reference) "${resolve('src/design/config.less')}";`,
-            ...generateModifyVars(),
-          },
+          modifyVars: generateModifyVars(),
           javascriptEnabled: true,
         },
       },
@@ -91,8 +94,12 @@
 
     optimizeDeps: {
       // @iconify/iconify: The dependency is dynamically and virtually loaded by @purge-icons/generated, so it needs to be specified explicitly
-      include: ['@iconify/iconify'],
-      exclude: ['vue-demi'],
+      include: [
+        '@vue/shared',
+        '@iconify/iconify',
+        'ant-design-vue/es/locale/zh_CN',
+        'ant-design-vue/es/locale/en_US',
+      ],
     },
   };
 };

--
Gitblit v1.8.0