requirejs实验002. r.js合并文件. 初体验.

时间:2022-08-16 16:36:54

requirejs的官网上有介绍如何使用r.js合并,压缩文件的.http://requirejs.org/docs/optimization.html

https://github.com/jrburke/r.js/blob/master/build/example.build.js 这里罗列了所有的优化参数.

我是在win7上使用r.js的. 安装使用的是npm ->  npm install -g requirejs  安装在全局,更合适,方便在任何地方使用.

windows上使用r.js有点微小不同. r.js -> r.js.cmd

我采用建立一个配置文件build.js来存放优化参数. 使用的是requirejs实验001中的项目. 如下:

({
baseUrl: '.',
// paths: {
// jquery: 'some/other/jquery'
// },
map: {
'b': {
'a': 'a.1.0'
},
'c': {
'a': 'a.1.1'
}
},
name: 'main',
out: 'main-built.js'
})

因为main.js中有配置map,所以build.js中也要配置map,否则...得不到正确的结果.

然后就是调用 r.js.cmd 来执行优化了.

 r.js.cmd -o build.js optimize=none

optimize=none 表示只合并文件不压缩.

C:\wxg\test\requirejs\demo3\js
λ r.js.cmd -o build.js optimize=none Tracing dependencies for: main C:/wxg/test/requirejs/demo3/js/main-built.js
----------------
C:/wxg/test/requirejs/demo3/js/a.1.0.js
C:/wxg/test/requirejs/demo3/js/util.js
C:/wxg/test/requirejs/demo3/js/b.js
C:/wxg/test/requirejs/demo3/js/a.1.1.js
C:/wxg/test/requirejs/demo3/js/c.js
C:/wxg/test/requirejs/demo3/js/main.js

zrender-demo

C:\wxg\test\zrender\demo\js
λ r.js.cmd -o build.js optimize=none Tracing dependencies for: main C:/wxg/test/zrender/demo/js/main-built.js
----------------
C:/wxg/test/zrender/demo/js/../../libs/zrender/src/dep/excanvas.js
C:/wxg/test/zrender/demo/js/../../libs/zrender/src/tool/util.js
C:/wxg/test/zrender/demo/js/../../libs/zrender/src/config.js
C:/wxg/test/zrender/demo/js/../../libs/zrender/src/tool/log.js
C:/wxg/test/zrender/demo/js/../../libs/zrender/src/tool/guid.js
C:/wxg/test/zrender/demo/js/../../libs/zrender/src/tool/env.js
C:/wxg/test/zrender/demo/js/../../libs/zrender/src/mixin/Eventful.js
C:/wxg/test/zrender/demo/js/../../libs/zrender/src/tool/event.js
C:/wxg/test/zrender/demo/js/../../libs/zrender/src/tool/vector.js
C:/wxg/test/zrender/demo/js/../../libs/zrender/src/tool/matrix.js
C:/wxg/test/zrender/demo/js/../../libs/zrender/src/Handler.js
C:/wxg/test/zrender/demo/js/../../libs/zrender/src/tool/curve.js
C:/wxg/test/zrender/demo/js/../../libs/zrender/src/tool/area.js
C:/wxg/test/zrender/demo/js/../../libs/zrender/src/mixin/Transformable.js
C:/wxg/test/zrender/demo/js/../../libs/zrender/src/tool/color.js
C:/wxg/test/zrender/demo/js/../../libs/zrender/src/shape/Base.js
C:/wxg/test/zrender/demo/js/../../libs/zrender/src/shape/Text.js
C:/wxg/test/zrender/demo/js/../../libs/zrender/src/shape/Rectangle.js
C:/wxg/test/zrender/demo/js/../../libs/zrender/src/loadingEffect/Base.js
C:/wxg/test/zrender/demo/js/../../libs/zrender/src/Layer.js
C:/wxg/test/zrender/demo/js/../../libs/zrender/src/shape/Image.js
C:/wxg/test/zrender/demo/js/../../libs/zrender/src/Painter.js
C:/wxg/test/zrender/demo/js/../../libs/zrender/src/Group.js
C:/wxg/test/zrender/demo/js/../../libs/zrender/src/Storage.js
C:/wxg/test/zrender/demo/js/../../libs/zrender/src/animation/easing.js
C:/wxg/test/zrender/demo/js/../../libs/zrender/src/animation/Clip.js
C:/wxg/test/zrender/demo/js/../../libs/zrender/src/animation/Animation.js
C:/wxg/test/zrender/demo/js/../../libs/zrender/src/zrender.js
C:/wxg/test/zrender/demo/js/../../libs/zrender/src/animation/animation.js
C:/wxg/test/zrender/demo/js/../../libs/zrender/src/shape/Circle.js
C:/wxg/test/zrender/demo/js/main.js