scniro / react-codemirror2

Codemirror integrated components for React
MIT License
1.65k stars 192 forks source link

Using react-codemirror2 via Browserify #238

Open Devmond opened 3 years ago

Devmond commented 3 years ago

This is to save the next sap who needs to simply include this component into a browser and use it the standard way.

If you generate a bundle via Browserify, you still need to export the CodeMirror object into the global scope so any loaded modes or addons that you include will have access to it.

Your bundle entry point will need to look similar to this:

function(require,module,exports){
window.CodeMirror  = require("codemirror");
window.ReactCodeMirror = require("react-codemirror2");
},{"react-codemirror2":6,"codemirror":2}

It took me 2 days of painful digging to realize why my options were not being taken into effect. My setup had included CodeMirror directly instead of having the component use the one that it was packaged with, this will somehow prevent the options from working.