15

当我在发布模式下运行我的 ASP.NET MVC 4 应用程序时,捆绑包仍在输出未缩小和单独的 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>
4

4 回答 4

38

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

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

由于 Debug 模式将定义DEBUG常量,而在 Release 模式期间未定义,因此该行将仅在 Release 模式期间执行。(你可以通过设置断点来测试它)

于 2013-06-30T10:16:19.690 回答
2
  1. 如果在 Web.config 文件中将 debug 设置为 true,则不会捆绑或缩小任何内容,以便您可以轻松调试输出。

  2. 如果您想覆盖它,只需将以下代码行添加到您的 BundleConfig 文件中:

    BundleTable.EnableOptimizations = true;

于 2013-03-01T14:08:18.287 回答
0

这对我有用

<system.web>
    <compilation debug="false" />
</system.web>
于 2013-11-12T15:33:22.443 回答
0

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

将此行放在 bundleconfig 的末尾仅用于测试...

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: ;
.....

分解你的捆绑包,你可以隔离问题。

希望这可以帮助某人。

于 2017-05-30T11:21:30.790 回答