From a3fd691dd6a0c7fa7dca8ac35e51793c4739a102 Mon Sep 17 00:00:00 2001 From: Pranav C Date: Thu, 14 Dec 2023 06:15:47 +0000 Subject: [PATCH] fix: load workers inline --- packages/nc-gui/components/monaco/Editor.vue | 29 ++++++++++++-------- packages/nc-gui/nuxt.config.ts | 8 ------ 2 files changed, 18 insertions(+), 19 deletions(-) diff --git a/packages/nc-gui/components/monaco/Editor.vue b/packages/nc-gui/components/monaco/Editor.vue index 4e8046987c..50282b4f28 100644 --- a/packages/nc-gui/components/monaco/Editor.vue +++ b/packages/nc-gui/components/monaco/Editor.vue @@ -2,12 +2,12 @@ import 'monaco-editor/esm/vs/basic-languages/javascript/javascript.contribution' import 'monaco-editor/esm/vs/basic-languages/typescript/typescript.contribution' -import EditorWorkerUrl from 'monaco-editor/esm/vs/editor/editor.worker?worker&url' -import TsWorkerUrl from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker&url' -import JsonWorkerUrl from 'monaco-editor/esm/vs/language/json/json.worker?worker&url' +import EditorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker&inline' +import TsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker&inline' +import JsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker&inline' import type { editor as MonacoEditor } from 'monaco-editor' -import { deepCompare, isDrawerOrModalExist, onMounted, ref, watch, initWorker } from '#imports' +import { deepCompare, initWorker, isDrawerOrModalExist, onMounted, ref, watch } from '#imports' interface Props { modelValue: string | Record @@ -49,15 +49,22 @@ const isValid = ref(true) * Adding monaco editor to Vite * * @ts-expect-error */ -self.MonacoEnvironment = { +self.MonacoEnvironment = window.MonacoEnvironment = { getWorker(_: any, label: string) { + console.log(JsonWorker, TsWorker, EditorWorker) switch (label) { - case 'json': - return initWorker(JsonWorkerUrl) - case 'typescript': - return initWorker(TsWorkerUrl) - default: - return initWorker(EditorWorkerUrl) + case 'json': { + const workerBlob = new Blob([JsonWorker], { type: 'text/javascript' }) + return initWorker(URL.createObjectURL(workerBlob)) + } + case 'typescript': { + const workerBlob = new Blob([TsWorker], { type: 'text/javascript' }) + return initWorker(URL.createObjectURL(workerBlob)) + } + default: { + const workerBlob = new Blob([EditorWorker], { type: 'text/javascript' }) + return initWorker(URL.createObjectURL(workerBlob)) + } } }, } diff --git a/packages/nc-gui/nuxt.config.ts b/packages/nc-gui/nuxt.config.ts index c662cf8730..46f92228c6 100644 --- a/packages/nc-gui/nuxt.config.ts +++ b/packages/nc-gui/nuxt.config.ts @@ -4,7 +4,6 @@ import Icons from 'unplugin-icons/vite' import IconsResolver from 'unplugin-icons/resolver' import Components from 'unplugin-vue-components/vite' import { AntDesignVueResolver } from 'unplugin-vue-components/resolvers' -import monacoEditorPlugin from 'vite-plugin-monaco-editor' import { NodeModulesPolyfillPlugin } from '@esbuild-plugins/node-modules-polyfill' import { FileSystemIconLoader } from 'unplugin-icons/loaders' @@ -180,13 +179,6 @@ export default defineNuxtConfig({ }), ], }), - monacoEditorPlugin({ - languageWorkers: ['json'], - // customWorkers: [{ label: 'sql', entry: 'monaco-sql-languages/out/esm/sql/sql.worker.js' }], - customDistPath: (root: string, buildOutDir: string) => { - return `${buildOutDir}/` + `monacoeditorwork` - }, - }), PurgeIcons({ /* PurgeIcons Options */ includedCollections: ['emojione'],