RequireJS Optimizer和VS 2010集成

时间:2012-03-21 16:27:51

标签: javascript visual-studio-2010 requirejs amd squishit

我想知道是否有任何VS 2010扩展用于触发requirejs优化,类似于squishit的工作方式:

  • 处于调试模式时,模块文件保持独立
  • 在发布模式下,模块文件缩小并合并

1 个答案:

答案 0 :(得分:0)

编辑:我们使用VS2012,但一般原则应该有效

虽然这不是您问题的直接答案,但这是我们提出的解决方法:

为要最小化和捆绑的文件创建模块。为了便于讨论,请将其命名为base_module

script

中创建_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>
}

创建该脚本后,您必须包装任何使用此类模块的内容:

// 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
    });
});