-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathvite.config.ts
More file actions
86 lines (82 loc) · 2.23 KB
/
vite.config.ts
File metadata and controls
86 lines (82 loc) · 2.23 KB
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
import { UserConfigExport, ConfigEnv, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
import vueJsx from "@vitejs/plugin-vue-jsx";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
const setAlias = (alias: [string, string][]) =>
alias.map((v) => {
return { find: v[0], replacement: path.resolve(__dirname, v[1]) };
});
interface ImportMetaEnv {
VITE_USER_NODE_ENV: string;
}
export default ({ mode }: ConfigEnv): UserConfigExport => {
const root = process.cwd();
const env = loadEnv(mode, root) as unknown as ImportMetaEnv;
return {
root,
resolve: {
alias: setAlias([["@", "src"]]),
},
plugins: [
vue(),
vueJsx({
babelPlugins: [
["@babel/plugin-proposal-decorators", { legacy: true }],
["@babel/plugin-proposal-class-properties", { loose: true }],
],
}),
AutoImport({
resolvers: [
ElementPlusResolver({
importStyle: false,
}),
],
}),
Components({
include: ["./src/**/*.{js,jsx,ts,tsx,vue,html}"],
resolvers: [
ElementPlusResolver({
importStyle: false,
}),
],
}),
createSvgIconsPlugin({
// 指定需要缓存的图标文件夹
iconDirs: [path.resolve(process.cwd(), "src/assets/icons")],
// 指定symbolId格式
symbolId: "icon-[dir]-[name]",
}),
],
base: env.VITE_USER_NODE_ENV === "development" ? "/" : "./",
server: {
port: 8888,
open: true,
},
css: {
preprocessorOptions: {
scss: {
// 自定义 element 主题样式
additionalData: `@use "@/styles/index.scss" as *;`,
},
},
postcss: {
plugins: [require("tailwindcss"), require("autoprefixer")],
},
},
build: {
manifest: true,
chunkSizeWarningLimit: 700,
rollupOptions: {
output: {
manualChunks: {
"element-plus": ["element-plus"],
},
},
},
},
};
};