dojo中的build(或叫压缩)

前端之家收集整理的这篇文章主要介绍了dojo中的build(或叫压缩)前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

参考文章http://www.ibm.com/developerworks/cn/web/0912_shenjc_dojobuild/

1.工具在/dojo/util/buildscripts下,build.bat文件

命令:buildprofile=exampleaction=releasereleaseName=myDojooptimize=shrinksafe

Profile:指定build使用的profile文件profile文件需要放在/dojo/util/buildscripts/profiles中);

Action:指定本次命令类型,有三个值:cleanreleasehelp;

releaseName:本次release的名字,默认是dojo;

Optimize:本次build中进行优化的方式,一般使用shrinksage即可;

2.profiles文件

/* example.profile.js */ 
 dependencies = { 
 layers: [    // 可以根据需要制定多个不同的 layer 
 { 
 name: "example.js",// 打包生成的 js 文件的名
 dependencies: [       // 需要打包的 js 文件列表
"dojo.date","dojox.uuid"       
 ] 
 } 
 ],prefixes: [       // 设置路径
 [ "dijit","../dijit" ],[ "dojox","../dojox" ] 
 ] 
 }

3.文件所在位置:

在action/releaseName/dojo/中,有profile.js(已压缩的)和profile.uncompressed.js(未压缩)

本例文件是release/myDojo/dojo/example.js

4.附加个更高级的profile

/* example.profile.js */ 
 dependencies = { 
 layers: [ 
 {   // 这个 layer 用来打包我们定制的 dojo 文件
 name: "mydojo.js",dependencies: [       
"dojo.date","dojox.uuid"
 ] 
 },{  // 这个 layer 用于打包我们自己的 js 文件
 name: "example.js",dependencies: [       
"my.example1"
 ] 
 } 
 ],prefixes: [ 
 [ "dijit","../dojox" ],[ "my","../my"] 
 ] 
 }

-------------------------------------------分割线--------------------------------------------------------

以上内容其实已经太老了,而且对于初学者来说,写的还不够具体!最起码折磨我了两天!愤怒。今天我来完善一下,希望后来人不要再掉进这个坑里面。

dojo的官网有个create build的文章,写的比较权威,不过对于实战主义者来说,怎么写出来最重要,下面我把profile.js文件内容贴一下。

myapp.profile.js文件内容

var profile = (function(){
    return {
        basePath: "../../../../js",//相对于profile.js文件的路径,例如我喜欢把profile.js文件放在util->buildScript->profiles文件夹下
        releaseDir: "./app",//相对于basePath路径,现在basePath已经定位到js文件夹下
        releaseName: "lib",//在releaseDir文件加下,此处是app文件夹下创建个lib文件夹
        action: "release",layerOptimize: "closure",optimize: "closure",cssOptimize: "comments",mini: true,stripConsole: "warn",selectorEngine: "lite",defaultConfig: {
            hasCache:{
                "dojo-built": 1,"dojo-loader": 1,"dom": 1,"host-browser": 1,"config-selectorEngine": "lite"
            },async: 1
        },staticHasFeatures: {
            "config-deferredInstrumentation": 0,"config-dojo-loader-catches": 0,"config-tlmSiblingOfDojo": 0,"dojo-amd-factory-scan": 0,"dojo-combo-api": 0,"dojo-config-api": 1,"dojo-config-require": 0,"dojo-debug-messages": 0,"dojo-dom-ready-api": 1,"dojo-firebug": 0,"dojo-guarantee-console": 1,"dojo-has-api": 1,"dojo-inject-api": 1,"dojo-log-api": 0,"dojo-modulePaths": 0,"dojo-moduleUrl": 0,"dojo-publish-privates": 0,"dojo-requirejs-api": 0,"dojo-sniff": 1,"dojo-sync-loader": 0,"dojo-test-sniff": 0,"dojo-timeout-api": 0,"dojo-trace-api": 0,"dojo-undef-api": 0,"dojo-v1x-i18n-Api": 1,"extend-dojo": 1
        },packages:[{
            name: "dojo",location: "dojo"
        },{
            name: "dijit",location: "dijit"
        },{
            name: "dojox",location: "dojox"
        },{
            name: "cbtree",//这里可以放一些扩展包,比如你自己的包
            location: "cbtree"
        }],layers: {
            "dojo/dojo": {
                include: [ 
							"dojo/dojo","dojo/i18n","dijit/registry","dojo/ready","dijit/Tree","dijit/form/CheckBox","dojo/store/Memory",// basic dojo/store
							 "cbtree/Tree",// CheckBox tree
							 "cbtree/model/TreeStoreModel",// ObjectStoreModel
							 "dijit/layout/BorderContainer","dojox/layout/ContentPane","dijit/layout/TabContainer","dojo/store/JsonRest","dojo/store/Observable",'dojo/_base/array',"dojo/request/xhr","dojo/on","dojox/grid/EnhancedGrid","dojo/data/ItemFileWriteStore","dojo/dom","dojo/parser","dojo/domReady" 
							],customBase: true,boot: true
            }
        }
    };
})();

然后打开cmd->cd到util/buildScripts/文件夹下,

运行:build.bat --profile ./profiles/myapp.profile.js

然后来杯咖啡!

控制台会有一堆的输出,最后,会显示error或者其他信息

**************************************************非常重要*****************************************************************

关键的关键来了!程序会在js的文件夹下生成app/lib/。。。包,此时把生成的dojo,dijit,dojox文件拷贝到项目里面,然后引用生成的dojo.js文件即可。

我之前一直以为,dojo build之后生成的dojo,dijit, dojox等文件不用复制进项目里面,而仅仅是将dojo.js这一个文件拷贝到项目就可以了,但是事件告诉我们这样不行,需要将生成的几个文件一同放在项目中。

原文链接:https://www.f2er.com/dojo/291015.html

猜你在找的Dojo相关文章