This post covers how to wire up CodeMirror version 5 in an Ember application.
npm i codemirror@5
ember install ember-modifier
ember g component javascript-editor
ember g modifier codemirror
First, let's update the ember-cli-build.js
file to include the CodeMirror CSS.
ember-cli-build.js
app.import('node_modules/codemirror/lib/codemirror.css');
Next, we'll invoke the component that we generated which will contain the JavaScript editor that we'll create through CodeMirror.
app/templates/application.hbs
<JavascriptEditor />
Let's update our component's template with a textarea
and a codemirror
modifier that we'll create.
app/templates/application.hbs
<textarea >const name = 'David';</textarea>
Finally, here is our codemirror
modifier.
app/modifiers/codemirror.js
import { modifier } from 'ember-modifier';
import CodeMirror from 'codemirror';
export default modifier(function codemirror(textarea) {
CodeMirror.fromTextArea(textarea, {
lineNumbers: true,
});
});