-
-
Notifications
You must be signed in to change notification settings - Fork 2k
feat: integrate Monaco Editor workers for enhanced code editing support #7249
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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'; | ||||||
| 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系统初始化完成'); | ||||||
|
|
@@ -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 }) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 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
Suggested change
|
||||||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Importing
monaco-editorstatically 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.