-
Notifications
You must be signed in to change notification settings - Fork 0
/
vite.config.ts
102 lines (99 loc) · 3.3 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
import { defineConfig, loadEnv, UserConfigExport, ConfigEnv } from "vite";
import react from "@vitejs/plugin-react";
import { resolve } from "path";
import { viteBuildInfo } from "./build/info";
import { createStyleImportPlugin, AntdResolve } from "vite-plugin-style-import";
import vitePluginImp from "vite-plugin-imp";
const root: string = process.cwd();
// 查找路径
const pathResolve = (dir: string): string => {
return resolve(__dirname, ".", dir);
};
// 别名
const alias: Record<string, string> = {
"@": pathResolve("src"),
};
// https://vitejs.dev/config/
export default defineConfig(({ mode }) => {
const { VITE_PUBLIC_PATH, VITE_PORT, VITE_DROP_CONSOLE } = loadEnv(
mode,
root,
""
);
return {
base: VITE_PUBLIC_PATH,
root,
plugins: [
react(),
viteBuildInfo(),
// createStyleImportPlugin({
// resolves: [AntdResolve()],
// }),
vitePluginImp({
libList: [
{
libName: "antd",
style: (name) => `antd/es/${name}/style`,
},
],
}),
],
css: {
// css预处理器
preprocessorOptions: {
scss: {
// 引入 base.scss 这样就可以在全局中使用 base.scss中预定义的变量了
// 给导入的路径最后加上 ;
additionalData: '@import "@/styles/theme/base.scss";',
},
},
},
resolve: {
alias,
},
clearScreen: false,
esbuild: {
pure: VITE_DROP_CONSOLE ? ["console.log", "debugger"] : [],
},
server: {
host: "0.0.0.0",
https: false,
port: VITE_PORT,
open: true,
// 本地跨域代理 https://cn.vitejs.dev/config/server-options.html#server-proxy
proxy: {
// 带选项写法:http://localhost:5173/api/bar -> http://jsonplaceholder.typicode.com/bar
"/api": {
target: "http://47.108.65.133:8098",
// target: "http://localhost:8098/",
changeOrigin: true,
rewrite: (path) => path.replace(/^\/api/, ""),
},
},
hmr: true,
},
build: {
outDir: "duxin-design",
lib: {
entry: resolve(__dirname, "./src/entry.ts"), //指定组件编译入口文件
name: "duxin-design",
fileName: "duxin-design",
formats: [`esm`, `es`, `umd`],
},
sourcemap: false,
// 消除打包大小超过500kb警告
chunkSizeWarningLimit: 4000,
// rollupOptions: {
// input: {
// index: pathResolve("index.html"),
// },
// // 静态资源分类打包
// output: {
// chunkFileNames: "static/js/[name]-[hash].js",
// entryFileNames: "static/js/[name]-[hash].js",
// assetFileNames: "static/[ext]/[name]-[hash].[ext]",
// },
// },
},
};
});