Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
sagemathinc
GitHub Repository: sagemathinc/cocalc
Path: blob/master/src/packages/frontend/codemirror/codemirror.js
1496 views
1
// This tricky code works in both Node.js *and* the web browser, in a way that
2
// works with Next.js SSR rendering. It just tooks hours of careful thought
3
// and trial and error to figure out.
4
let CodeMirror;
5
try {
6
// Try to require the full codemirror package. In the browser via webpack
7
// this will work.
8
CodeMirror = window.CodeMirror = require("codemirror");
9
require("codemirror/addon/runmode/runmode.js");
10
} catch (err) {
11
// In next.js browser or node.js, so we use the node runmode approach,
12
// which fully works in both situations.
13
// Note that we *have* to define global.CodeMirror in this case
14
// since the mode loading won't work otherwise.
15
// See ./static.js.
16
CodeMirror =
17
global.CodeMirror = require("codemirror/addon/runmode/runmode.node");
18
}
19
20
export default CodeMirror;
21
22