ace-builds provides the distribution files for the Ace Editor, a mature, lightweight text editor engine. @monaco-editor/loader is a low-level utility for loading the Monaco Editor (the engine behind VS Code) in browser environments, handling AMD module resolution. react-monaco-editor is a React component wrapper that simplifies embedding the Monaco Editor into React applications. While ace-builds represents a different editor engine entirely, the Monaco packages offer varying levels of abstraction for integrating Microsoft's editor technology.
When embedding a code editor into a web application, architects typically choose between two dominant engines: Ace and Monaco. ace-builds distributes the Ace Editor, while @monaco-editor/loader and react-monaco-editor facilitate integrating the Monaco Editor. The decision isn't just about features โ it's about bundle weight, initialization complexity, and framework integration. Let's compare how these packages handle real-world implementation.
ace-builds requires manual initialization on a DOM node.
// ace-builds: Manual initialization
import ace from 'ace-builds';
const editor = ace.edit("editor-container");
editor.setTheme("ace/theme/monokai");
editor.session.setMode("ace/mode/javascript");
editor.setValue("function hello() {}");
@monaco-editor/loader handles the asynchronous loading of Monaco's AMD modules.
init() and wait for the promise to resolve before creating the editor.// @monaco-editor/loader: Custom loading
import * as monacoLoader from '@monaco-editor/loader';
monacoLoader.init().then((monaco) => {
const editor = monaco.editor.create(document.getElementById("container"), {
value: "function hello() {}",
language: "javascript"
});
});
react-monaco-editor abstracts initialization into a React component.
<Editor /> component with props.// react-monaco-editor: Component abstraction
import Editor from 'react-monaco-editor';
function CodeEditor() {
return (
<Editor
height="90vh"
language="javascript"
value="function hello() {}"
theme="vs-dark"
/>
);
}
ace-builds uses direct method calls for configuration.
setOptions on the editor instance.// ace-builds: Direct configuration
editor.setOptions({
fontSize: "14pt",
showPrintMargin: false,
wrap: true
});
@monaco-editor/loader passes configuration objects to the create method.
updateOptions on the instance.// @monaco-editor/loader: Config object
const editor = monaco.editor.create(container, {
value: "",
fontSize: 14,
automaticLayout: true
});
// Later update
editor.updateOptions({ fontSize: 16 });
react-monaco-editor passes configuration via React props.
// react-monaco-editor: Prop-based config
function CodeEditor({ fontSize }) {
const options = { fontSize, automaticLayout: true };
return <Editor options={options} language="javascript" />;
}
ace-builds relies on traditional event emitters.
editor.on().// ace-builds: Event emitter
editor.on("change", (delta) => {
console.log("Content changed", delta);
});
// Cleanup required
// editor.off("change", handler);
@monaco-editor/loader uses Monaco's event system.
// @monaco-editor/loader: Disposable events
const listener = editor.onDidChangeModelContent((e) => {
console.log("Model changed", e);
});
// Cleanup
// listener.dispose();
react-monaco-editor exposes events as callback props.
onChange directly to the component.// react-monaco-editor: Callback props
function CodeEditor() {
const handleChange = (value) => {
console.log("Value updated", value);
};
return <Editor onChange={handleChange} language="javascript" />;
}
ace-builds requires explicit destruction.
editor.destroy() when the component unmounts.// ace-builds: Manual cleanup
useEffect(() => {
const editor = ace.edit("container");
return () => {
editor.destroy();
};
}, []);
@monaco-editor/loader requires manual disposal of the editor instance.
editor.dispose() in useEffect cleanup.// @monaco-editor/loader: Manual disposal
useEffect(() => {
let editorInstance;
monacoLoader.init().then((monaco) => {
editorInstance = monaco.editor.create(container, options);
});
return () => {
if (editorInstance) editorInstance.dispose();
};
}, []);
react-monaco-editor handles cleanup internally.
// react-monaco-editor: Automatic cleanup
// No explicit cleanup code needed in parent component
function App() {
return <Editor language="javascript" />;
}
ace-builds is often loaded via CDN or copied assets.
// ace-builds: CDN configuration
ace.config.set('basePath', 'https://cdnjs.cloudflare.com/ajax/libs/ace/1.4.12/');
@monaco-editor/loader supports configuring the CDN path for Monaco assets.
paths to a CDN to avoid bundling the heavy editor code.// @monaco-editor/loader: CDN config
monacoLoader.config({
paths: {
vs: 'https://cdn.jsdelivr.net/npm/monaco-editor@0.33.0/min/vs'
}
});
react-monaco-editor typically bundles the editor or expects global setup.
// react-monaco-editor: Webpack config (simplified)
// Requires CopyWebpackPlugin to move monaco assets to build folder
// Or using monaco-editor-webpack-plugin
Despite different engines and abstraction levels, these tools share core goals.
// Ace
editor.session.setMode("ace/mode/python");
// Monaco
monaco.editor.create(el, { language: "python" });
// Ace
editor.setTheme("ace/theme/twilight");
// Monaco
monaco.editor.defineTheme('myTheme', { base: 'vs-dark', inherit: true, rules: [] });
// Ace
editor.commands.addCommand({ name: 'save', bindKey: 'Ctrl-S', exec: saveFunction });
// Monaco
editor.addCommand(monaco.KeyMod.CtrlCmd | monaco.KeyCode.KeyS, saveFunction);
| Feature | ace-builds | @monaco-editor/loader | react-monaco-editor |
|---|---|---|---|
| Engine | Ace Editor | Monaco Editor | Monaco Editor |
| React Integration | Manual (useEffect) | Manual (useEffect) | Built-in Component |
| Initialization | Synchronous (DOM ready) | Asynchronous (Promise) | Declarative (JSX) |
| Cleanup | Manual (destroy()) | Manual (dispose()) | Automatic |
| Bundle Weight | Lighter | Heavier | Heavier |
| Maintenance | Stable, Legacy | Active, Low-level | Community, Less Active than Official |
ace-builds is the pragmatic choice for lightweight needs.
@monaco-editor/loader is the power user's tool for Monaco.
react-monaco-editor is the convenience wrapper.
@monaco-editor/react instead, as it is more actively maintained by the loader's author. Use react-monaco-editor primarily for maintaining existing implementations.Final Thought: The choice between Ace and Monaco is about feature density vs. performance. The choice between Loader and React Wrapper is about control vs. convenience. Match the tool to your team's capacity and your app's requirements.
Choose @monaco-editor/loader if you need full control over the Monaco Editor initialization process without the constraints of a pre-built React component. It is ideal for custom integrations, non-React frameworks, or when you need to manage the editor lifecycle manually to optimize performance in complex applications.
Choose ace-builds if you require a lightweight, highly stable editor with a smaller footprint than Monaco. It is suitable for legacy systems, simple text editing needs, or environments where the heavy resource usage of Monaco is prohibitive, though it lacks some of the advanced IDE features of Monaco.
Choose react-monaco-editor if you need a quick, drop-in React component for Monaco Editor and prefer a community-maintained wrapper. However, for new projects, evaluate @monaco-editor/react as it is more actively maintained; use this package primarily for maintaining existing codebases that already depend on it.
The utility to easy setup monaco-editor into your browser
Configure and download monaco sources via its loader script, without needing to use webpack's (or any other module bundler's) configuration files
It's been a while we are working with monaco editor. It's a great library and provides a powerful editor out of the box. Anyway, there were couple of problems related to the setup process. The main problem is the need to do some additional webpack configuration; that's not bad, but some quite useful tools, like CRA, aren't happy with that fact. The library @monaco-editor/react was being created to solve that problem - monaco editor wrapper for easy/one-line integration with React applications without needing to use webpack's (or any other module bundler's) configuration files. In that library, there was a utility that cares about the initialization process of monaco and overcomes the additional use of webpack configuration. That utility grows over time and now it's a separate library. Now, you can easily setup monaco into your browser, create your own editors, wrappers for React/Vue/Angular of whatever you want.
Monaco editor provides a script called loader, which itself provides tooling to download monaco sources. The library, under the hood, handles the configuration and loading part and gives us an easy-to-use API to interact with it
npm install @monaco-editor/loader
or
yarn add @monaco-editor/loader
NOTE: For TypeScript type definitions, this package uses the monaco-editor package as a peer dependency. So, if you need types and don't already have the monaco-editor package installed, you will need to do so.
The library exports types and the utility called loader, the last one has two methods
import loader from '@monaco-editor/loader';
loader.init().then(monaco => {
monaco.editor.create(/* editor container, e.g. document.body */, {
value: '// some comment',
language: 'javascript',
});
});
By using the .config method we can configure the monaco loader. By default all sources come from CDN, you can change that behavior and load them from wherever you want
import loader from '@monaco-editor/loader';
// you can change the source of the monaco files
loader.config({ paths: { vs: '...' } });
// you can configure the locales
loader.config({ 'vs/nls': { availableLanguages: { '*': 'de' } } });
// or
loader.config({
paths: {
vs: '...',
},
'vs/nls' : {
availableLanguages: {
'*': 'de',
},
},
});
loader.init().then(monaco => { /* ... */ });
import loader from '@monaco-editor/loader';
import * as monaco from 'monaco-editor';
loader.config({ monaco });
loader.init().then(monacoInstance => { /* ... */ });
The .init method handles the initialization process. It returns the monaco instance, wrapped with cancelable promise
import loader from '@monaco-editor/loader';
loader.init().then(monaco => {
console.log('Here is the monaco instance', monaco);
});
import loader from '@monaco-editor/loader';
const cancelable = loader.init();
cancelable.then(monaco => {
console.log('You will not see it, as it is canceled');
});
cancelable.cancel();
electron usersIn general it works fine with electron, but there are several cases that developers usually face to and sometimes it can be confusing. Here they are:
import loader from '@monaco-editor/loader';
loader.config({ paths: { vs: '../path-to-monaco' } });
or, if you want to use it as an npm package, you can do it like this:
import loader from '@monaco-editor/loader';
import * as monaco from 'monaco-editor';
loader.config({ monaco });
loader.init().then(monacoInstance => { /* ... */ });
monaco-editor package installed and you want to load monaco from the node_modules rather than from CDN: in that case, you can write something like this:function ensureFirstBackSlash(str) {
return str.length > 0 && str.charAt(0) !== '/'
? '/' + str
: str;
}
function uriFromPath(_path) {
const pathName = path.resolve(_path).replace(/\\/g, '/');
return encodeURI('file://' + ensureFirstBackSlash(pathName));
}
loader.config({
paths: {
vs: uriFromPath(
path.join(__dirname, '../node_modules/monaco-editor/min/vs')
)
}
});
or, just use it as an npm package.
There were several issues about this topic that can be helpful too - 1 2 3 4
And if you use electron with monaco and have faced an issue different than the above-discribed ones, please let us know to make this section more helpful.
Next.js usersThe part of the source that should be pre-parsed is optimized for server-side rendering, so, in usual cases, it will work fine, but if you want to have access, for example, to monacoInstance you should be aware that it wants to access the document object, and it requires browser environment. Basically you just need to avoid running that part out of browser environment, there are several ways to do that. One of them is described here.
And if you use monaco with Next.js and have faced an issue different than the above-described one, please let us know to make this section more helpful.