RequireJS optimizer Ant task

build.xml文件

 1 <?xml version="1.0" encoding="utf-8"?>
 2 <project name="sample-require-js" default="" basedir=".">
 3     
 4     <!-- properties -->
 5     
 6     <property name="r.js" value="_build/rjs/r.js" />
 7     <property name="closure.jar" value="_build/closure/compiler.jar" />
 8     <property name="rhino.jar" value="_build/rhino/js.jar" />
 9     <property name="js.build" value="_build/js.build.js" />
10     <property name="css.build" value="_build/css.build.js" />
11     
12     <!-- custom tasks -->
13     
14     
15     <!-- targets -->
16     
17     <target name="-optimize" description="Combine and minify files.">
18         <java classname="org.mozilla.javascript.tools.shell.Main">
19             <classpath>
20                 <pathelement location="${rhino.jar}" />
21                 <pathelement location="${closure.jar}" />
22             </classpath>
23             <arg value="${r.js}"/>
24             <arg value="-o"/>
25             <arg value="${requirejs.optimizer.settings}"/>
26         </java>
27         <echo message="optimized ${requirejs.optimizer.settings}" />
28     </target>
29     
30     <target name="optimizeJS">
31         <echo message="Combining and minifying JS files." />
32         <antcall target="-optimize">
33             <param name="requirejs.optimizer.settings" value="${js.build}" />
34         </antcall>  
35     </target>
36     
37     <target name="optimizeCSS">
38         <echo message="Combining and compressing CSS files." />
39         <antcall target="-optimize">
40             <param name="requirejs.optimizer.settings" value="${css.build}" />
41         </antcall>  
42     </target>
43     
44 </project>

css.build.js

1 ({
2     baseUrl: "../style",
3     optimizeCss : "standard",
4     dir: "../deploy/style"
5 })

js.build.js

 1 ({
 2     baseUrl: "../scripts",
 3     dir: "../deploy/scripts",
 4     modules: [
 5         {
 6             name: "main",
 7             include : [
 8                 "lib/my_awesome_shared_lib"
 9             ]
10         },
11         {
12             name : "sections/home/main",
13             exclude : [
14                 "lib/my_awesome_shared_lib"
15             ]
16         },
17         {
18             name : "sections/gallery/main",
19             exclude : [
20                 "lib/my_awesome_shared_lib"
21             ]
22         }
23     ]
24 })

js.build.js

 1 ({
 2     baseUrl: "/app",
 3     name: "main",
 4     optimize: 'closure',
 5     out: "main-built.js",
 6     paths: {
 7         underscore:   '/libs/underscore/underscore-1.4.1.amd.min',
 8         backbone:     '/libs/backbone/backbone-0.9.2.amd',
 9         validation :  '/libs/backbone/backbone-validation-amd',
10         jquery:       'empty:',
11     },
12     shim: {
13         'underscore':   {exports: '_'},
14         'backbone':     {deps: ['underscore'],exports: 'Backbone'}
15     }
16 })

 

 

 

 

posted on 2012-11-23 13:52  稻草人.Net  阅读(1252)  评论(0编辑  收藏  举报