forked from lctoolsweb/DanhengWebTools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
65 lines (60 loc) · 1.65 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
63
64
65
import { UserConfig, ConfigEnv } from 'vite';
import path from 'path';
import { createVitePlugins } from './config/vite/plugins';
import proxy from './config/vite/proxy';
import { VITE_DROP_CONSOLE, VITE_PORT } from './config/constant';
import { generateModifyVars } from './config/themeConfig';
function resovePath(paths: string) {
return path.resolve(__dirname, paths);
}
export default async ({ command, mode }: ConfigEnv): Promise<UserConfig> => {
const isBuild = command === 'build';
console.log('Command:', command);
console.log('Mode:', mode);
const viteConfig: UserConfig = {
resolve: {
alias: {
"@": path.resolve(__dirname, './src'),
'@config': resovePath('./config'),
"@components": resovePath('./src/components'),
'@utils': resovePath('./src/utils'),
'@api': resovePath('./src/api'),
}
},
base: "./",
plugins: await createVitePlugins(isBuild),
css: {
preprocessorOptions: {
less: {
modifyVars: generateModifyVars(),
javascriptEnabled: true,
additionalData: `@import "${resovePath('src/assets/styles/base.less')}";`
},
},
},
server: {
hmr: { overlay: false },
port: VITE_PORT,
open: false,
cors: true,
host: '0.0.0.0',
proxy,
force: true
},
build: {
target: 'es2015',
terserOptions: {
compress: {
keep_infinity: true,
drop_console: VITE_DROP_CONSOLE,
},
},
rollupOptions: {
external: [],
},
chunkSizeWarningLimit: 2000,
},
};
console.log('Vite config:', viteConfig);
return viteConfig;
};