-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvite.config.ts
146 lines (144 loc) · 4.66 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
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
import { defineConfig, loadEnv, ConfigEnv, UserConfig } from "vite";
import { createHtmlPlugin } from "vite-plugin-html";
import vue from "@vitejs/plugin-vue";
import { resolve } from "path";
import { wrapperEnv } from "./src/utils/getEnv";
import { visualizer } from "rollup-plugin-visualizer";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
import viteCompression from "vite-plugin-compression";
import VueSetupExtend from "vite-plugin-vue-setup-extend";
import eslintPlugin from "vite-plugin-eslint";
import vueJsx from "@vitejs/plugin-vue-jsx";
// import importToCDN from "vite-plugin-cdn-import";
import { Plugin as importToCDN } from "vite-plugin-cdn-import";
// import AutoImport from "unplugin-auto-import/vite";
// import Components from "unplugin-vue-components/vite";
// import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
// @see: https://vitejs.dev/config/
export default defineConfig(({ mode }: ConfigEnv): UserConfig => {
const env = loadEnv(mode, process.cwd());
const viteEnv = wrapperEnv(env);
return {
// base: "/",
// alias config
resolve: {
alias: {
"@": resolve(__dirname, "./src"),
"vue-i18n": "vue-i18n/dist/vue-i18n.cjs.js",
json2csv: "json2csv/dist/json2csv.umd.js"
}
},
// variables
define: {
APP_VERSION: JSON.stringify(process.env.npm_package_version)
},
// global css
css: {
preprocessorOptions: {
scss: {
additionalData: `@import "@/styles/var.scss";`
}
}
},
// server config
server: {
host: "0.0.0.0", // Server host name, if external access is allowed, it can be set to "0.0.0.0"
port: viteEnv.VITE_PORT,
open: viteEnv.VITE_OPEN,
cors: true,
// https: false,
// Agent cross -domain (Mock does not need to be configured, here is just a matter)
// 跨域代理配置
proxy: {
"/api": {
target: "https://mock.mengxuegu.com/mock/629d727e6163854a32e8307e", // easymock
// target: "https://www.fastmock.site/mock/f81e8333c1a9276214bcdbc170d9e0a0", // fastmock
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, "")
}
}
},
// plugins
plugins: [
vue(),
createHtmlPlugin({
inject: {
data: {
title: viteEnv.VITE_GLOB_APP_TITLE
}
}
}),
// * 使用 svg 图标
createSvgIconsPlugin({
iconDirs: [resolve(process.cwd(), "src/assets/icons")],
symbolId: "icon-[dir]-[name]"
}),
// * EsLint: The error information is displayed on the browser interface
// eslintPlugin(),
// * VITE can use JSX/TSX syntax
vueJsx(),
// * name can be written on the script tag
VueSetupExtend(),
// * Demand Import Element
// AutoImport({
// resolvers: [ElementPlusResolver()]
// }),
// Components({
// resolvers: [ElementPlusResolver()]
// }),
// * cdn 引入(vue、element-plus)
importToCDN({
modules: [
// The introduction of Vue on demand will lead to a problem with Vue plug -in (column: PINIA/Vuex)
// {
// name: "vue",
// var: "Vue",
// path: "https://unpkg.com/vue@next"
// },
// When using CDN to introduce Element-Plus, the development environment still needs to introduce Element-Plus in main.js.
// {
// name: "element-plus",
// var: "ElementPlus",
// path: "https://unpkg.com/element-plus",
// css: "https://unpkg.com/element-plus/dist/index.css"
// }
]
}),
// * Whether to generate a preview
// viteEnv.VITE_REPORT && visualizer(),
// * gzip compress
viteEnv.VITE_BUILD_GZIP &&
viteCompression({
verbose: true,
disable: false,
threshold: 10240,
algorithm: "gzip",
ext: ".gz"
})
],
esbuild: {
pure: viteEnv.VITE_DROP_CONSOLE ? ["console.log", "debugger"] : []
},
// build configure
build: {
outDir: "dist-ui",
// ESBUILD package is faster, but it cannot be removed
minify: "esbuild",
// minify: "terser",
// terserOptions: {
// compress: {
// drop_console: viteEnv.VITE_DROP_CONSOLE,
// drop_debugger: true
// }
// },
rollupOptions: {
output: {
// Static resource classification and packaging
chunkFileNames: "assets/js/[name]-[hash].js",
entryFileNames: "assets/js/[name]-[hash].js",
assetFileNames: "assets/[ext]/[name]-[hash].[ext]"
}
}
}
};
});