-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvite.config.ts
47 lines (43 loc) · 1.48 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
import { fileURLToPath, URL } from 'node:url';
import { defineConfig, loadEnv } from 'vite';
import type { ConfigEnv } from 'vite';
import { createProxy } from './build/vite/proxy';
import { wrapperEnv } from './build/utils';
import { createVitePlugins } from './build/vite/plugin';
import { createBuild } from './build/vite/build';
const target = 'http://XXX';
// https://vitejs.dev/config/
export default defineConfig(({ command, mode }: ConfigEnv) => {
const root = process.cwd(); // 当前工作目录
const isBuild = command === 'build'; // 是否是构建 serve
const env = loadEnv(mode, root); // 加载env环境
// The boolean type read by loadEnv is a string. This function can be converted to boolean type
const viteEnv = wrapperEnv(env);
console.log('viteEnv', viteEnv);
console.log('\x1B[33m%s\x1b[0m', '正在运行的环境:', viteEnv.VITE_ENV);
return {
base: isBuild ? './' : '/',
server: {
host: true
// proxy: createProxy(viteEnv, target)
},
plugins: [...createVitePlugins(viteEnv, isBuild)],
resolve: {
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
css: {
preprocessorOptions: {
scss: {
charset: false, // 避免出现: build时的 @charset 必须在第一行的警告
additionalData: `
@import "@/styles/mixin.scss";
@import "@/styles/variables.scss";
`
}
}
},
build: createBuild(viteEnv)
};
});