跑在释放模式的ASP.NET MVC应用程序4不捆绑和minifiy的js文件 [英] Running an ASP.NET MVC 4 app in release mode does not bundle and minifiy the js files

查看:138
本文介绍了跑在释放模式的ASP.NET MVC应用程序4不捆绑和minifiy的js文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我运行我的ASP.NET MVC应用程序4中的发布的模式下,包还在输出unminified和独立的js文件,而不是捆绑,并将其与缩小到更少的捆绑JavaScript文件。

任何想法?

仅供参考,释放配置:

<?XML版本=1.0&GT?;
<结构的xmlns:XDT =htt​​p://schemas.microsoft.com/XML-Document-Transform>
  <&的System.Web GT;
    <编译XDT:转换=RemoveAttributes(调试)/>
  < /system.web>
< /结构>


解决方案

由于aleyush的评论发布在应用过程中 Web.release.config 只使用,不本地运行它的时候,我能够通过添加以下行到 BundleConfig.cs 文件来解决它:

#如果!DEBUG
BundleTable.EnableOptimizations = TRUE;
#万一

由于调试模式将定义 DEBUG 不变,并在释放模式下,它是没有定义,这条线将只在发行模式下执行。 (您可以通过设置断点测试)

When I run my ASP.NET MVC 4 app in release mode, the bundles are still outputting the unminified and separate js files, instead of bundling and minifying it into fewer bundled JavaScript files.

Any ideas?

FYI, release config:

<?xml version="1.0"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
  <system.web>
    <compilation xdt:Transform="RemoveAttributes(debug)" />
  </system.web>
</configuration>

解决方案

Thanks to aleyush's comment that Web.release.config is only used during publishing the app, and not when running it locally, I was able to fix it by adding the following lines to the BundleConfig.cs file:

#if !DEBUG
BundleTable.EnableOptimizations = true;
#endif

Since Debug mode will define the DEBUG constant, and during Release mode it is not defined, this line will only execute during Release mode. (you can test it by setting a breakpoint)

这篇关于跑在释放模式的ASP.NET MVC应用程序4不捆绑和minifiy的js文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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