umi(react)项目中引入monaco-editor

编程入门 行业动态 更新时间:2024-10-26 04:28:17
  1. 问题

Module parse failed: Unexpected token (30:15)

You may need an appropriate loader to handle this file type, currently no loaders are configured to process this file. See https://webpack.js/concepts#loaders

| // src/language/json/monaco.contribution.ts

| var LanguageServiceDefaultsImpl = class {

> _onDidChange = new monaco_editor_core_exports.Emitter();

  1. 分析:需要编译可以翻译class 的loader。引入@babel/plugin-proposal-class-properties

import MonacoWebpackPlugin from 'monaco-editor-webpack-plugin';
// config.ts中
  chainWebpack(memo, { webpack }) {
    const Config = require('webpack-chain');
    const config = new Config();

    config.module
      .rule('compile')
      .test('/\.(js|jsx)$/')
      .use('babel')
      .loader('babel-loader')
      .options({
        presets: ["@babel/preset-env", "@babel/preset-react"],
        plugins: ["@babel/plugin-proposal-class-properties"],
      })
    config.plugin('monaco-editor').use(MonacoWebpackPlugin, [
      {
        languages: ['json', 'javascript']
      }
    ])
    module.exports = config.toConfig();
  },
    <MonacoEditor
        width="800"
        height="600"
        language="mysql"
        theme="vs-light"
        value={code}
        options={{
            selectOnLineNumbers: true
        }}
        onChange={onMonacoChange}
    // editorDidMount={this.editorDidMount}
    />

更多推荐

umi(react)项目中引入monaco-editor

本文发布于:2023-06-14 09:48:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1462587.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:项目   react   umi   monaco   editor

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!