monaco-editor-vue is a Vue.js component that integrates the powerful Monaco Editor, the code editor that powers VS Code. As of version 1.0.10, it provides a convenient wrapper for embedding the editor within Vue applications, simplifying initialization and event handling. While the package itself is relatively small, it relies heavily on the `monaco-editor` core, which is a significant dependency. Key differentiators include its declarative API for setting properties like `language`, `theme`, and `options`, and handling editor events through standard Vue patterns. It's actively maintained with a stable API, though specific release cadence isn't explicitly defined, it follows standard npm versioning. A crucial aspect of its usage is the requirement for `monaco-editor-webpack-plugin` for proper bundle optimization and resource loading.
npm install monaco-editor-vueVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up `monaco-editor-vue` in a Vue 3 application with TypeScript, including the necessary Webpack configuration for the `monaco-editor-webpack-plugin`. It showcases basic usage with properties like `width`, `height`, `theme`, `language`, `options`, `value` (for controlled mode), and event handling for `change`, `editorBeforeMount`, and `editorMounted`.
Install `monaco-editor-webpack-plugin` and add it to your webpack configuration (or `chainWebpack` for Vue CLI). Ensure you list all required languages in its `languages` option to avoid bundling unnecessary editor features.
If you need to switch themes, dynamically update the `theme` prop. For custom themes, register them using the `monaco` instance provided by the `editorBeforeMount` event.
For controlled mode, always bind `value` and update it with the new value received from the `@change` event. For uncontrolled mode, omit the `value` prop and retrieve the editor content via its methods or the `change` event.
Configure `monaco-editor-webpack-plugin` to include only the `languages` and `features` your application strictly needs. Consider dynamic imports if the editor is not required on the initial page load.
Ensure `monaco-editor-webpack-plugin` is installed (`npm install monaco-editor-webpack-plugin`) and correctly added to your `webpack.config.js` or `vue.config.js` `plugins` array, or `chainWebpack` configuration for Vue CLI.
Run `npm install monaco-editor-vue` or `yarn add monaco-editor-vue` and verify the import statement `import MonacoEditor from 'monaco-editor-vue';` is correct.
In your `monaco-editor-webpack-plugin` configuration, specify only the `languages` and `features` you absolutely need. Consider increasing Node.js's heap limit for your build script (e.g., `NODE_OPTIONS=--max_old_space_size=4096 vue-cli-service build`).