From cf963f2a2cb24a17a30ef4c5a43c5004d477011a Mon Sep 17 00:00:00 2001 From: seven Date: Sat, 30 Dec 2023 18:33:52 +0800 Subject: [PATCH] feat: fix monaco editor import language issue #10 Signed-off-by: seven --- src/views/editor/index.vue | 32 +++++++++++++++++++++++++++++++- vite.config.ts | 1 - 2 files changed, 31 insertions(+), 2 deletions(-) diff --git a/src/views/editor/index.vue b/src/views/editor/index.vue index 560654d..88b8f6f 100644 --- a/src/views/editor/index.vue +++ b/src/views/editor/index.vue @@ -29,9 +29,39 @@ const { established } = storeToRefs(connectionStore); * refer https://github.com/wobsoriano/codeplayground * https://github.com/wobsoriano/codeplayground/blob/master/src/components/MonacoEditor.vue */ +self.MonacoEnvironment = { + async getWorker(_, label) { + let worker; + + switch (label) { + case 'json': + worker = await import('monaco-editor/esm/vs/language/json/json.worker?worker'); + break; + case 'css': + case 'scss': + case 'less': + worker = await import('monaco-editor/esm/vs/language/css/css.worker?worker'); + break; + case 'html': + case 'handlebars': + case 'razor': + worker = await import('monaco-editor/esm/vs/language/html/html.worker?worker'); + break; + case 'typescript': + case 'javascript': + worker = await import('monaco-editor/esm/vs/language/typescript/ts.worker?worker'); + break; + default: + worker = await import('monaco-editor/esm/vs/editor/editor.worker?worker'); + } + + return new worker.default(); + }, +}; +monaco.languages.typescript.typescriptDefaults.setEagerModelSync(true); + monaco.languages.register({ id: 'search' }); monaco.languages.setMonarchTokensProvider('search', searchTokensProvider); - // https://github.com/tjx666/adobe-devtools/commit/8055d8415ed3ec5996880b3a4ee2db2413a71c61 let displayEditor: Editor | null = null; let queryEditor: Editor | null = null; diff --git a/vite.config.ts b/vite.config.ts index e3cd61e..537a905 100644 --- a/vite.config.ts +++ b/vite.config.ts @@ -30,7 +30,6 @@ export default defineConfig({ resolve: { alias: { 'vue-i18n': 'vue-i18n/dist/vue-i18n.cjs.js', - 'monaco-editor': 'monaco-editor/esm/vs/editor/editor.api.js', }, }, });