Dojo构建 - > dojo.require();还需要吗 [英] Dojo build -> dojo.require(); still needed?
问题描述
这是我第一个dojo构建,所以请原谅我在这件事上的无知。
this was my first dojo build so please excuse my ignorance in this matter.
我刚刚从dojo构建系统创建了自定义构建,使用以下(非常简化)个人资料:
I've just created my custom build from dojo build system using the following (very simplified) profile:
dependencies = {
stripConsole: "normal",
layers: [
{
name: "../dijits/cx/dijitsCXbuild.js",
copyrightFile: "CopyrightCX.txt",
dependencies: [
"dojo.parser",
"dijit.dijit",
"dijit._Widget",
"dijit._Templated",
"dijit._Container",
"dojo.i18n",
"dojo.NodeList-fx",
"dojox.grid.cells",
"dojox.grid.DataGrid",
"dojox.layout.GridContainer",
"dijit.TitlePane",
"dijits.cx.TaskPanel",
"dijits.cx.Identify"
]
}
],
prefixes: [
[ "dijit", "../dijit" ],
[ "dojox", "../dojox" ],
[ "dijits.cx", "../dijits/cx" ]
]
}
...好吧,这一切都进行得很好,我收到了我所要求的一切的包裹。然后在我的webapp我包括以下
... well, it all proceeds fine and I get my own package with everything I requested. Then in my webapp I include the following
<script type="text/javascript">
djConfig = {
isDebug:false,
parseOnLoad:true,
locale:getLocale()
};
</script>
<script type="text/javascript" src="Lib/cxdojo/dojo/dojo.js"></script>
<script type="text/javascript" src="Lib/cxdojo/dijits/cx/dijitsCXbuild.js"></script>
...看起来很好,直到代码需要实例化第一个dijit,它失败了与臭名昭着的:dijits.cx。TaskPanel不是一个构造函数。
... looks ok, until the code needs to instantiate the first dijit and it fails with the notorious : "dijits.cx. TaskPanel is not a constructor."
我可以通过添加dojo.require()来摆脱这个问题,但这是我我将通过创建我自己的自定义构建来摆脱。任何想法,我做错了什么或为了避免'dojo.require()'行...我该怎么做...
感谢堆。
I can get rid of this problem by including the "dojo.require()" but that's something I though I'll get rid of by creating my custom own build. Any ideas of what am I doing wrong or what shall I do in order to avoid that 'dojo.require()' lines... thanks heaps.
推荐答案
您仍然需要在您的文件中的 dojo.require
。压缩的构建只是阻止 dojo.require
对文件进行GET请求,将所有文件连接到一个文件中并将其缩小。这样可以节省页面载入周期(现在我相信你已经看到了)。
You still need the dojo.require
in your file. The compressed build just prevents the dojo.require
from doing a GET request for the file that is required by concatenating all the files into one file and shrinking it. This saves cycles on page load quite a bit (as I'm sure you have seen by now).
如果你真的想摆脱许多 dojo.require
(我不是太疯狂,因为我喜欢看到页面中使用的内容),你可以这样做:
If you really want to get rid of the many dojo.require
(which I'm not too crazy about because I like seeing what's used in the page), you can do something like this:
dojo.provide('my.main');
dojo.require('dijit.cx.TaskPane');
... all the other dojo.require statements ...
然后将其放在一个与dojo平行的目录中的文件:
Then put this in a file in a directory parallel to dojo:
Lib/cxdojo/my/main.js
Lib/cxdojo/dojo/dojo.js
.. etc ...
然后将您的依赖项更改为:
Then change your dependencies to be:
dependencies: [
"my.main"
]
然后在您的文件中,您可以将其包含在脚本标签中:
Then in your file, you can include it with the script tag:
<script type="text/javascript" src="Lib/cxdojo/my/main.js"></script>
然后,您只需要一个需求:
Then, you only need one require:
dojo.require('my.main');
这种方法的另一个优点是您只需要更改一个文件(/ my / main。 js)当你添加一个模块到你的应用程序。
Another advantage of this approach is that you only need to change one file (the /my/main.js) when you add a module to your application.
这篇关于Dojo构建 - > dojo.require();还需要吗的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!