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

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

问题描述

我正在探索电子,我遇到了一个路障。我不知道如何加载 Dojo工具包,并在Electron中使用它。



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

 <!DOCTYPE html> 
< html>
< head>
< title>教程:Hello Dojo!< / title>
< / head>
< body>
< h1 id =greeting> Hello< / h1>
<! - 加载Dojo - >
< script src =// ajax.googleapis.com/ajax/libs/dojo/1.10.4/dojo/dojo.js
data-dojo-config =async:true> ;< /脚本>
< 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次不同的实验,我已经无处可去了。



有人可以启发我吗?

解决方案

虽然您可以禁用节点集成作为Shwany说,我相信会有效地渲染 ipc 模块无用,这可能会造成不必要的限制,因为您无法在主渲染器和渲染器进程之间进行通信。



但是,有可能,有点迷惑,让Dojo和Electron玩得很好。



首先,强制主机节点具有 false 的功能。这可以通过在 dojoConfig.has 中设置来实现,例如:

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

其次,正如Shwany指出的,Dojo将会看到已经存在的要求 ,所以我们需要在加载Dojo之前移动它:

  //加载Dojo之前移动Electron的要求
window .electronRequire = require;
delete window.require;

加载dojo.js后,您可以在其他地方移动Dojo的要求,如果需要,可以将Electron移回。无论您想要这样做还可能取决于您打算如何编写应用程序的客户端。表面上看,Dojo的全球需要,因为您可以通过任何定义的模块请求上下文相关的 require 'require'模块ID。



如果要查看包含Dojo的脚手架电子应用程序,我创建了一个<几周前,href =https://github.com/kfranqueiro/electron-dojo-boilerplate =nofollow>样板(尽管建议目前依靠电子包装机的叉子) 。如果您想看到一个更全面的Electron / Dojo应用程序的例子,我写了一个名为 Nukebox < a>几个月前,它使用Dojo和dgrid(虽然它的脚手架与新的样板有点不同)。


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.

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>

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.

Can someone please enlighten me?

解决方案

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.

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.

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
    }
}

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;

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.

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).

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

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