运行ASP.. NET MVC 4应用在发布模式下不会捆绑和最小化js文件



当我运行我的ASP。. NET MVC 4应用在release模式下,bundle仍然输出未被压缩的独立js文件,而不是将其打包并压缩成更少的JavaScript文件。

任何想法?

仅供参考,发布配置:

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

由于aleyush的评论,Web.release.config仅在发布应用程序期间使用,而不是在本地运行时,我能够通过向BundleConfig.cs文件添加以下行来修复它:

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

由于调试模式将定义DEBUG常数,而在发布模式下没有定义,因此这一行只在发布模式下执行。(您可以通过设置断点来测试它)

  1. 如果debug在Web中设置为true,则没有任何内容被捆绑或缩小。

  2. 如果你想覆盖它,只需在你的bundlecconfig文件中添加以下代码行:

    BundleTable。enableoptimization = true;

这对我有用

<system.web>
    <compilation debug="false" />
</system.web>

我的包太大了我不得不把它分解成更小的部分,它工作得很好。可能一些变量在缩小后发生冲突。

把这行放在你的bundlecconfig的末尾,只用于测试…

BundleTable.EnableOptimizations = true;

如果您打开缩小的文件,您将看到如下内容:

    /* Minification failed. Returning unminified contents.
    (5079,1-2): run-time warning JS1195: Expected expression: .
    (5080,18-19): run-time warning JS1004: Expected ';': :
    (5084,18-19): run-time warning JS1004: Expected ';': :
    (5091,18-19): run-time warning JS1004: Expected ';': :
    (5095,20-21): run-time warning JS1197: Too many errors. The file might not be a JavaScript file: ;
.....

分解你的bundle,你可以隔离问题。

希望这可以帮助别人。

最新更新