如何在 Electron 应用程序中使用 Dojo Toolkit? [英] How do I use Dojo Toolkit in an Electron application?

查看:12
本文介绍了如何在 Electron 应用程序中使用 Dojo Toolkit?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在探索 Electron,但遇到了障碍.我不知道如何加载 Dojo Toolkit 并在 Electron 中使用它.

I'm exploring Electron and I've run into a roadblock. I can't figure out how to load the Dojo Toolkit and use it in Electron.

例如,这里是 Dojo 的简单Hello World":

For example, here is the simple "Hello World" for Dojo:

<!DOCTYPE html>
<html>
<head>
    <title>Tutorial: Hello Dojo!</title>
</head>
<body>
    <h1 id="greeting">Hello</h1>
    <!-- load Dojo -->
    <script src="//ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js"
        data-dojo-config="async: true"></script>
    <script>
        require([
            'dojo/dom',
            'dojo/dom-construct'
        ], function (dom, domConstruct) {
            var greetingNode = dom.byId('greeting');
            domConstruct.place('<em> Dojo!</em>', greetingNode);
        });
    </script>
</body>
</html>

这在浏览器中可以正常工作,但在 Electron 中根本不起作用.经过几个小时的谷歌搜索并尝试了 50 种不同的实验,我一无所获.

That works fine in a browser, but doesn't work at all in Electron. After a couple hours of googling and trying 50 different experiments I've gotten nowhere.

有人可以赐教吗?

推荐答案

虽然您可以像 Shwany 所说的那样禁用 node-integration,但我相信这将有效地呈现 ipc模块无用,这可能会造成不良限制,因为您将无法在主进程和渲染器进程之间进行通信.

While you can disable node-integration as Shwany said, I believe that will effectively render the ipc modules useless, which will probably pose undesirable limitations since you won't be able to communicate between the main and renderer processes.

但是,有可能让 Dojo 与 Electron 配合得很好.在您的入口页面中您只需要做几件事.

However, it is possible, with a bit of finagling, to get Dojo to play nice with Electron. There are only a couple of things you need to do in your entry page.

首先,强制host-node 具有特征false.这可以通过在 dojoConfig.has 中设置来完成,例如:

Firstly, force the host-node has feature to false. This can be done by setting it in dojoConfig.has, e.g.:

var dojoConfig = {
    async: true,
    has: {
        'host-node': false
    }
}

其次,正如 Shwany 指出的,Dojo 将看到已经存在的 require,因此我们需要在加载 Dojo 之前将其移出:

Secondly, as Shwany pointed out, Dojo is going to see the already-existing require, so we need to move that out before loading Dojo:

// Move Electron's require out before loading Dojo
window.electronRequire = require;
delete window.require;

加载 dojo.js 后,如果您愿意,您可以将 Dojo 的 require 移到其他地方,并将 Electron 移到后面.您是否要这样做可能取决于您打算如何对应用程序的客户端进行编码.从表面上看,Dojo 的全局 require 从来不需要,因为您可以通过 'require' 模块 ID 在任何已定义的模块中请求上下文相关的 require.

After loading dojo.js, you can move Dojo's require elsewhere and move Electron's back, if you wish. Whether you want to do this may depend on how you intend to code the client side of your application. Ostensibly, Dojo's global require is never needed, since you can request a context-sensitive require in any defined module via the 'require' module ID.

如果您想查看包含 Dojo 的支架式 Electron 应用程序,我创建了一个 样板几周前(尽管被告知它目前依赖于电子包装器的一个分支).如果你想看一个更成熟的 Electron/Dojo 应用程序的例子,我写了一个音乐播放器,叫做 Nukebox 几个月前,它使用 Dojo 和 dgrid(尽管它的脚手架与较新的样板有点不同).

If you want to see a scaffolded Electron application incorporating Dojo, I created a boilerplate a few weeks ago (though be advised it's currently relying on a fork of electron-packager). If you want to see an example of a more full-blown Electron/Dojo application, I wrote a music player called Nukebox a couple of months ago which uses Dojo and dgrid (though its scaffolding is a bit different than the newer boilerplate).

这篇关于如何在 Electron 应用程序中使用 Dojo Toolkit?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆