5

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

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

1 回答 1

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
    });
});
于 2013-08-28T23:38:08.853 回答