2011-11-21 51 views

回答

2

您可以在構建文件中設置很多選項。在Github上查看完整的例子(https://github.com/jrburke/r.js/blob/master/build/example.build.js

你想要做的是排除你的模塊某些項目是什麼:

//This module entry combines all the dependencies of foo/bar/bip into one file, 
//but excludes foo/bar/bop and its dependencies from the built file. If you want 
//to exclude a module that is also another module being optimized, it is more 
//efficient if you define that module optimization entry before using it 
//in an exclude array. 
    { 
     name: "foo/bar/bip", 
     exclude: [ 
      "foo/bar/bop" 
     ] 
    }, 

//This module entry shows how to specify a specific module be excluded 
//from the built module file. excludeShallow means just exclude that 
//specific module, but if that module has nested dependencies that are 
//part of the built file, keep them in there. This is useful during 
//development when you want to have a fast bundled set of modules, but 
//just develop/debug one or two modules at a time. 
    { 
     name: "foo/bar/bin", 
     excludeShallow: [ 
      "foo/bar/bot" 
     ] 
    } 

您還可以排除使用正則表達式的項目,但是這可能是矯枉過正:

//When the optimizer copies files from the source location to the 
//destination directory, it will skip directories and files that start 
//with a ".". If you want to copy .directories or certain .files, for 
//instance if you keep some packages in a .packages directory, or copy 
//over .htaccess files, you can set this to null. If you want to change 
//the exclusion rules, change it to a different regexp. If the regexp 
//matches, it means the directory will be excluded. This used to be 
//called dirExclusionRegExp before the 1.0.2 release. 
//As of 1.0.3, this value can also be a string that is converted to a 
//RegExp via new RegExp(). 

fileExclusionRegExp: /^\./, 
+0

fileExclusionRegExp實際上非常有用,如果您將CoffeeScript編譯爲JS,並且因此不需要編譯目錄中的'.coffee'文件。 – Daniel