-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
62 lines (60 loc) · 1.95 KB
/
vite.config.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import type { UserConfig, ConfigEnv } from 'vite';
import { loadEnv } from 'vite';
import { wrapperEnv } from './build/utils';
import { createVitePlugins } from './build/vite/plugin';
import { createProxy } from './build/vite/proxy';
import { resolve } from 'path';
const pathResolve = (dir: string) => resolve(process.cwd(), '.', dir);
// https://vitejs.dev/config/
export default ({ command, mode }: ConfigEnv): UserConfig => {
const root = process.cwd();
const env = loadEnv(mode, root);
const viteEnv = wrapperEnv(env);
const { VITE_PORT, VITE_PUBLIC_PATH, VITE_PROXY } = viteEnv;
const isBuild = command === 'build';
return {
base: VITE_PUBLIC_PATH,
publicDir: 'public',
resolve: {
alias: [
{
find: /@\//,
replacement: `${pathResolve('src')}/`,
},
],
},
server: {
port: VITE_PORT,
https: false,
cors: true,
proxy: createProxy(VITE_PROXY),
},
esbuild: {
jsxFactory: 'h',
jsxFragment: 'Fragment',
},
css: {
preprocessorOptions: {
less: {
// color - 全局默认主题颜色; width - 默认页面最小宽度
additionalData: '@color: #ef9103;@width: 1366px;',
javascriptEnabled: true,
},
},
},
build: {
target: 'es2015',
outDir: 'dist',
assetsDir: 'doppler',
assetsInlineLimit: 4096, // 4kb
// 默认为 Terser,虽然 Terser 相对较慢,但大多数情况下构建后的文件体积更小。ESbuild 最小化混淆更快但构建后的文件相对更大。
minify: isBuild ? 'terser' : 'esbuild',
// 启用/禁用 brotli 压缩大小报告。压缩大型输出文件可能会很慢,因此禁用该功能可能会提高大型项目的构建性能
brotliSize: false,
// chunk 大小警告的限制(以 kbs 为单位)
chunkSizeWarningLimit: 2000,
},
// viteEnv, isBuild
plugins: createVitePlugins(),
};
};