-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
109 lines (108 loc) · 2.86 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
99
100
101
102
103
104
105
106
107
108
109
import { defineConfig, loadEnv, ConfigEnv, UserConfig, type PluginOption } from "vite";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
import path from "node:path";
import { wrapperEnv } from "./src/utils/getEnv";
import { visualizer } from "rollup-plugin-visualizer";
import viteCompression from "vite-plugin-compression";
import eslintPlugin from "vite-plugin-eslint";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
import VueI18nPlugin from "@intlify/unplugin-vue-i18n/vite";
import postcssPresetEnv from "postcss-preset-env";
import UnoCSS from "unocss/vite";
import { viteServeInfoPlugin } from "./vite/plugin/vite-serve-info";
import { cdn } from "./vite/plugin/cdn";
import VueDevTools from "vite-plugin-vue-devtools";
import { name, version } from "./vite/plugin/app-info";
export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
const env = loadEnv(mode, process.cwd());
const viteEnv = wrapperEnv(env);
return {
base: "./",
resolve: {
alias: {
"@": path.resolve(__dirname, "./src")
}
},
server: {
open: viteEnv.VITE_OPEN,
host: true,
port: viteEnv.VITE_PORT,
proxy: {
"/api": {
target: "http://117.72.43.202:8099", // 本地node路径
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, "")
}
}
},
plugins: [
vue(),
vueJsx(),
VueI18nPlugin({
include: [path.resolve(__dirname, "./src/language")]
}),
// * 是否生成包预览(分析依赖包大小,方便做优化处理)
viteEnv.VITE_REPORT &&
(visualizer({
emitFile: true,
filename: "stats.html"
}) as PluginOption),
// * gzip压缩
viteCompression({
verbose: true,
disable: false,
threshold: 10240,
algorithm: "gzip",
ext: ".gz",
deleteOriginFile: false
}),
// * EsLint 报错信息显示在浏览器界面上
eslintPlugin(),
// * 使用 svg 图标
createSvgIconsPlugin({
iconDirs: [path.resolve(__dirname, "./src/assets/icons")],
symbolId: "icon-[dir]-[name]"
}),
viteEnv.VITE_CDN && cdn,
UnoCSS(),
viteServeInfoPlugin(),
mode === "development" && VueDevTools()
],
css: {
// * postcss后处理器
postcss: {
// * postcssPresetEnv css语法降级
plugins: [postcssPresetEnv()]
}
},
esbuild: {
pure: ["console.log", "debugger"]
},
build: {
outDir: "dist",
rollupOptions: {
output: {
compact: true,
// * 分包策略
manualChunks: (id: string) => {
if (id.includes("node_modules")) return "vendor";
},
// * 静态资源分类包装
chunkFileNames: "assets/js/[name]-[hash].js",
entryFileNames: "assets/js/[name]-[hash].js",
assetFileNames: "assets/[ext]/[name]-[hash].[ext]"
}
}
},
define: {
__APP_INFO__: JSON.stringify({
pkg: {
name,
version
},
lastBuildTime: new Date().getTime()
})
}
};
});