Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dependencies not found when import monaco-editor with webpack

vuejs code:

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: '/'
}

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.

terminal output:

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?

like image 798
anrainie Avatar asked Nov 08 '22 20:11

anrainie


1 Answers

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

like image 56
Arielle Nguyen Avatar answered Nov 14 '22 21:11

Arielle Nguyen