Vben
2021-03-31 8a14069e71d5393cfa5b758f46a1c5c001fa172b
提交 | 用户 | age
99ac30 1 import type { UserConfig, ConfigEnv } from 'vite';
2f6253 2
bd7b53 3 import { loadEnv } from 'vite';
07c18d 4 import { resolve } from 'path';
bd7b53 5
3d1681 6 import { generateModifyVars } from './build/config/themeConfig';
173d40 7 import { createProxy } from './build/vite/proxy';
a9462f 8 import { createAlias } from './build/vite/alias';
bd7b53 9 import { wrapperEnv } from './build/utils';
99ac30 10 import { createVitePlugins } from './build/vite/plugin';
759e53 11 import { OUTPUT_DIR } from './build/constant';
2f6253 12
99ac30 13 export default ({ command, mode }: ConfigEnv): UserConfig => {
07c18d 14   const root = process.cwd();
V 15
bd7b53 16   const env = loadEnv(mode, root);
07c18d 17
V 18   // The boolean type read by loadEnv is a string. This function can be converted to boolean type
bd7b53 19   const viteEnv = wrapperEnv(env);
07c18d 20
b67cf2 21   const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY, VITE_DROP_CONSOLE } = viteEnv;
99ac30 22
V 23   const isBuild = command === 'build';
24
bd7b53 25   return {
f24422 26     base: VITE_PUBLIC_PATH,
bd7b53 27     root,
993538 28     resolve: {
a9462f 29       alias: createAlias([
V 30         // /@/xxxx => src/xxxx
31         ['/@/', 'src'],
32         // /#/xxxx => types/xxxx
33         ['/#/', 'types'],
34       ]),
993538 35     },
99ac30 36     server: {
V 37       port: VITE_PORT,
07c18d 38       // Load proxy configuration from .env
99ac30 39       proxy: createProxy(VITE_PROXY),
8a1bfd 40     },
99ac30 41     build: {
e09068 42       target: 'es2015',
759e53 43       outDir: OUTPUT_DIR,
99ac30 44       terserOptions: {
V 45         compress: {
46           keep_infinity: true,
07c18d 47           // Used to delete console in production environment
99ac30 48           drop_console: VITE_DROP_CONSOLE,
V 49         },
50       },
07c18d 51       // Turning off brotliSize display can slightly reduce packaging time
1b71db 52       brotliSize: false,
3ba828 53       chunkSizeWarningLimit: 1200,
99ac30 54     },
bd7b53 55     define: {
V 56       // setting vue-i18-next
57       // Suppress warning
58       __VUE_I18N_LEGACY_API__: false,
59       __VUE_I18N_FULL_INSTALL__: false,
60       __INTLIFY_PROD_DEVTOOLS__: false,
2f6253 61     },
99ac30 62     css: {
V 63       preprocessorOptions: {
64         less: {
65           modifyVars: {
07c18d 66             // Used for global import to avoid the need to import each style file separately
3509eb 67             // reference:  Avoid repeated references
99ac30 68             hack: `true; @import (reference) "${resolve('src/design/config.less')}";`,
3d1681 69             ...generateModifyVars(),
99ac30 70           },
V 71           javascriptEnabled: true,
116a1f 72         },
bd7b53 73       },
V 74     },
75
07c18d 76     // The vite plugin used by the project. The quantity is large, so it is separately extracted and managed
V 77     plugins: createVitePlugins(viteEnv, isBuild),
8a1bfd 78
99ac30 79     optimizeDeps: {
07c18d 80       // @iconify/iconify: The dependency is dynamically and virtually loaded by @purge-icons/generated, so it needs to be specified explicitly
c8e84d 81       include: [
V 82         '@iconify/iconify',
83         'ant-design-vue/es/locale/zh_CN',
84         'moment/dist/locale/zh-cn',
85         'ant-design-vue/es/locale/en_US',
86         'moment/dist/locale/eu',
87       ],
8a1406 88       exclude: ['vue-demi'],
bd7b53 89     },
V 90   };
6f8d75 91 };