RequireJS Optimizer和VS 2010 Itegration

dro*_*gon 5 javascript amd visual-studio-2010 squishit requirejs

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

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

Jer*_*her 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>
}
Run Code Online (Sandbox Code Playgroud)

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

// 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
    });
});
Run Code Online (Sandbox Code Playgroud)