5

I was wondering if there were any VS 2010 extensions out there for triggering the requirejs optimization similar to how squishit works:

  • When in debug mode, module files stay separate
  • When in release mode, modules files get minified and combined
drogon
  • 1,785
  • 3
  • 21
  • 34

1 Answers1

0

Edit: We use VS2012, but the general principle should work

While this isn't a direct answer to your question, this is the work around that we came up with:

Create a module for the files that you want to have minimized and bundled. For the sake of discussion, call it base_module.

Create a script in your _layout.cshtml

function requireBaseModulesDebug(func) {
    // In debug mode, just execute the call back directly.
    // Do not load any base modules, require each module to fully state any dependencies.
    func();
}

function requireBaseModulesRelease(func) {
    require(["js_modules/base_module"], func);
}


// Views are always in DEBUG mode, so we have to this this work-around.
@if (HttpContext.Current.IsDebuggingEnabled)
{
    <text>requireBaseModules = requireBaseModulesDebug;</text>
} 
else
{
    <text>requireBaseModules = requireBaseModulesRelease;</text>
}

With that script created, you then have to wrap anything that would use a module like this:

// If you are in DEBUG mode, requireBaseModules won't do anything
// But, if you are in a release mode, then requireBaseModules will load your
// bundled module and have them primed. Any modules required but NOT in your
// base bundle will be loaded normally.
requireBaseModules(function () {
    require(['jQuery'], function ($) {
      // Do Stuff
    });
});
Jeremy J Starcher
  • 23,369
  • 6
  • 54
  • 74