vite.config.ts 2.3 KB
Newer Older
V
vben 已提交
1
import type { UserConfig, Resolver } from 'vite';
陈文彬 已提交
2 3
import { resolve } from 'path';

4 5
import { modifyVars } from './build/config/lessModifyVars';
import { createProxy } from './build/vite/proxy';
V
vben 已提交
6 7 8

import globbyTransform from './build/vite/plugin/transform/globby';
import dynamicImportTransform from './build/vite/plugin/transform/dynamic-import';
9

V
vben 已提交
10
import { loadEnv } from './build/utils';
陈文彬 已提交
11

12
import { createRollupPlugin, createVitePlugins } from './build/vite/plugin';
13 14

const pkg = require('./package.json');
陈文彬 已提交
15

16 17
const viteEnv = loadEnv();

V
vben 已提交
18
const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY, VITE_DROP_CONSOLE, VITE_DYNAMIC_IMPORT } = viteEnv;
陈文彬 已提交
19 20 21 22

function pathResolve(dir: string) {
  return resolve(__dirname, '.', dir);
}
B
bin 已提交
23

V
vben 已提交
24 25 26 27 28 29 30 31
const alias: Record<string, string> = {
  '/@/': pathResolve('src'),
};

const root: string = process.cwd();

const resolvers: Resolver[] = [];

陈文彬 已提交
32
const viteConfig: UserConfig = {
V
vben 已提交
33 34
  root,
  alias,
B
bin 已提交
35
  /**
V
vben 已提交
36
   * port
B
bin 已提交
37 38 39
   * @default '3000'
   */
  port: VITE_PORT,
V
vben 已提交
40

陈文彬 已提交
41
  /**
V
vben 已提交
42
   * Base public path when served in production.
陈文彬 已提交
43 44
   * @default '/'
   */
B
bin 已提交
45
  base: VITE_PUBLIC_PATH,
陈文彬 已提交
46 47

  /**
V
vben 已提交
48
   * Transpile target for esbuild.
V
vben 已提交
49
   * @default 'es2020'
陈文彬 已提交
50
   */
V
vben 已提交
51
  esbuildTarget: 'es2019',
V
vben 已提交
52

V
vben 已提交
53
  // terser options
V
vben 已提交
54
  terserOptions: {
V
vben 已提交
55 56 57 58
    compress: {
      drop_console: VITE_DROP_CONSOLE,
    },
  },
59 60
  define: {
    __VERSION__: pkg.version,
V
vben 已提交
61
    // setting vue-i18-next
V
vben 已提交
62 63 64 65
    // Suppress warning
    __VUE_I18N_LEGACY_API__: false,
    __VUE_I18N_FULL_INSTALL__: false,
    __INTLIFY_PROD_DEVTOOLS__: false,
66
  },
陈文彬 已提交
67 68 69 70 71 72
  cssPreprocessOptions: {
    less: {
      modifyVars: modifyVars,
      javascriptEnabled: true,
    },
  },
V
vben 已提交
73
  // The package will be recompiled using rollup, and the new package compiled into the esm module specification will be put into node_modules/.vite_opt_cache
陈文彬 已提交
74
  optimizeDeps: {
V
vben 已提交
75 76 77 78 79 80
    include: [
      'echarts/map/js/china',
      'ant-design-vue/es/locale/zh_CN',
      'ant-design-vue/es/locale/en_US',
      '@ant-design/icons-vue',
    ],
陈文彬 已提交
81
  },
V
vben 已提交
82

B
bin 已提交
83
  proxy: createProxy(VITE_PROXY),
84
  plugins: createVitePlugins(viteEnv),
陈文彬 已提交
85
  rollupInputOptions: {
86
    plugins: createRollupPlugin(),
陈文彬 已提交
87
  },
V
vben 已提交
88 89
  transforms: [
    globbyTransform({
V
vben 已提交
90 91 92
      resolvers: resolvers,
      root: root,
      alias: alias,
V
vben 已提交
93 94
      includes: [resolve('src/router'), resolve('src/locales')],
    }),
V
vben 已提交
95
    dynamicImportTransform(VITE_DYNAMIC_IMPORT),
V
vben 已提交
96
  ],
V
vben 已提交
97 98 99
};

export default viteConfig;