gpt4 book ai didi

javascript - RequireJS 优化器和 VS 2010 集成

转载 作者:搜寻专家 更新时间:2023-11-01 04:42:40 24 4
gpt4 key购买 nike

我想知道是否有任何 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com