javascript - RequireJS 优化器和 VS 2010 集成

标签 javascript visual-studio-2010 requirejs amd squishit

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

  • 在 Debug模式下,模块文件保持独立
  • 在 Release模式下,模块文件会被压缩和合并

最佳答案

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

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

为您想要最小化和捆绑的文件创建一个模块。为了便于讨论,将其称为 base_module

在您的 _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
    });
});

关于javascript - RequireJS 优化器和 VS 2010 集成,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9808792/

相关文章:

javascript - 使用 testdouble.js 替换 AMD 模块格式的依赖项

javascript - Uncaught ReferenceError : jQuery is not defined - requireJS

javascript - RequireJS 忽略了一些路径

javascript - 当我将数组索引存储为变量时,代码不起作用

javascript - EmberJS - 使用几个解决方案从外部调用组件方法(征集讨论)

c - 在 Visual Studio 2008 或 2010 中将 Lua 嵌入到 C 应用程序中

visual-studio-2010 - 如何判断我正在调试哪个进程(附加到多个进程)?

javascript - 删除 CSS onClick

javascript - 输入文本格式,Jquery,Javascript 或 Css

.net - Visual Studio 2010 - 本地历史功能?