如何给出相关性列表道场建设成一个单一的文件,? [英] How to build Dojo into a single file, given a list of dependencies?

查看:113
本文介绍了如何给出相关性列表道场建设成一个单一的文件,?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个简单的Dojo应用程序,那不只有一个要求通话,加载所有的依赖关系。麻烦的是,虽然这是非常简单的,但它仍然从服务器结束加载〜100个文件。我试图解决使用Dojo构建系统的问题,但似乎我没有足够深刻的理解。

I have a simple Dojo application, that does only one require call, loading all the dependencies. The trouble is, while it is extremely simple, it still ends up loading ~100 files from server. I tried to solve that problem using Dojo build system, but seems I don't have a deep enough understanding.

所以我的问题是 - 给相关性列表,如下所示:

So my question is - given a list of dependencies, like the following:

["dojo/parser",
 "dijit/registry",
 "dojo/dom",
 "dojo/on",
 "dojo/query",
 "dojo/dom-class",
 "dojo/request",
 "dijit/form/ValidationTextBox", 
 "dijit/form/Select",
 "dijit/form/NumberSpinner",
 "dijit/form/CheckBox",
 "dijit/layout/ContentPane",
 "dijit/Dialog",
 "dojo/NodeList-traverse",
 "dojo/domReady"]

我该如何设置构建创建一个单一的文件(或几个文件,只是没有100文件)道场文件?

how do I set up the build to create a single-file (or several-file, just not 100-file) dojo file?

推荐答案

如果你使用Dojo的要求()装载机,还有的构建工具中,您可以使用文件和缩小结合起来。据现场,构建工具不包含在正式发布,所以你必须从让他们开发版(尤其是查找在 buildscripts 目录)。

If you're using Dojo's require() loader, there are build tools that you can use to combine files and minify. According to the site, the build tools aren't included in an official release, so you'll have to get them from the development version (specifically, look in the buildscripts directory).

在Dojo文档包含其构建系统的一些信息,你也可以找到有用的。

The Dojo documentation contains some info on its build system that you may also find useful.

作为概念的证明,这里是我采取的步骤:

As a proof of concept, here are the steps I took:


  1. 转到下载页面和下载源Dojo Toolkit的SDK(它是唯一一个包含所需的构建使用util脚本)。

  1. Go to the download page, and download the Source Dojo Toolkit SDK (it's the only one that contains the util scripts needed for a build).

解压缩到一个位置(这个职位的缘故,让我们说这是的/ opt /道场的工具包)。

Extract to a location (for the sake of this post, let's say it's /opt/dojo-toolkit).

从Dojo工具包目录的(即的/ opt /道场的工具包),运行生成UTIL: ./ UTIL / buildscripts / build.sh行动=释放htmlFiles = /路径/要/我的/ index.html的(小心,这放慢我5岁的双核到爬行)

From the Dojo toolkit directory (i.e. /opt/dojo-toolkit), run the build util: ./util/buildscripts/build.sh action=release htmlFiles=/path/to/my/index.html (careful, this slowed my 5-year-old dual-core to a crawl)

index.html的(这是完全道场的工具包目录中)的例子:

Example of index.html (this one is exactly inside the dojo-toolkit directory):

...
<head>
    <script src="dojo/dojo.js"></script>
    <script>
    dojo.require("my.test");
    </script>
</head>
...

要求()调用看起来嵌套模块(我无法得到它与一个顶层模块的工作),所以在这种情况下,我已经有一个我的 道场的工具包,其中包含的内部目录 test.js 文件。该文件是在加载所有依赖的主要引导文件。我只是把随机要求()调用我的:

The require() call looks for nested modules (I couldn't get it to work with a top-level module), so in this case, I've got a my directory inside of dojo-toolkit which contains a test.js file. That file is the main "bootstrap" file which loads in all of the dependencies. I just put random require() calls in mine:

dojo.require('dijit.ProgressBar');
dojo.require('dijit.Tree');

和应该这样做。基本上,运行针对您的HTML文件(即包含的dojo.js参考的)的构建工具可确保所有的相关性发现,从顶部开始。

And that should do it. Basically, running the build utility against your HTML file (the one that contains the reference to dojo.js) makes sure that all of the dependencies are found, starting from the top.

注意的:构建系统创建一个发布目录与内置的输出,但它看起来有点误导起初 - 它似乎有精缩每个单独的文件,但如果你看看你的实际的引导文件(我/ test.js ,在这种情况下),这将是一个组合,缩小的有(我的文件presume),你需要运行你的应用程序的一切。

Note: the build system create a release directory with the built output, but it looks a little misleading at first - it appears to have minified each individual file, but if you look at your actual bootstrap file (my/test.js, in this case), it will be a combined, minified file with (I presume) everything you need to run your app.

否则,如果你使用AMD的风格需要()的(如require.js),你可以使用它的优化工具。据该网站,它会:

Otherwise, if you're using AMD style require()'s (as in require.js), you can use its optimization tool. According to the site, it will:


  1. 将所有相关文件(包括require.js本身)到一个文件中。分析了要求()打电话找出哪些文件需要结合起来。

  1. Combine all dependent files (including require.js itself) into a single file. It analyzes the require() call to figure out which files it needs to combine.

压缩JavaScript使用或者UglifyJS(默认)或关闭编译器。

Minify your JavaScript using either UglifyJS (default) or Closure Compiler.

这篇关于如何给出相关性列表道场建设成一个单一的文件,?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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