diff --git a/src/app/components/utils/code-editor.vue b/src/app/components/utils/code-editor.vue index 31afda3e8..89a34cde0 100644 --- a/src/app/components/utils/code-editor.vue +++ b/src/app/components/utils/code-editor.vue @@ -27,7 +27,32 @@ import { editor, languages } from 'monaco-editor'; import { markRaw } from 'vue'; import { mapState } from 'vuex'; +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'; +// Fix error: Unexpected usage at fd.loadForeignModule +// https://github.com/vitejs/vite/discussions/1791 + +self.MonacoEnvironment = { + getWorker(_, label) { + 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() + } +} // https://microsoft.github.io/monaco-editor/api/interfaces/monaco.editor.ieditorconstructionoptions.html const defaultSizeConfig = {