-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathvite.config.ts
67 lines (66 loc) · 1.62 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
66
67
import { UserConfig, ConfigEnv, loadEnv } from 'vite';
import vue from '@vitejs/plugin-vue';
import { resolve } from 'path';
import { proxy } from './build/proxy';
import Components from 'unplugin-vue-components/vite';
import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers';
const root: string = process.cwd();
// https://vitejs.dev/config/
export default ({ command, mode }: ConfigEnv): UserConfig => {
// 获取当前环境的配置
const {
VITE_PORT,
VITE_PUBLIC_PATH,
VITE_OUT_DIR,
VITE_ASSET_DIR,
VITE_BASEURL,
}: any = loadEnv(mode, root);
return {
base: VITE_PUBLIC_PATH,
plugins: [
vue(),
Components({
resolvers: [
AntDesignVueResolver({
importStyle: false, // css in js
}),
],
}),
],
// 解析相关 【别名】
resolve: {
alias: [
{
find: '@', //字符串|正则
replacement: resolve(__dirname, 'src'),
},
],
},
// css相关
css: {
// 引入全局scss |less 指定传递给 CSS 预处理器的选项。
preprocessorOptions: {
scss: {
additionalData: '@import "@/styles/mixin.scss";',
},
less: {
javascriptEnabled: true,
},
},
},
// 服务相关
server: {
https: false,
port: VITE_PORT,
proxy: proxy(VITE_BASEURL),
},
// .构建相关【打包相关】
build: {
outDir: VITE_OUT_DIR,
assetsDir: VITE_ASSET_DIR,
sourcemap: false,
// 消除打包大小超过500kb警告
chunkSizeWarningLimit: 4000,
},
};
};