ScriptBundle将在调试模式下完全和缩小的文件 [英] ScriptBundle adding both full and minified file in debug mode

查看:106
本文介绍了ScriptBundle将在调试模式下完全和缩小的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有以下ScriptBundle在BundleConfig.cs定义 -

I have the following ScriptBundle defined in BundleConfig.cs-

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

这其实也不是唯一的包,但是这是所有在那里是相关的问题 - 剩下的只是其他软件包定义

It isn't in fact the only bundle, but that is all in there that is pertinent to the question - the rest is just other bundle definitions.

当作为在web.config中设置调试模式 -

When in "debug" mode as set in the web.config-

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

这两个脚本的完整和缩小的版本发送到浏览器 -

Both the full and minified versions of the script are sent to the browser-

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

该脚本使用HTML帮助像这样加 -

The script is added using the HTML helper like so-

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

这是在Windows 7专业版64位。

This is an MVC4 project running in Visual Studio 2012 on Windows 7 Professional 64-bit.

无论我做什么我不能得到的{}版本通配符来作为的微软文档 -

Whatever I do I cannot get the {version} wildcard to behave as described in the Microsoft documentation-

注:除非EnableOptimizations是真实的还是在调试属性
  在Web.config文件编译元素设置为false,文件
  不会被捆绑或缩小的。此外,的.min版本
  文件将不被使用,全部调试版本将被选中

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.

有关ASP.NET MVC 4,这意味着调试配置,文件
  的jquery-1.7.1.js将被添加到该包。在释放
  配置,jQuery的,1.7.1.min.js将增加。捆绑
  框架如下几种常见的约定,如:

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:


      
  • 选择.min文件发布时,FileX.min.js和FileX.js
      存在

  •   
  • 选择用于调试非.min版本

  •   
  • 忽略-vsdoc
      文件(如jquery的-1.7.1-vsdoc.js),它仅由用
      智能感知。

  •   
  • 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.

上面显示的版本{}通配符匹配来
  自动创建相应版本的一个jQuery捆绑
  jQuery的在脚本文件夹中。在这个例子中,使用的是外卡
  提供了以下好处:

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:


      
  • 允许使用的NuGet更新到新版本的jQuery无
      改变preceding捆绑在你看来code或引用的jQuery
      页面。

  •   
  • 自动选择完整版的调试配置
      和.min版本发布版本。

  •   
  • 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它似乎像预期的那样。

If I add "EnableOptimizations" it seems to behave as expected.

有其他人注意到这一点,或找到了解决办法?

Has anyone else noticed this or found a solution?

推荐答案

MVC4只知道如何处理 .min.js 文件。它不承认 -min.js (用破折号)。

MVC4 only knows how to handle a .min.js file. It doesn't recognize -min.js (with a dash).

我通常这样做,可以方便地成功的方法,就是要摆脱任何 .min.js -min.js 由提供图书馆提供的文件既是的.js 以及一个 .min.js -min.js 。默认情况下,当你部署你的网站MVC会自动运行如下捆绑任何的.js 文件,所以没有必要使用提供的 .min.js -min.js 文件。

The way I typically do this, with easy success, is to get rid of any .min.js or -min.js files provided by libraries that provide both a .js and either a .min.js or -min.js. By default, MVC will automatically minify any bundled .js files when you deploy your website, so there's no need to use the provided .min.js or -min.js files.

这不一定是直接回答您的特定问题 - 这是完全绕过这个问题的方法。

This isn't necessarily a direct answer to your particular question - it's a way to circumvent the problem entirely.

这篇关于ScriptBundle将在调试模式下完全和缩小的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆