简体   繁体   English

摩纳哥编辑器不会在React应用中显示

[英]Monaco editor won't show in a react app

I started using react-monaco-editor library because I want to add a cool json editor in my web react application. 我开始使用react-monaco-editor库,因为我想在Web react应用程序中添加一个很酷的json编辑器。

I followed the instruction on github: react-monaco-editor-DOC 我按照github上的说明进行操作: react-monaco-editor-DOC

but it seems like I am missing something which is probably not shared in the DOC for the webpack setup. 但似乎我缺少Webpack设置的DOC中可能未共享的内容。 After I used the webpack setup instructions from the doc, import the library and added the lines: 使用文档中的webpack设置说明后,导入库并添加以下行:

 import MonacoEditor from 'react-monaco-editor'; class Editor extends React.Component{ editorDidMount(editor, monaco) { console.log('editorDidMount', editor); editor.focus(); } render(){ const options = { selectOnLineNumbers: true }; return( <div> <MonacoEditor width="800" height="600" language="json" value="// some code" options={options} editorDidMount={this.editorDidMount}/> </div> ); } } 

I get an empty text area. 我得到一个空白的文本区域。

I've encountered the same issue. 我遇到了同样的问题。 The solution was to configure Webpack to copy a vs folder from inside an npm module or to use a require.config . 解决方案是将Webpack配置为从npm模块内部复制vs文件夹,或使用require.config Another way is to put it into a public folder manually. 另一种方法是手动将其放入公用文件夹。 I'm not sure whether it's the correct way, but in my case this workaround works just perfect. 我不确定这是否是正确的方法,但就我而言,此变通办法很完美。

here is my sample of require part: 这是我的需求部分样本:

render() {
  const requireConfig = {
    url: 'node_modules/monaco-editor/min/vs/loader.js',
    paths: {
      vs: 'node_modules/monaco-editor/min/vs'
    }
  };

  return (
    <MonacoEditor
      ...
      requireConfig={requireConfig}
    />
  );
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM