-
Notifications
You must be signed in to change notification settings - Fork 4
/
vite.config.ts
57 lines (51 loc) · 1.54 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
import { defineConfig, loadEnv } from 'vite';
import { fileURLToPath } from 'node:url';
import dayjs from 'dayjs';
import { getEnvConfig } from './.env.config';
import {
createViteBuild,
createVitePlugins,
createViteProxy,
} from './build/vite';
// crypto-js 默认使用4.1.1,最新版打包以后报错
// unocss默认使用0.58.5,最新版改成ejs了,需要手动改回0.58.5
// https://vitejs.dev/config/
export default defineConfig((configEnv) => {
const viteEnv = loadEnv(configEnv.mode, process.cwd()) as ImportMetaEnv;
const { VITE_HTTP_PROXY = false, VITE_BASE_URL, VITE_PORT } = viteEnv;
const envConfig = getEnvConfig(viteEnv);
const buildTime = dayjs().format('YYYY-MM-DD HH:mm:ss');
return {
base: VITE_BASE_URL,
resolve: {
alias: {
'~': fileURLToPath(new URL('./', import.meta.url)),
'@': fileURLToPath(new URL('./src', import.meta.url)),
},
},
plugins: createVitePlugins(viteEnv, configEnv.command === 'build'),
define: {
BUILD_TIME: JSON.stringify(buildTime),
},
server: {
host: '0.0.0.0',
port: VITE_PORT || 3200,
open: true,
proxy: createViteProxy(VITE_HTTP_PROXY, envConfig),
},
optimizeDeps: {
exclude: ['crypto-js'],
},
build: createViteBuild(viteEnv),
css: {
preprocessorOptions: {
// less: {
// modifyVars: {
// hack: `true; @import (reference) "${resolve('src/styles/config.less')}";`,
// },
// javascriptEnabled: true,
// },
},
},
};
});