Host mode files separately from Ace Editor

老子叫甜甜 提交于 2019-12-12 10:56:23

问题


I want to bundle ACE Editor with the desktop application and render it inside WebView. Ace is running from file:/// protocol. Is there any way to host Mode files separately from ace.js? For example ace.js will be located inside the application bundle /Application/MyApp.app/..., but mode files at ~/Library/Application Support/MyApp/ace/modes.

I started with test project and have the following code

<script type="text/javascript">
    var require = {
        baseUrl: window.location.protocol + "//" + window.location.host
                + window.location.pathname.split("/").slice(0, -1).join("/"),
        paths: {
            "ace/mode": "/Users/user/ace-build",
        }
    };
</script>
<script type="text/javascript" src="require.js"></script>
<script type="text/javascript" src="ace/ace.js"></script>
<script type="text/javascript">
    require(["ace/ace"], function(ace){
        var editor = ace.edit("editor-container");
        editor.getSession().setUseWorker(false);
        editor.setTheme("ace/theme/xcode");
        editor.getSession().setMode("ace/mode/javascript");
    });
</script>

I expect that module ace/mode/javascript will be loaded from /Users/user/ace-build/javascript but it loads from ace/mode-javascript.js. How to make modes loading from different location?


回答1:


use

require("ace/config").set("modePath", require.toUrl("ace/mode"))

if ext-* and other files are in the same folder you can do .set("basePath", ..) instead



来源:https://stackoverflow.com/questions/17507618/host-mode-files-separately-from-ace-editor

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!