Path: blob/master/src/packages/frontend/codemirror/codemirror.js
1496 views
// This tricky code works in both Node.js *and* the web browser, in a way that1// works with Next.js SSR rendering. It just tooks hours of careful thought2// and trial and error to figure out.3let CodeMirror;4try {5// Try to require the full codemirror package. In the browser via webpack6// this will work.7CodeMirror = window.CodeMirror = require("codemirror");8require("codemirror/addon/runmode/runmode.js");9} catch (err) {10// In next.js browser or node.js, so we use the node runmode approach,11// which fully works in both situations.12// Note that we *have* to define global.CodeMirror in this case13// since the mode loading won't work otherwise.14// See ./static.js.15CodeMirror =16global.CodeMirror = require("codemirror/addon/runmode/runmode.node");17}1819export default CodeMirror;202122