npm package
ace-builds review
Choose ace-builds if your application can manage the editor instance and its asset URLs.
A visible editor does not prove that its theme files will load. ace-builds packages Ace for embedding in a browser page. Its npm entry is src-noconflict/ace.js; the upstream v1.45.2 source explains how additional module URLs are resolved. This guide helps developers decide whether they can manage those asset URLs and the editor's lifecycle. The examples are source-based illustrations, not executed browser tests.
Choose ace-builds if your application can manage the editor instance and its asset URLs. Before adopting it, verify an optional theme request from the deployed page and confirm that view cleanup discards only a session you intend to destroy.
Answers from our run
ace-builds or codemirror: which should you use?
codemirror: Consider codemirror 6.0.2 if you want to evaluate the package described by its registry metadata as a basic configuration for the CodeMirror code editor. Its exports declare separate import and require entries. That metadata does not establish compatibility with your application. Choose ace-builds if your application can manage the editor instance and its asset URLs.
When should you not use ace-builds?
You only need a plain text field and do not need a separate code editor.
Use it if
Skip it if
Setup reality
Install the exact package with npm install --save-exact ace-builds@1.45.2. For the script-tag example, copy node_modules/ace-builds/src-noconflict into the directory your server exposes as /vendor/ace/1.45.2/. This is a proposed deployment arrangement, not a measured installation result. Give the editor container an explicit height. The example uses an inline script; a page whose Content Security Policy blocks inline scripts needs an allowed external script instead.
Set basePath before requesting optional modules. In the upstream v1.45.2 source, config.moduleUrl checks explicit module URL overrides before constructing a filename from a component-specific path or basePath. Loading ace.js therefore does not establish that a later theme request will succeed. Check the page under its production URL prefix, request a theme and inspect the resulting network request. The root-relative paths below assume your server serves those locations; adjust them for your deployment.
The later snippets assume the first example has created editor and container. The two theme snippets are alternatives: use a theme directory or map the module to one exact URL. Neither configuration copies an asset or verifies that the server can return it.
The upstream v1.45.2 editor source documents that -1 passed to setValue moves the cursor to the start; omitting the argument selects all text. getValue returns the current session's content. setReadOnly changes an editor option and does not provide server authorization. Its implementation does not prevent application code from calling setValue.
Read any final text before disposal. The upstream v1.45.2 destroy implementation destroys the attached session and removes editor listeners. Use the cleanup example only when that session can be discarded. Application-owned buttons and DOM listeners need their own cleanup.
The evidence consists of supplied npm registry metadata, upstream v1.45.2 implementation extracts and the tagged changelog. It contains no inspection extracts from the published ace-builds JavaScript, browser execution results, application installation results, audit results or loading-time measurements. These snippets have not been executed for this guide. Before adoption, verify the production asset paths and check typing and keyboard access on your target devices.
The dimension notes use documentation evidence as their criteria: available methods and documented edge behavior for API stability; the clarity and location of integration explanations for documentation quality; dated changelog entries for maintenance; and declared entry points, typings and loader configuration for ecosystem integration. Cross-version compatibility, adoption and browser performance remain unmeasured. The numerical fields are retained without introducing an editorial scoring scale; the supplied evidence does not establish the site's score-computation formula.
Patterns
Create a browser editor with local assets mount-editor
<!-- Serve the copied src-noconflict directory at this URL first. -->
<div id="editor" style="height: 300px; width: 100%"></div>
<script src="/vendor/ace/1.45.2/ace.js"></script>
<script>
ace.config.set("basePath", "/vendor/ace/1.45.2");
const container = document.getElementById("editor");
const editor = ace.edit(container);
editor.setValue("SELECT 1;", -1);
</script>Source-based browser illustration, not an executed example. Serve the copied assets before opening the page. Later snippets assume editor and container exist in this page.
Load a theme from a separate directory configure-theme-path
// Copy the 1.45.2 theme-monokai.js file here first.
ace.config.set("themePath", "/vendor/ace/1.45.2/themes");
editor.setTheme("ace/theme/monokai");The upstream resolver constructs a theme-monokai.js URL beneath themePath. This configuration does not copy the file or verify the URL. Use this or the exact-URL example.
Map a theme to one exact URL override-theme-url
// Serve the 1.45.2 theme file at this URL first.
// Apply the override before requesting the theme.
ace.config.setModuleUrl(
"ace/theme/monokai",
"/static/editor/theme-monokai.js"
);
editor.setTheme("ace/theme/monokai");In the upstream v1.45.2 resolver, the explicit module URL takes precedence over path construction. This is an alternative to the themePath example, not a deployment check.
Replace text and position the cursor replace-editor-text
editor.setValue("SELECT customer_id\nFROM customers;", -1);This replaces the document. The upstream v1.45.2 implementation moves to the start for -1, moves to the end for 1 and selects all text when the argument is omitted or zero.
Read text when the user asks to save read-editor-text
const saveButton = document.createElement("button");
saveButton.textContent = "Read query";
container.after(saveButton);
function readQuery() {
const query = editor.getValue();
console.log(query);
}
saveButton.addEventListener("click", readQuery);getValue returns the current session's content. This illustration logs the text; it does not save it. If used, remove the button and its listener when disposing of the view.
Switch the editing control to read-only make-editor-read-only
editor.setReadOnly(true);
// When your application allows editing again:
// editor.setReadOnly(false);The upstream method sets the readOnly option. It does not provide server authorization, and setValue can still replace the document through application code.
Recompute layout after changing container size resize-visible-editor
container.style.height = "420px";
editor.resize(true);The upstream resize documentation says true recomputes size even when height and width have not changed. This illustration assumes a visible container; hidden-container behavior was not tested.
Dispose of the view after reading its final text dispose-editor
const finalText = editor.getValue();
// If the read-editor-text example was used:
// saveButton.removeEventListener("click", readQuery);
// saveButton.remove();
editor.destroy();
container.remove();Run this last, only when the attached session can be discarded. The upstream v1.45.2 destroy implementation destroys that session and removes editor listeners. Uncomment the button cleanup if that example was used. finalText remains an in-memory string.
Alternatives
| Package | Registry | Pick it when |
|---|---|---|
| codemirror | npm | Consider codemirror 6.0.2 if you want to evaluate the package described by its registry metadata as a basic configuration for the CodeMirror code editor. Its exports declare separate import and require entries. That metadata does not establish compatibility with your application. |
| monaco-editor | npm | Consider monaco-editor 0.57.0 as another browser code editor to evaluate. Its registry exports declare separate import and require entries. Verify those entry points in your own build; the metadata does not establish easier integration. |
More data guides
How this guide is made: grounded in the library's documentation, release notes, changelog, and issue history, on a fixed rubric — not a hands-on install of every release. The 50 most-downloaded entries are additionally install-verified in clean containers. Corrections: contact the desk.