在 umijs 项目中使用 Monaco Editor 的配置

在 umijs 项目中使用 Monaco Editor 的配置

  1. 安装相关包
    yarn add monaco-editoryarn add monaco-editor-webpack-pluginyarn add react-monaco-editor
  2. 添加 chainWebpack 配置
import MonacoWebpackPlugin from 'monaco-editor-webpack-plugin';
...
const chainWebpack = (config, { webpack }) => {
    config.plugin('monaco-editor').use(MonacoWebpackPlugin, [
        {
            languages: ['yaml']
        }
    ])
};
export default{
    ...
    chainWebpack
}
  1. 使用
<Monaco
    width="100%"
    height="100%"
    language="yaml"
    theme="vs-light"
    value={code}
    options={{ selectOnLineNumbers: true }}
/>

猜你喜欢

转载自www.cnblogs.com/zengande/p/11505505.html
今日推荐