使用webpack导入monaco-editor时找不到依赖项

anr*_*nie 5 node.js webpack vue.js

vuejs代码:

import monaco from "monaco-editor/min/vs/loader.js";
Run Code Online (Sandbox Code Playgroud)

webpack.base.conf.js:

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

我使用webpack的monaco-editor,但我甚至无法导入loader.js.看起来像monaco-editor/vs下的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
Run Code Online (Sandbox Code Playgroud)

我能做什么?

Ari*_*yen 1

有 2 种方法可以与 webpack 集成。最简单的是使用 Monaco Editor Loader Plugin

索引.js

import * as monaco from 'monaco-editor';

monaco.editor.create(document.getElementById('container'), {
  value: [
    'function x() {',
    '\tconsole.log("Hello world!");',
    '}'
  ].join('\n'),
  language: 'javascript'
});
Run Code Online (Sandbox Code Playgroud)

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()
  ]
};
Run Code Online (Sandbox Code Playgroud)

https://github.com/Microsoft/monaco-editor/blob/HEAD/docs/integrate-esm.md