-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
125 lines (124 loc) · 3.69 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
import { defineConfig, loadEnv } from "vite";
import vue from "@vitejs/plugin-vue";
import path from "path";
import vueJsx from "@vitejs/plugin-vue-jsx";
import usePluginImport from "vite-plugin-importer";
import ViteComponents from "unplugin-vue-components/vite";
import {
AntDesignVueResolver,
ElementPlusResolver,
NaiveUiResolver,
} from "unplugin-vue-components/resolvers";
import { generateModifyVars } from "./build/style/generateModifyVars";
// import { LayuiVueResolver } from "@layui/layui-vue";
export default defineConfig(({ command, mode, ssrBuild }) => {
// 可以根据不同环境自定义配置
const IS_PROD = mode === "production";
const { APP_HTTP_URL, APP_HTTP_PORT, APP_API_HTTP, APP_DIST_DIR } = loadEnv(
mode,
process.cwd(),
""
);
return {
// base: "/dist/",
plugins: [
vue(),
vueJsx(),
// ElementPlus({
// // options
// }),
ViteComponents({
dirs: ["./", "./components", "src/components"],
directoryAsNamespace: true,
resolvers: [
AntDesignVueResolver({
resolveIcons: true,
}),
ElementPlusResolver({
importStyle: "css",
}),
NaiveUiResolver(),
// LayuiVueResolver(),
],
// include: [/@layui/],
// extensions: ['vue'],
// include: [/\.vue$/, /\.vue\?vue/,/[\\/]node_modules[\\/]/],
}),
//tsx用
usePluginImport({
libraryName: "ant-design-vue",
libraryDirectory: "es",
style: "css",
}),
],
resolve: {
// 配置别名,注意:需要在tsconfig配置中同步
alias: [
{
find: "@",
replacement: path.resolve(__dirname, "src"),
},
],
},
// 开发者相关的服务配置
server: {
host: APP_HTTP_URL, //调试网址
port: Number(APP_HTTP_PORT), // 调试端口
open: true, // 是否在运行时自动打开浏览器
cros: true, //跨域设置
// 代理配置
proxy: {
"^/api": {
target: APP_API_HTTP,
changeOrigin: true,
rewrite: path => path.replace(/^\/api/, ""),
},
},
},
// 编译配置
esbuild: {
// 生产环境删除 console、debugger 语句
drop: IS_PROD ? ["debugger", "console"] : [],
},
// 打包构建时的配置
build: {
sourcemap: !IS_PROD, // 非生产环境生成 sourcemap
outDir: APP_DIST_DIR,
// assetsDir: APP_DIST_DIR+'static/img/', // 指定生成静态资源的存放路径
// Rollup 打包配置
rollupOptions: {
// external: ['vue', 'element-plus'], // 确保外部化处理那些你不想打包进库的依赖
// output: {
// globals: {
// vue: 'Vue', // 在 UMD 构建模式下为这些外部化的依赖提供一个全局变量
// 'element-plus': 'elementPlus',
// },
// },
brotliSize: false, // 不统计
target: "esnext",
minify: "esbuild", // 混淆器,terser构建后文件体积更小
plugins: [
// visualizer({ open: true, gzipSize: true })
],
},
chunkSizeWarningLimit: 2000,
cssCodeSplit: true, //css 拆分
assetsInlineLimit: 5000, //小于该值 图片将打包成Base64
minify: false, //是否禁用最小化混淆,esbuild打包速度最快,'terser'打包体积最小。
terserOptions: {
compress: {
drop_console: true,
drop_debugger: true,
},
},
},
css: {
preprocessorOptions: {
less: {
modifyVars: generateModifyVars(),
javascriptEnabled: true,
},
},
},
};
});