Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
30 changes: 25 additions & 5 deletions dashboard/src/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,33 @@ import VueApexCharts from 'vue3-apexcharts';

import print from 'vue3-print-nb';
import { loader } from '@guolao/vue-monaco-editor'
import * as monaco from 'monaco-editor';
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Importing monaco-editor statically in the main entry file will cause the entire library (which is several megabytes) to be bundled into the initial chunk. This significantly increases the application's initial load time. It is recommended to remove this static import and use a dynamic import instead.

import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
import jsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker';
import cssWorker from 'monaco-editor/esm/vs/language/css/css.worker?worker';
import htmlWorker from 'monaco-editor/esm/vs/language/html/html.worker?worker';
import tsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker';
import axios from 'axios';
import { waitForRouterReadyInBackground } from './utils/routerReadiness.mjs';

(self as any).MonacoEnvironment = {
getWorker(_: string, label: string) {
if (label === 'json') {
return new jsonWorker();
}
if (label === 'css' || label === 'scss' || label === 'less') {
return new cssWorker();
}
if (label === 'html' || label === 'handlebars' || label === 'razor') {
return new htmlWorker();
}
if (label === 'typescript' || label === 'javascript') {
return new tsWorker();
}
return new editorWorker();
},
};

// 初始化新的i18n系统,等待完成后再挂载应用
setupI18n().then(async () => {
console.log('🌍 新i18n系统初始化完成');
Expand Down Expand Up @@ -112,8 +136,4 @@ window.fetch = (input: RequestInfo | URL, init?: RequestInit) => {
return _origFetch(input, { ...init, headers });
};

loader.config({
paths: {
vs: 'https://cdn.jsdelivr.net/npm/monaco-editor@0.54.0/min/vs',
},
})
loader.config({ monaco })
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

To optimize performance, use a dynamic import for the Monaco Editor. This allows Vite to split the library into a separate chunk that is only loaded when needed. The @guolao/vue-monaco-editor loader handles Promises passed to the monaco property correctly.

Suggested change
loader.config({ monaco })
loader.config({ monaco: import('monaco-editor') })

Loading