-
Notifications
You must be signed in to change notification settings - Fork 23
/
vite.config.ts
98 lines (93 loc) · 2.52 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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import { resolve, join } from "path";
import { readdirSync } from "fs";
import viteCompression from "vite-plugin-compression";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
const project_pages = {};
const entryPath = resolve(__dirname, "./src/modules");
const entrys = readdirSync(entryPath).reduce((obj, dirname) => {
obj[dirname] = join(entryPath, dirname);
return obj;
}, {});
Object.keys(entrys).forEach(pageName => {
project_pages[pageName] = resolve(__dirname, `src/modules/${pageName}/index.html`);
});
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
let pages = {};
const env = loadEnv(mode, process.cwd());
const isDev = mode === "development";
if (isDev) {
pages = { ...project_pages };
} else {
if (env.VITE_APP_MODEL) {
pages[env.VITE_APP_MODEL] = project_pages[env.VITE_APP_MODEL];
} else {
pages = { ...project_pages };
}
}
return {
root: env.VITE_APP_ROOTPATH,
plugins: [
vue(),
createSvgIconsPlugin({
// 指定需要缓存的图标文件夹
iconDirs: [
resolve(process.cwd(), "src/assets/icons"),
resolve(process.cwd(), "src/modules/main/assets/icons"),
],
// 指定symbolId格式
symbolId: "icon-[dir]-[name]",
}),
// gzip压缩 生产环境生成 .gz 文件
viteCompression({
verbose: true,
disable: false,
threshold: 10240,
algorithm: "gzip",
ext: ".gz",
}),
],
resolve: {
extensions: [".js", ".ts", ".vue", ".json"],
alias: {
"@": resolve(__dirname, "src"),
"@main": resolve(__dirname, "src/modules/main"),
"@minor": resolve(__dirname, "src/modules/minor"),
},
},
css: {
preprocessorOptions: {
less: {
additionalData: '@import "@/assets/style/main.less";',
},
},
},
server: {
host: "0.0.0.0",
port: 5238,
open: false,
https: false,
proxy: {
"/cnhis": {
target: "https://mock.mengxuegu.com/mock/63856c7c9433403d6c06899c", // easymock
changeOrigin: true,
rewrite: path => path.replace(/^\/cnhis/, ""),
},
},
},
build: {
rollupOptions: {
input: pages,
output: { dir: "./dist" },
},
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true,
},
},
},
};
});