| 1234567891011121314151617181920 |
- 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'
- // The JavaScript editor on the Functions page is backed by monaco's TypeScript
- // worker (JS and TS share it). Without this mapping monaco hands a JS model the
- // plain editor worker, which does not speak the language protocol, so editing a
- // function's source throws from inside the worker. Bundled locally like the
- // others - the CDN loader is not an option offline.
- import tsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker'
- import { loader } from '@monaco-editor/react'
- self.MonacoEnvironment = {
- getWorker(_workerId: string, label: string): Worker {
- if (label === 'json') return new jsonWorker()
- if (label === 'javascript' || label === 'typescript') return new tsWorker()
- return new editorWorker()
- },
- }
- loader.config({ monaco })
|