Search code examples
visual-studio-2010compressionminifycombres

Needed - Visual Studio Custom Build Actions To Minify JS and CSS


I've been using Combres in my applications to compress, combine and minify my javascript and css at run time. This works extremely well and satisfies YSlow perfectly.

Now I'm rethinking the whole process for performance reasons, and I'm more so thinking about doing all of this at build time instead of run time.

I'm hoping that I can get a little advice on how to do this without too much hassle. Is there an existing tool (similar to Combres) that can do what I need?


Solution

  • I originally used Chirpy to do my bundling, but have since moved over to Bundler. Bundler allows me to wire everything up nicely in a sexy build file (powershell) with relative ease. I've personally moved away from Visual Studio Build events, and started running the builds in a stand alone environment. This helps me with things like Github to Team City Continuous Integration (CI).

    Here's what your build file "could" look like. (note might not fully run, this is untested)


    build.ps1

    # Set up varriables for build script
    $invocation = (Get-Variable MyInvocation).Value
    $directorypath = Split-Path $invocation.MyCommand.Path
    $BundlerDir = "$directorypath\build_tools\bundler\"
    $AppRoot = "$directorypath\SomeApp.Web\"   
    $ScriptsDir = "scripts\"                                   
    $CssDir = "css\"                  
    
    # Run Bundler to Combine and Minify
    &($BundlerDir + "node.exe") ( $BundlerDir + "bundler.js") ($AppRoot +$CssDir) ($AppRoot + $ScriptsDir)
    
    # Everything else...
    #    Clean the bins
    #    Build the projects
    #    Run the tests