A Vite plugin that simplifies loading the Monaco Editor by automatically bundling workers and injecting them via Vite's dev server and build pipeline. Version 1.1.0 is the latest stable release, with active maintenance (frequent patch releases). Unlike webpack-based alternatives, it leverages Vite-specific hooks and esbuild for worker bundling, supports custom language workers, CDN public path overrides, and selective worker inclusion. Ships TypeScript types. Requires monaco-editor >=0.33.0 as a peer dependency.
npm install vite-plugin-monaco-editorVerified import paths — ran on the pinned version, not inferred.
Basic setup: add plugin to vite config and create an editor instance with one language.
Ensure your vite config is in .mjs or TypeScript, or use dynamic import().
Install monaco-editor as a regular dependency (not devDependency) and import it in your code.
In your entry file, add: (self as any).MonacoEnvironment = { globalAPI: true }; then import * as monaco from 'monaco-editor';If you rely on the default publicPath for caching, update your service-worker or CDN config.
Change to: import monacoEditorPlugin from 'vite-plugin-monaco-editor'
Run: npm install monaco-editor; then add the plugin to vite.config.ts.
Use: import * as monaco from 'monaco-editor'