如何在没有 Node.js 的情况下使用摩纳哥编辑器

yot*_*ota 6 monaco-editor

我需要将 monaco-editor 与纯客户端解决方案集成在网页上,并且无需使用 Node.js。

我在 @SimperT How to Implement monaco-editor on a web without Nodejs and Electron找到了一个很好的答案,但他的存储库已经过时了(js 是一个狂野的世界),而且我有一个额外的限制,即文件只能在本地提供(没有 CDN) ,其用于 Intranet,无需外部访问)。

所以,这有点像瓶子里的信息,但如果有人有关于如何做到这一点的线索或指示,我会洗耳恭听......(如果我想出解决方案,我会将其发布在这里)

yot*_*ota 16

这个问题问得有点笨拙。尽管如此,我的错误可能对其他人有益:问题出在未正确设置的 require 变量中。

在这里找到包: https: //registry.npmjs.org/monaco-editor/-/monaco-editor-0.23.0.tgz

解压并正确静态服务。路径是monaco-editor-x.xx.x/package/min/vs/[editor/].

这是提供的 html 页面(使用cherrypy):

<!doctype html>
<html lang="en">
    <head>
        <meta charset="utf-8">
        <title>monaco editor</title>

        <!-- MONACO CSS -->
        <link rel="stylesheet" data-name="vs/editor/editor.main" href="_static/js/ext/monaco-editor/min/vs/editor/editor.main.css">
    </head>

    <body style="background-color: rgb(140, 190, 190);">
        <h1>monaco editor</h1>
        <div id="monaco_editor" style="height:400px">
        </div>

        <!-- MONACO JS -->
        <script>var require = { paths: { 'vs': '_static/js/ext/monaco-editor/min/vs' } };</script>

        <script src="_static/js/ext/monaco-editor/min/vs/loader.js"></script>
        <script src="_static/js/ext/monaco-editor/min/vs/editor/editor.main.nls.js"></script>
        <script src="_static/js/ext/monaco-editor/min/vs/editor/editor.main.js"></script>

        <script>
        // CREATE AN EDITOR
        var h_div = document.getElementById('monaco_editor');
        var editor = monaco.editor.create(h_div, {
            value: [
                'function x() {',
                '\tconsole.log("Hello world!");',
                '}'
            ].join('\n'),
            language: 'javascript'
        });
        </script>
    </body>
</html>
Run Code Online (Sandbox Code Playgroud)