monacoSetup.ts 972 B

1234567891011121314151617181920
  1. import * as monaco from 'monaco-editor'
  2. import editorWorker from 'monaco-editor/esm/vs/editor/editor.worker?worker'
  3. import jsonWorker from 'monaco-editor/esm/vs/language/json/json.worker?worker'
  4. // The JavaScript editor on the Functions page is backed by monaco's TypeScript
  5. // worker (JS and TS share it). Without this mapping monaco hands a JS model the
  6. // plain editor worker, which does not speak the language protocol, so editing a
  7. // function's source throws from inside the worker. Bundled locally like the
  8. // others - the CDN loader is not an option offline.
  9. import tsWorker from 'monaco-editor/esm/vs/language/typescript/ts.worker?worker'
  10. import { loader } from '@monaco-editor/react'
  11. self.MonacoEnvironment = {
  12. getWorker(_workerId: string, label: string): Worker {
  13. if (label === 'json') return new jsonWorker()
  14. if (label === 'javascript' || label === 'typescript') return new tsWorker()
  15. return new editorWorker()
  16. },
  17. }
  18. loader.config({ monaco })