-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
135 lines (133 loc) · 4.33 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
import { type ConfigEnv, type UserConfigExport, loadEnv } from "vite";
import path from "path";
import vue from "@vitejs/plugin-vue";
import vueJsx from "@vitejs/plugin-vue-jsx";
import { createSvgIconsPlugin } from "vite-plugin-svg-icons";
import svgLoader from "vite-svg-loader";
import tailwindcss from "tailwindcss";
import autoprefixer from "autoprefixer";
import AutoImport from "unplugin-auto-import/vite";
import Components from "unplugin-vue-components/vite";
import { ElementPlusResolver } from "unplugin-vue-components/resolvers";
import { visualizer } from "rollup-plugin-visualizer";
// https://vitejs.dev/config/
// eslint-disable-next-line no-control-regex
const INVALID_CHAR_REGEX = /[\u0000-\u001F"#$&*+,:;<=>?[\]^`{|}\u007F]/g;
const DRIVE_LETTER_REGEX = /^[a-z]:/i;
export default (configEnv: ConfigEnv): UserConfigExport => {
// @ts-ignore
const viteEnv = loadEnv(configEnv.mode, process.cwd()) as ImportMetaEnv;
const { VITE_PUBLIC_PATH } = viteEnv;
return {
base: VITE_PUBLIC_PATH,
plugins: [
vue(),
vueJsx(),
/** 将 SVG 静态图转化为 Vue 组件 */
svgLoader({ defaultImport: "url" }),
/** SVG */
createSvgIconsPlugin({
iconDirs: [path.resolve(process.cwd(), "pages/admin/icons/svg")],
symbolId: "icon-[dir]-[name]"
}),
visualizer({
emitFile: false,
filename: "analysis-chart.html", // 分析图生成的文件名
open: true // 如果存在本地服务端口,将在打包后自动展示
}),
AutoImport({
resolvers: [ElementPlusResolver()]
}),
Components({
resolvers: [ElementPlusResolver()]
})
],
optimizeDeps: {
include: ["vue", "vue-router", "pinia", "axios", "@vueuse/core", "vue-i18n"]
},
css: {
postcss: {
plugins: [tailwindcss, autoprefixer]
}
},
server: {
hmr: true, // 开启热更新
/** 是否开启 HTTPS */
https: false,
/** 设置 host: true 才可以使用 Network 的形式,以 IP 访问项目 */
host: true, // host: "0.0.0.0"
/** 端口号 */
port: 3333,
/** 是否自动打开浏览器 */
open: false,
/** 跨域设置允许 */
cors: true,
/** 端口被占用时,是否直接退出 */
strictPort: false,
/** 接口代理 */
proxy: {
// "/api/v1": {
// target: "https://www.fastmock.site/mock/761e2dda2b8890ab86c928a74e8f6538",
// ws: true,
// /** 是否允许跨域 */
// changeOrigin: true
// },
"/gxjh-api": {
target: "http://10.80.101.61:8000/dynamic_home",
ws: true,
changeOrigin: true,
rewrite: (path) => path.replace(/^\/gxjh-api/, "")
}
// "/gxjh-api": {
// target: "http://120.27.223.237/gxjh-api",
// ws: true,
// changeOrigin: true,
// rewrite: (path) => path.replace(/^\/gxjh-api/, "")
// }
}
},
resolve: {
alias: {
// "@": path.resolve(__dirname, "./src"),
"@tailwind": path.resolve(__dirname, "node_modules/tailwind"),
"@": path.resolve(__dirname, "./pages/previews"),
"@admin": path.resolve(__dirname, "./pages/admin")
},
extensions: [".mjs", ".js", ".ts", ".jsx", ".tsx", ".json", ".vue"]
},
build: {
chunkSizeWarningLimit: 1500,
rollupOptions: {
input: {
index: path.resolve(__dirname, "index.html"),
admin: path.resolve(__dirname, "admin.html")
},
output: {
// manualChunks(id) {
// if (id.includes("node_modules")) {
// return id
// .toString()
// .split("node_modules/")[1]
// .split("/")[0]
// .toString();
// }
// },
sanitizeFileName(name) {
const match = DRIVE_LETTER_REGEX.exec(name);
const driveLetter = match ? match[0] : "";
return driveLetter + name.slice(driveLetter.length).replace(INVALID_CHAR_REGEX, "");
}
}
}
},
/** 混淆器 */
esbuild: {
/** 打包时移除 console.log */
pure: ["console.log"],
/** 打包时移除 debugger */
drop: ["debugger"],
/** 打包时移除所有注释 */
legalComments: "none"
}
};
};