Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: update build to shrink built size (#16281)

boojack9e91adb3e7d6
diff --git a/frontend/src/components/MonacoEditor/editor.ts b/frontend/src/components/MonacoEditor/editor.ts
index 16adcd6f2b..99c0b3ec19 100644
--- a/frontend/src/components/MonacoEditor/editor.ts
+++ b/frontend/src/components/MonacoEditor/editor.ts
@@ -1,5 +1,6 @@
-import * as monaco from "monaco-editor";
+import type * as MonacoType from "monaco-editor";
import { defer } from "@/utils";
+import { loadMonacoEditor } from "./lazy-editor";
import { initializeMonacoServices } from "./services";
const state = {
@@ -23,9 +24,10 @@ const initialize = async () => {
export const createMonacoEditor = async (config: {
container: HTMLElement;
- options?: monaco.editor.IStandaloneEditorConstructionOptions;
-}): Promise<monaco.editor.IStandaloneCodeEditor> => {
+ options?: MonacoType.editor.IStandaloneEditorConstructionOptions;
+}): Promise<MonacoType.editor.IStandaloneCodeEditor> => {
await initialize();
+ const monaco = await loadMonacoEditor();
// Create monaco editor.
const editor = monaco.editor.create(config.container, {
@@ -44,9 +46,10 @@ export const createMonacoEditor = async (config: {
export const createMonacoDiffEditor = async (config: {
container: HTMLElement;
- options?: monaco.editor.IStandaloneDiffEditorConstructionOptions;
-}): Promise<monaco.editor.IStandaloneDiffEditor> => {
+ options?: MonacoType.editor.IStandaloneDiffEditorConstructionOptions;
+}): Promise<MonacoType.editor.IStandaloneDiffEditor> => {
await initialize();
+ const monaco = await loadMonacoEditor();
// Create monaco diff editor.
const editor = monaco.editor.createDiffEditor(config.container, {
@@ -64,7 +67,7 @@ export const createMonacoDiffEditor = async (config: {
};
export const defaultEditorOptions =
- (): monaco.editor.IStandaloneEditorConstructionOptions => {
+ (): MonacoType.editor.IStandaloneEditorConstructionOptions => {
return {
// Learn more: https://github.com/microsoft/monaco-editor/issues/311
renderValidationDecorations: "on",
@@ -106,7 +109,7 @@ export const defaultEditorOptions =
};
export const defaultDiffEditorOptions =
- (): monaco.editor.IStandaloneDiffEditorConstructionOptions => {
+ (): MonacoType.editor.IStandaloneDiffEditorConstructionOptions => {
return {
// Learn more: https://github.com/microsoft/monaco-editor/issues/311
enableSplitViewResizing: false,
diff --git a/frontend/src/components/MonacoEditor/lazy-editor.ts b/frontend/src/components/MonacoEditor/lazy-editor.ts
new file mode 100644
index 0000000000..ce49387409
--- /dev/null
+++ b/frontend/src/components/MonacoEditor/lazy-editor.ts
@@ -0,0 +1,27 @@
+import type * as monaco from "monaco-editor";
+import { defer } from "@/utils";
+
+// Lazy load monaco-editor to reduce initial bundle size
+let monacoModule: typeof monaco | undefined;
+const monacoLoadDefer = defer<typeof monaco>();
+
+export const loadMonacoEditor = async (): Promise<typeof monaco> => {
+ if (monacoModule) {
+ return monacoModule;
+ }
+
+ // Dynamic import of monaco-editor (will create a separate chunk)
+ monacoModule = await import("monaco-editor");
+ monacoLoadDefer.resolve(monacoModule);
+
+ return monacoModule;
+};
+
+export const getMonacoEditor = async (): Promise<typeof monaco> => {
+ return monacoLoadDefer.promise;
+};
+
+// Helper to check if monaco is already loaded
+export const isMonacoLoaded = (): boolean => {
+ return monacoModule !== undefined;
+};
diff --git a/frontend/src/components/MonacoEditor/text-model.ts b/frontend/src/components/MonacoEditor/text-model.ts
index 1be5e519f8..b97816d305 100644
--- a/frontend/src/components/MonacoEditor/text-model.ts
+++ b/frontend/src/components/MonacoEditor/text-model.ts
@@ -1,20 +1,22 @@
-import * as monaco from "monaco-editor";
+import type * as MonacoType from "monaco-editor";
import { isRef, markRaw, ref, shallowRef, unref, watch } from "vue";
import type { Language, MaybeRef } from "@/types";
import { MonacoEditorReady } from "./editor";
+import { getMonacoEditor } from "./lazy-editor";
const ready = ref(false);
MonacoEditorReady.then(() => (ready.value = true));
// Store TextModel uniq by filename.
-const TextModelMapByFilename = new Map<string, monaco.editor.ITextModel>();
+const TextModelMapByFilename = new Map<string, MonacoType.editor.ITextModel>();
-export const getUriByFilename = (filename: string) => {
+export const getUriByFilename = async (filename: string) => {
+ const monaco = await getMonacoEditor();
return monaco.Uri.parse(`file:///workspace/${filename}`);
};
-const createTextModel = (
+const createTextModel = async (
filename: string,
content: string,
language: string
@@ -24,7 +26,8 @@ const createTextModel = (
return TextModelMapByFilename.get(filename)!;
}
- const uri = getUriByFilename(filename);
+ const monaco = await getMonacoEditor();
+ const uri = await getUriByFilename(filename);
const model = monaco.editor.createModel(content, language, uri);
TextModelMapByFilename.set(filename, model);
return model;
@@ -36,13 +39,15 @@ export const useMonacoTextModel = (
language: MaybeRef<Language>,
sync: boolean = true
) => {
- const model = shallowRef<monaco.editor.ITextModel>();
+ const model = shallowRef<MonacoType.editor.ITextModel>();
watch(
[ready, () => unref(filename), () => unref(language)],
- ([ready, filename, language]) => {
+ async ([ready, filename, language]) => {
if (!ready) return;
- const m = markRaw(createTextModel(filename, unref(content), language));
+ const m = markRaw(
+ await createTextModel(filename, unref(content), language)
+ );
if (sync && isRef(content)) {
m.onDidChangeContent(() => {
diff --git a/frontend/src/router/sqlEditor.ts b/frontend/src/router/sqlEditor.ts
index f6c6f41249..bdb44c0a7a 100644
--- a/frontend/src/router/sqlEditor.ts
+++ b/frontend/src/router/sqlEditor.ts
@@ -44,49 +44,49 @@ const sqlEditorRoutes: RouteRecordRaw[] = [
path: "",
name: SQL_EDITOR_HOME_MODULE,
meta: { title: () => "Bytebase SQL Editor" },
- component: () => import("../views/sql-editor/SQLEditorHomePage.vue"),
+ component: () => import("../views/sql-editor/SQLEditorPage.vue"),
},
{
path: "projects/:project",
name: SQL_EDITOR_PROJECT_MODULE,
meta: { title: () => "Bytebase SQL Editor" },
- component: () => import("../views/sql-editor/SQLEditorHomePage.vue"),
+ component: () => import("../views/sql-editor/SQLEditorPage.vue"),
},
{
path: "projects/:project/instances/:instance/databases/:database",
name: SQL_EDITOR_DATABASE_MODULE,
meta: { title: () => "Bytebase SQL Editor" },
- component: () => import("../views/sql-editor/SQLEditorHomePage.vue"),
+ component: () => import("../views/sql-editor/SQLEditorPage.vue"),
},
{
path: "projects/:project/instances/:instance",
name: SQL_EDITOR_INSTANCE_MODULE,
meta: { title: () => "Bytebase SQL Editor" },
- component: () => import("../views/sql-editor/SQLEditorHomePage.vue"),
+ component: () => import("../views/sql-editor/SQLEditorPage.vue"),
},
{
path: "projects/:project/sheets/:sheet",
name: SQL_EDITOR_WORKSHEET_MODULE,
meta: { title: () => "Bytebase SQL Editor" },
- component: () => import("../views/sql-editor/SQLEditorHomePage.vue"),
+ component: () => import("../views/sql-editor/SQLEditorPage.vue"),
},
{
path: ":connectionSlug",
name: SQL_EDITOR_DETAIL_MODULE_LEGACY,
meta: { title: () => "Bytebase SQL Editor" },
- component: () => import("../views/sql-editor/SQLEditorHomePage.vue"),
+ component: () => import("../views/sql-editor/SQLEditorPage.vue"),
},
{
path: "sheet/:sheetSlug",
name: SQL_EDITOR_SHARE_MODULE_LEGACY,
meta: { title: () => "Bytebase SQL Editor" },
- component: () => import("../views/sql-editor/SQLEditorHomePage.vue"),
+ component: () => import("../views/sql-editor/SQLEditorPage.vue"),
},
{
path: "sheet/:sheetSlug",
name: SQL_EDITOR_SHARE_MODULE_LEGACY,
meta: { title: () => "Bytebase SQL Editor" },
- component: () => import("../views/sql-editor/SQLEditorHomePage.vue"),
+ component: () => import("../views/sql-editor/SQLEditorPage.vue"),
},
{
path: "setting",
diff --git a/frontend/src/views/sql-editor/SQLEditorPage.vue b/frontend/src/views/sql-editor/SQLEditorPage.vue
new file mode 100644
index 0000000000..cceba50d32
--- /dev/null
+++ b/frontend/src/views/sql-editor/SQLEditorPage.vue
@@ -0,0 +1,34 @@
+<template>
+ <Suspense>
+ <template #default>
+ <SQLEditorHomePage />
+ </template>
+ <template #fallback>
+ <div class="flex items-center justify-center h-screen">
+ <BBSpin />
+ </div>
+ </template>
+ </Suspense>
+</template>
+
+<script setup lang="ts">
+import { defineAsyncComponent } from "vue";
+import { BBSpin } from "@/bbkit";
+
+// Lazy load the SQL Editor to reduce initial bundle size.
+const SQLEditorHomePage = defineAsyncComponent({
+ loader: () => import("./SQLEditorHomePage.vue"),
+ delay: 200,
+ timeout: 30000,
+ errorComponent: {
+ template: `
+ <div class="flex items-center justify-center h-screen">
+ <div class="text-red-500">Failed to load SQL Editor</div>
+ </div>
+ `,
+ },
+ onError(error) {
+ console.error("Failed to load SQL Editor:", error);
+ },
+});
+</script>
diff --git a/frontend/vite.config.ts b/frontend/vite.config.ts
index 938ea38ad0..cf2e9ae313 100644
--- a/frontend/vite.config.ts
+++ b/frontend/vite.config.ts
@@ -51,11 +51,40 @@ export default defineConfig({
}),
],
build: {
+ chunkSizeWarningLimit: 1000,
rollupOptions: {
input: {
main: resolve(__dirname, "index.html"),
"explain-visualizer": resolve(__dirname, "explain-visualizer.html"),
},
+ output: {
+ manualChunks: (id) => {
+ // Monaco Editor - separate chunk
+ if (id.includes("monaco-editor") || id.includes("monaco-vscode")) {
+ return "monaco-editor";
+ }
+ // SQL tools - separate chunk
+ if (id.includes("sql-formatter") || id.includes("antlr4")) {
+ return "sql-tools";
+ }
+ // Protobuf - separate chunk
+ if (id.includes("protobufjs")) {
+ return "protobuf";
+ }
+ // UI framework
+ if (id.includes("naive-ui")) {
+ return "ui-framework";
+ }
+ // Utilities
+ if (
+ id.includes("lodash") ||
+ id.includes("dayjs") ||
+ id.includes("axios")
+ ) {
+ return "utils";
+ }
+ },
+ },
},
},
server: {