Multiple File Output

Mar 12, 2012 at 12:24 PM

Is it possible to output multiple input files into corresponding multiple output files? e.g.

jsfile1.js, jsfile2.js, jsfile3.js....to *-min.js, which would create jsfile1-min.js, jsfile2-min.js, jsfile3-min.js?

The documentation for YUI Compression (http://developer.yahoo.com/yui/compressor/#using) hints at this option but haven't seen an example with this library using it.

Thanks

Coordinator
Mar 12, 2012 at 1:25 PM

Hi,

Don't confuse the Java version of YUI Compressor with this .Net port - they may not offer exactly the same feature set, though the compressed data should be basically the same.

The documentation there does seem to hint at multi file output, though it might just be poorly worded :)

Having said that, you should be able to achieve what you want via the magic of msbuild.... something like this:

    <ItemGroup>
        <JsFiles Include="jsfile1.js "/>
        <JsFiles Include="jsfile2.js "/>
        <JsFiles Include="jsfile3" />
    </ItemGroup>
        
    <Target Name="Minify">
        <CompressorTask
            JavaScriptCompressionType="YuiStockCompression"
            JavaScriptFiles="@(JsFiles)"
            EncodingType="Default"
            DeleteJavaScriptFiles="false"
            LineBreakPosition="-1"
            JavaScriptOutputFile="%(JsFiles.Identity).min"
            ThreadCulture="iv"
            />
    </Target>

The key bit is the %(JsFiles.Identity) bit, which forces msbuild to iterate over the call once per JsFile.

HTH