【问题标题】:dependencies not found when import monaco-editor with webpack使用 webpack 导入 monaco-editor 时找不到依赖项
【发布时间】:2017-12-02 18:44:12
【问题描述】:

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 中使用 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

我能做什么?

【问题讨论】:

    标签: node.js webpack vue.js


    【解决方案1】:

    有两种方法可以与 webpack 集成。最简单的就是使用 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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2018-07-26
      • 1970-01-01
      • 2016-01-19
      • 2021-07-07
      • 1970-01-01
      • 2018-06-28
      • 2020-11-22
      相关资源
      最近更新 更多