-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
98 lines (82 loc) · 2.5 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, ConfigEnv, UserConfig, PluginOption } from "vite";
import { createHtmlPlugin } from "vite-plugin-html";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
import { visualizer } from "rollup-plugin-visualizer";
import { compression, buildConfig } from "./config/vite/construct";
import VueSetupExtend from "vite-plugin-vue-setup-extend";
import eslintPlugin from "vite-plugin-eslint";
import { Plugin } from "vue";
// import AutoImport from "unplugin-auto-import/vite";
// import Components from "unplugin-vue-components/vite";
// import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
const env = loadEnv(mode, process.cwd()); //环境变量
// * 打包去除 console.log && debugger
const { VITE_CLEAR_CONSOLE, VITE_CLEAR_DEBUGGER } = env
const pure_console = VITE_CLEAR_CONSOLE === 'true' ? 'console.log' : ''
const pure_debugger = VITE_CLEAR_DEBUGGER === 'true' ? 'debugger' : ''
const isDev = env.NODE_ENV === "development";
const isProd = env.NODE_ENV === "production";
return {
base: "./",
resolve: {
alias: {
"@": resolve(__dirname, "./src"),
// "vue-i18n": "vue-i18n/dist/vue-i18n.cjs.js"
}
},
css: {
preprocessorOptions: {
// scss: {
// additionalData: `@import "@/styles/var.scss";`
// }
}
},
server: {
// 服务器主机名,如果允许外部访问,可设置为 "0.0.0.0"
host: "0.0.0.0",
port: 8123,
open: false,
cors: true,
// 跨域代理配置
},
plugins: [
vue(),
// * 替换index.html内容
createHtmlPlugin({
inject: {
data: {
title: env.VITE_APP_TITLE//替换 <%- title %>内容
}
}
}),
// * 使用 svg 图标
createSvgIconsPlugin({
iconDirs: [resolve(process.cwd(), "src/assets/icons")],
symbolId: "icon-[dir]-[name]"
}),
// * EsLint 报错信息显示在浏览器界面上
// eslintPlugin({
// cache:false,
// exclude:['./node_modules/**']
// }),
// * name 可以写在 script 标签上
VueSetupExtend(),
compression,//压缩
// * 是否生成包预览(分析依赖包大小,方便做优化处理)
visualizer({
open: true,
gzipSize: true,
brotliSize: true
}) as PluginOption,
],
esbuild: { pure: [pure_console, pure_debugger].filter(e => e) },
build: {
outDir: env.VITE_BUILD_OUTPUT,
minify: "esbuild",
...buildConfig
}
};
});