Monaco Internals
This page covers build and runtime tips for monaco-editor when using the library.
Installation
bash
pnpm add stream-monacoVite bundling tips
- Monaco requires worker configuration for production builds. Use
vite-plugin-monaco-editor-esmorvite-plugin-monaco-editor. - In Vite config:ts
import { defineConfig } from 'vite' import monacoEditorPlugin from 'vite-plugin-monaco-editor' export default defineConfig({ plugins: [monacoEditorPlugin()] })
Avoid worker-not-found errors
- Ensure the plugin packages Monaco workers where your site expects them (e.g., via
customDistPath) and verify worker file urls after build. - If bundling into a library, make sure the peer
stream-monacois installed in consuming applications.
Packaging notes
- The library lazy-loads Monaco only when a
CodeBlockNodemounts. This reduces initial bundle size and avoids SSR failures. - If the host app wants to warm Monaco earlier, call markstream-vue's
preloadCodeBlockRuntime()instead of importingstream-monacodirectly. This keeps markstream-vue's code block runtime readiness in sync with the worker preload.
Troubleshooting
- If you see
Failed to load Monaco worker, check that the worker files are present indistand accessible by the built site. The plugin'scustomDistPathcan help relocate them.
Quick try — preload the code block runtime at app startup so editor mounts faster and warm remounts skip the loading fallback:
ts
import { preloadCodeBlockRuntime } from 'markstream-vue'
void preloadCodeBlockRuntime()getUseMonaco() remains supported for existing integrations and has the same runtime-ready side effect.