import monaco from "monaco-editor/min/vs/loader.js";
entry: {
    app: './src/main.js'
},
output:{
    path:resolve(__dirname, '../dist'),
    filename:'[name].js',
    publicPath: '/'
}
im use monaco-editor with webpack, but i can't even import loader.js. seems like js files under monaco-editor/vs are not allowed to load.
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
what can i do?
There's 2 ways to integrate with webpack. The easiest is to use Monaco Editor Loader Plugin
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/docs/integrate-esm.md
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With