gpt4 book ai didi

asp.net - ScriptBundle 在 Debug模式下添加完整文件和缩小文件

转载 作者:行者123 更新时间:2023-12-01 11:42:19 26 4
gpt4 key购买 nike

我在 BundleConfig.cs 中定义了以下 ScriptBundle-

    public class BundleConfig
{
public static void RegisterBundles(BundleCollection bundles)
{
bundles.Add(new ScriptBundle("~/js/yepnope").Include(
"~/Scripts/yepnope.{version}.js"));
}
}

它实际上并不是唯一的 bundle ,但这就是与问题相关的所有内容 - 其余只是其他 bundle 定义。

当处于 web.config 中设置的“调试”模式时-

<compilation debug="true" targetFramework="4.5">

脚本的完整版和精简版都被发送到浏览器-

<script src="/Scripts/yepnope.1.5.4-min.js"></script>
<script src="/Scripts/yepnope.1.5.4.js"></script>

脚本是使用 HTML 助手添加的,就像这样-

@section HeadScripts
{
@Scripts.Render("~/js/yepnope")
}

这是一个在 Windows 7 Professional 64 位 Visual Studio 2012 中运行的 MVC4 项目。

无论我做什么,我都无法让 {version} 通配符按照 Microsoft documentation 中的描述进行操作-

Note: Unless EnableOptimizations is true or the debug attribute in the compilation Element in the Web.config file is set to false, files will not be bundled or minified. Additionally, the .min version of files will not be used, the full debug versions will be selected.

For ASP.NET MVC 4, this means with a debug configuration, the file jquery-1.7.1.js will be added to the bundle. In a release configuration, jquery-1.7.1.min.js will be added. The bundling framework follows several common conventions such as:

  • Selecting “.min” file for release when “FileX.min.js” and “FileX.js” exist.
  • Selecting the non “.min” version for debug.
  • Ignoring “-vsdoc” files (such as jquery-1.7.1-vsdoc.js), which are used only by IntelliSense.

The {version} wild card matching shown above is used to automatically create a jQuery bundle with the appropriate version of jQuery in your Scripts folder. In this example, using a wild card provides the following benefits:

  • Allows you to use NuGet to update to a newer jQuery version without changing the preceding bundling code or jQuery references in your view pages.
  • Automatically selects the full version for debug configurations and the ".min" version for release builds.

如果我添加“EnableOptimizations”,它的行为似乎符合预期。

有没有其他人注意到这个或找到解决方案?

最佳答案

MVC4 只知道如何处理 .min.js 文件。它无法识别 -min.js(带破折号)。

我通常很容易成功地做到这一点的方法是摆脱库提供的任何 .min.js-min.js 文件一个 .js 和一个 .min.js-min.js。默认情况下,MVC 会在您部署网站时自动缩小所有捆绑的 .js 文件,因此无需使用提供的 .min.js-min .js 文件。

这不一定是对您的特定问题的直接回答 - 这是一种完全规避问题的方法。

关于asp.net - ScriptBundle 在 Debug模式下添加完整文件和缩小文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18663378/

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