简体   繁体   English

使用require js导入monaco编辑器

[英]Import monaco editor using require js

I have installed monaco-editor using 我已经使用安装了monaco-editor

npm install monaco-editor

now I want to require in my js file 现在我想在我的js文件中要求

so I have tried to require using 所以我试图要求使用

var monaco = require('monaco-editor');

but it is giving me module not found error. 但这给了我模块找不到错误。

Is there wrong I am doing? 我做错了吗?

Monaco-editor uses a custom AMD style module loader. 摩纳哥编辑使用定制的AMD样式模块加载程序。 the loader.js will result in the global require being set to Monaco-editor's loader. loader.js将导致全局需求被设置为Monaco编辑器的加载器。

The samples GitHub has many examples of using the editor in different contexts. 样本 GitHub有许多在不同上下文中使用编辑器的示例。

Check out how they solve your problem in the Electorn samples index.html. 在Electorn示例index.html中查看它们如何解决您的问题。 After persisting the Monaco-editor custom loader you would use it like in most of the examples out there. 坚持使用Monaco-editor自定义加载程序后,您将像在大多数示例中一样使用它。 It is an AMD style loader so the syntax differs from node var me = require('monaco') . 它是一种AMD样式的加载程序,因此语法不同于node var me = require('monaco') I am not sure if it is possible to use like node loader but after loading loader.js and persisting the require to some variable such as amdRequire you will use such as: 我不确定是否可以使用类似node loader的方法,但是在加载loader.js并将require持久化到诸如amdRequire之类的某些变量之后,您将使用例如:

amdRequire(['vs/editor/editor.main'], function () 
{ 
    // your code using monaco ns here
    monaco.editor.create( document.getElementById('elementId'), {} );
})

They just released ESM distribution which is compatible with webpack etc. Check out the docs here . 他们刚刚发布了与webpack等兼容的ESM发行版。在此处查看文档。

Also there are many examples for using monaco with webpack , parcel an so on. 另外,还有许多将monaco与webpack一起使用, 打包等的示例。 See all. 查看全部。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM