-
-
Notifications
You must be signed in to change notification settings - Fork 233
/
Copy pathvite.config.ts
63 lines (60 loc) · 1.73 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
import { fileURLToPath } from 'url';
import { ConfigEnv, defineConfig, loadEnv } from 'vite';
import { createBuild } from './build/vite/build';
import { wrapperEnv } from './build/utils';
import { createProxy } from './build/vite/proxy';
import { createVitePlugins } from './build/vite/plugin';
import autoprefixer from 'autoprefixer';
export default defineConfig(async ({ command, mode }: ConfigEnv) => {
const root = process.cwd(); // 当前工作目录
const isBuild = command === 'build'; // 是否是构建 serve
const env = loadEnv(mode, root); // 加载 env 环境
const viteEnv = wrapperEnv(env);
return {
// base: './',
resolve: {
// 设置别名
alias: {
'@': fileURLToPath(new URL('./src', import.meta.url))
}
},
build: createBuild(viteEnv),
css: {
preprocessorOptions: {
scss: {
additionalData: '@use "@/style/global.scss" as *;' // 关键
}
},
postcss: {
// ⚠️ 关键代码
plugins: [
autoprefixer({
// 自动添加前缀
overrideBrowserslist: [
'Android 4.1',
'iOS 7.1',
'Chrome > 31',
'ff > 31',
'ie >= 8',
'last 2 versions', // 所有主流浏览器最近 2 个版本
'not IE <= 11' // 排除 IE11 及以下
],
grid: true
})
]
}
},
plugins: [...(await createVitePlugins(viteEnv, isBuild))],
esbuild: {
logOverride: { 'this-is-undefined-in-esm': 'silent' }
},
server: {
port: 8888, // 启动端口
host: '0.0.0.0',
open: true,
hmr: true,
// 设置代理
proxy: createProxy()
}
};
});