2021-12-08 23:34:23 +08:00
|
|
|
import { defineConfig } from "vite";
|
2022-08-06 02:35:11 +08:00
|
|
|
import path from "path";
|
2022-03-30 12:36:39 +08:00
|
|
|
import svgr from "vite-plugin-svgr";
|
2021-12-08 23:34:23 +08:00
|
|
|
import react from "@vitejs/plugin-react";
|
2024-05-29 09:39:26 +08:00
|
|
|
import legacy from "@vitejs/plugin-legacy";
|
2024-11-18 01:21:00 +08:00
|
|
|
import monacoEditorPlugin, {
|
|
|
|
|
type IMonacoEditorOpts,
|
|
|
|
|
} from "vite-plugin-monaco-editor";
|
|
|
|
|
const monacoEditorPluginDefault = (monacoEditorPlugin as any).default as (
|
2024-11-24 00:14:46 +08:00
|
|
|
options: IMonacoEditorOpts,
|
2024-11-18 01:21:00 +08:00
|
|
|
) => any;
|
2021-12-08 23:34:23 +08:00
|
|
|
|
|
|
|
|
export default defineConfig({
|
|
|
|
|
root: "src",
|
2022-09-02 01:35:06 +08:00
|
|
|
server: { port: 3000 },
|
2022-07-05 00:52:22 +08:00
|
|
|
plugins: [
|
|
|
|
|
svgr(),
|
|
|
|
|
react(),
|
2024-05-29 09:39:26 +08:00
|
|
|
legacy({
|
2024-06-05 09:04:08 +08:00
|
|
|
renderLegacyChunks: false,
|
|
|
|
|
modernTargets: ["edge>=109", "safari>=13"],
|
2024-05-29 09:39:26 +08:00
|
|
|
modernPolyfills: true,
|
|
|
|
|
additionalModernPolyfills: [
|
2024-06-05 00:12:06 +08:00
|
|
|
"core-js/modules/es.object.has-own.js",
|
2024-06-05 09:04:08 +08:00
|
|
|
"core-js/modules/web.structured-clone.js",
|
2024-05-30 20:27:12 +08:00
|
|
|
path.resolve("./src/polyfills/matchMedia.js"),
|
2024-05-29 09:39:26 +08:00
|
|
|
path.resolve("./src/polyfills/WeakRef.js"),
|
|
|
|
|
path.resolve("./src/polyfills/RegExp.js"),
|
|
|
|
|
],
|
|
|
|
|
}),
|
2024-11-18 01:21:00 +08:00
|
|
|
monacoEditorPluginDefault({
|
2024-05-13 22:58:25 +08:00
|
|
|
languageWorkers: ["editorWorkerService", "typescript", "css"],
|
2024-04-17 21:19:37 +08:00
|
|
|
customWorkers: [
|
|
|
|
|
{
|
|
|
|
|
label: "yaml",
|
|
|
|
|
entry: "monaco-yaml/yaml.worker",
|
|
|
|
|
},
|
|
|
|
|
],
|
2025-03-27 05:09:36 +08:00
|
|
|
globalAPI: false,
|
2024-04-17 21:19:37 +08:00
|
|
|
}),
|
2022-07-05 00:52:22 +08:00
|
|
|
],
|
2021-12-12 00:39:28 +08:00
|
|
|
build: {
|
2025-03-14 00:57:17 +08:00
|
|
|
outDir: "../dist",
|
2021-12-22 01:15:04 +08:00
|
|
|
emptyOutDir: true,
|
2025-03-27 05:09:36 +08:00
|
|
|
target: "esnext",
|
|
|
|
|
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";
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2021-12-12 00:39:28 +08:00
|
|
|
},
|
2022-08-06 02:35:11 +08:00
|
|
|
resolve: {
|
|
|
|
|
alias: {
|
|
|
|
|
"@": path.resolve("./src"),
|
|
|
|
|
"@root": path.resolve("."),
|
|
|
|
|
},
|
|
|
|
|
},
|
2024-11-18 01:07:16 +08:00
|
|
|
css: {
|
|
|
|
|
preprocessorOptions: {
|
|
|
|
|
scss: {
|
|
|
|
|
api: "modern-compiler",
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
2022-08-16 01:53:40 +08:00
|
|
|
define: {
|
2023-01-14 12:07:31 +08:00
|
|
|
OS_PLATFORM: `"${process.platform}"`,
|
2022-08-16 01:53:40 +08:00
|
|
|
},
|
2021-12-08 23:34:23 +08:00
|
|
|
});
|