Add the Monaco Webpack pluginmonaco-editor-webpack-plugin to your webpack.config.js:
const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');module.exports = { plugins: [ new MonacoWebpackPlugin({ // available options are documented at https://github.com/microsoft/monaco-editor/blob/main/webpack-plugin/README.md#options languages: ['json'] }) ]};
Sidenote: Monaco Editor uses CSS imports internally, so if you're using CSS Modules in your project - you're likely to get conflict by default. In order to avoid that - separate css-loader for app and monaco-editor package:
import React from 'react';import { MonacoDiffEditor } from 'react-monaco-editor';class App extends React.Component { render() { const code1 = "// your original code..."; const code2 = "// a different version..."; const options = { //renderSideBySide: false }; return ( <MonacoDiffEditor width="800" height="600" language="javascript" original={code1} value={code2} options={options} /> ); }}
Usage with create-react-app
The easiest way to use the react-monaco-editor with create-react-app is to use the react-app-rewired project. For setting it up, the following steps are required: