refactor(工具箱): 优化逻辑,提取 MonacoEnvironment 配置
This commit is contained in:
21
src/assets/js/monaco-editor.js
Normal file
21
src/assets/js/monaco-editor.js
Normal file
@@ -0,0 +1,21 @@
|
||||
import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker';
|
||||
import jsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker';
|
||||
import tsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker';
|
||||
|
||||
/** 初始化 MonacoEnvironment */
|
||||
export function initMonacoEnvironment() {
|
||||
if (!self.MonacoEnvironment) {
|
||||
// 配置编辑器环境(Service Worker 等)
|
||||
self.MonacoEnvironment = {
|
||||
getWorker(workerId, label) {
|
||||
if (label === 'javascript' || label === 'typescript') {
|
||||
return new tsWorker();
|
||||
} else if (label === 'json') {
|
||||
return new jsonWorker();
|
||||
} else {
|
||||
return new editorWorker();
|
||||
}
|
||||
},
|
||||
};
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user