当用WebPack导入摩纳哥编辑时找不到依赖项



vuejs代码:

import monaco from "monaco-editor/min/vs/loader.js";

webpack.base.conf.js:

entry: {
    app: './src/main.js'
},
output:{
    path:resolve(__dirname, '../dist'),
    filename:'[name].js',
    publicPath: '/'
}

我将摩纳哥编辑与WebPack一起使用,但我什至无法导入Loader.js。似乎不允许在摩纳哥编辑下的JS文件加载。

终端输出:

These dependencies were not found:
* vs/editor/edcore.main in ./~/monaco-editor/min/vs/editor/editor.main.js
* vs/language/typescript/src/mode in ./~/monaco-editor/min/vs/editor/editor.main.js
* fs in ./~/monaco-editor/min/vs/language/typescript/lib/typescriptServices.js

我该怎么办?

有两种与WebPack集成的方法。最简单的是使用摩纳哥编辑器加载程序插件

index.js

import * as monaco from 'monaco-editor';
monaco.editor.create(document.getElementById('container'), {
  value: [
    'function x() {',
    'tconsole.log("Hello world!");',
    '}'
  ].join('n'),
  language: 'javascript'
});

webpack.config.js

const MonacoWebpackPlugin = require('monaco-editor-webpack-plugin');
const path = require('path');
module.exports = {
  entry: './index.js',
  output: {
    path: path.resolve(__dirname, 'dist'),
    filename: 'app.js'
  },
  module: {
    rules: [{
      test: /.css$/,
      use: ['style-loader', 'css-loader']
    }]
  },
  plugins: [
    new MonacoWebpackPlugin()
  ]
};

https://github.com/microsoft/monaco-editor/blob/head/head/docs/integrate-esm.md

最新更新