forked from clash-verge-rev/clash-verge-rev
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvite.config.mts
More file actions
146 lines (139 loc) · 4.33 KB
/
vite.config.mts
File metadata and controls
146 lines (139 loc) · 4.33 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
143
144
145
146
import { defineConfig } from "vite";
import path from "path";
import svgr from "vite-plugin-svgr";
import react from "@vitejs/plugin-react";
import legacy from "@vitejs/plugin-legacy";
import monacoEditorPlugin, {
type IMonacoEditorOpts,
} from "vite-plugin-monaco-editor";
const monacoEditorPluginDefault = (monacoEditorPlugin as any).default as (
options: IMonacoEditorOpts,
) => any;
export default defineConfig({
root: "src",
server: { port: 3000 },
plugins: [
svgr(),
react(),
legacy({
renderLegacyChunks: false,
modernTargets: ["edge>=109", "safari>=13"],
modernPolyfills: true,
additionalModernPolyfills: [
"core-js/modules/es.object.has-own.js",
"core-js/modules/web.structured-clone.js",
path.resolve("./src/polyfills/matchMedia.js"),
path.resolve("./src/polyfills/WeakRef.js"),
path.resolve("./src/polyfills/RegExp.js"),
],
}),
monacoEditorPluginDefault({
languageWorkers: ["editorWorkerService", "typescript", "css"],
customWorkers: [
{
label: "yaml",
entry: "monaco-yaml/yaml.worker",
},
],
globalAPI: false,
}),
],
build: {
outDir: "../dist",
emptyOutDir: true,
target: "es2020",
minify: "terser",
chunkSizeWarningLimit: 4000,
reportCompressedSize: false,
sourcemap: false,
cssCodeSplit: true,
cssMinify: true,
rollupOptions: {
treeshake: {
preset: "recommended",
moduleSideEffects: (id) => !/\.css$/.test(id),
tryCatchDeoptimization: false,
},
output: {
compact: true,
experimentalMinChunkSize: 30000,
dynamicImportInCjs: true,
manualChunks(id) {
if (id.includes("node_modules")) {
// Monaco Editor should be a separate chunk
if (id.includes("monaco-editor")) return "monaco-editor";
// React-related libraries (react, react-dom, react-router-dom, etc.)
if (
id.includes("react") ||
id.includes("react-dom") ||
id.includes("react-router-dom") ||
id.includes("react-transition-group") ||
id.includes("react-error-boundary") ||
id.includes("react-hook-form") ||
id.includes("react-markdown") ||
id.includes("react-virtuoso")
) {
return "react";
}
// Utilities chunk: group commonly used utility libraries
if (
id.includes("axios") ||
id.includes("lodash-es") ||
id.includes("dayjs") ||
id.includes("js-base64") ||
id.includes("js-yaml") ||
id.includes("cli-color") ||
id.includes("nanoid")
) {
return "utils";
}
// Tauri-related plugins: grouping together Tauri plugins
if (
id.includes("@tauri-apps/api") ||
id.includes("@tauri-apps/plugin-clipboard-manager") ||
id.includes("@tauri-apps/plugin-dialog") ||
id.includes("@tauri-apps/plugin-fs") ||
id.includes("@tauri-apps/plugin-global-shortcut") ||
id.includes("@tauri-apps/plugin-notification") ||
id.includes("@tauri-apps/plugin-process") ||
id.includes("@tauri-apps/plugin-shell") ||
id.includes("@tauri-apps/plugin-updater")
) {
return "tauri-plugins";
}
// Material UI libraries (grouped together)
if (
id.includes("@mui/material") ||
id.includes("@mui/icons-material") ||
id.includes("@mui/lab") ||
id.includes("@mui/x-data-grid")
) {
return "mui";
}
// Small vendor packages
const pkg = id.match(/node_modules\/([^\/]+)/)?.[1];
if (pkg && pkg.length < 8) return "small-vendors";
// Large vendor packages
return "large-vendor";
}
},
},
},
},
resolve: {
alias: {
"@": path.resolve("./src"),
"@root": path.resolve("."),
},
},
css: {
preprocessorOptions: {
scss: {
api: "modern-compiler",
},
},
},
define: {
OS_PLATFORM: `"${process.platform}"`,
},
});