-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.ts
More file actions
142 lines (133 loc) · 3.79 KB
/
vite.config.ts
File metadata and controls
142 lines (133 loc) · 3.79 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
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
/// <reference types="vitest/config" />
import process from "node:process";
import { cleanupSVG, isEmptyColor, parseColors, runSVGO, SVG } from "@iconify/tools";
import tailwindcss from "@tailwindcss/vite";
import react from "@vitejs/plugin-react";
import { codeInspectorPlugin } from "code-inspector-plugin";
import dayjs from "dayjs";
import { FileSystemIconLoader } from "unplugin-icons/loaders";
import Icons from "unplugin-icons/vite";
import { defineConfig } from "vite";
import { checker } from "vite-plugin-checker";
import { vitePluginFakeServer } from "vite-plugin-fake-server";
import svgrPlugin from "vite-plugin-svgr";
import { author, dependencies, devDependencies, license, name, version } from "./package.json";
const __APP_INFO__ = {
pkg: { dependencies, devDependencies, name, version, license, author },
lastBuildTime: dayjs(new Date()).format("YYYY-MM-DD HH:mm:ss"),
};
const isDev = process.env.NODE_ENV === "development";
// https://vitejs.dev/config/
export default defineConfig({
base: isDev ? "/" : "/react-antd-admin/",
plugins: [
tailwindcss(),
react(),
vitePluginFakeServer({
basename: "/api",
enableProd: true,
timeout: 1000,
}),
// https://github.com/pd4d10/vite-plugin-svgr#options
svgrPlugin({
// https://react-svgr.com/docs/options/
svgrOptions: {
plugins: ["@svgr/plugin-svgo", "@svgr/plugin-jsx"],
svgoConfig: {
floatPrecision: 2,
},
},
}),
checker({
typescript: true,
terminal: false,
enableBuild: false,
}),
/**
* 点击页面 DOM 打开 IDE 并将光标自动定位到源代码位置
*
* macOS 默认组合键 Option + Shift
* Windows 默认组合键 Alt + Shift
* 在 Web 页面上按住组合键时,移动鼠标即会在 DOM 上出现遮罩层并显示相关信息,鼠标点击一下,将自动打开 IDE 并将光标定位到元素对应的代码位置
* 更多用法看 https://inspector.fe-dev.cn/guide/start.html
*/
codeInspectorPlugin({
bundler: "vite",
// hideConsole: true,
}),
/**
* 按需加载图标
* https://github.com/antfu/unplugin-icons
*/
Icons({
customCollections: {
svg: FileSystemIconLoader("./src/icons/svg"),
},
/**
* @see https://iconify.design/docs/articles/cleaning-up-icons/#parsing-one-monotone-icon
* Cleaning up icons
* Set default color to currentColor
* Set default width and height to 1em
*/
transform: (svg, collection) => {
if (collection === "svg") {
const svgObject = new SVG(svg);
cleanupSVG(svgObject);
runSVGO(svgObject);
parseColors(svgObject, {
defaultColor: "currentColor",
callback: (attr, colorStr, color) => {
if (!color) {
// Color cannot be parsed!
throw new Error(`Invalid color: "${colorStr}" in attribute ${attr}`);
}
if (isEmptyColor(color)) {
// Color is empty: 'none' or 'transparent'. Return as is
return color;
}
// If color is not empty, return it
return color;
},
});
return svgObject.toString({ height: "1em", width: "1em" }); ;
}
return svg;
},
compiler: "jsx",
jsx: "react",
scale: 1,
}),
],
test: {
globals: true,
environment: "happy-dom",
setupFiles: ["./src/setupTests.ts"],
},
server: {
port: 3333,
// https://vitejs.dev/config/server-options#server-proxy
proxy: {
// "/api": {
// target: "http://191.255.255.123:8888",
// changeOrigin: true,
// rewrite: path => isDev ? path.replace(/^\/api/, "") : path,
// },
},
},
define: {
__APP_INFO__: JSON.stringify(__APP_INFO__),
},
build: {
outDir: "build",
sourcemap: false,
rollupOptions: {
output: {
manualChunks: {
react: ["react", "react-dom", "react-router"],
antd: ["antd", "@ant-design/icons"],
faker: ["@faker-js/faker"],
},
},
},
},
});