当我在发布模式下运行我的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>
答案 0 :(得分:37)
感谢aleyush的评论Web.release.config
仅在发布应用时使用,而不是在本地运行时使用,我可以通过在BundleConfig.cs
中添加以下行来修复它文件:
#if !DEBUG
BundleTable.EnableOptimizations = true;
#endif
由于调试模式将定义DEBUG
常量,并且在释放模式期间未定义,因此该行仅在释放模式期间执行。 (您可以通过设置断点来测试它)
答案 1 :(得分:2)
如果在Web.config文件中将debug设置为true,则不会捆绑或缩小任何内容,以便您可以轻松调试输出。
如果要覆盖它,只需将以下代码行添加到BundleConfig文件中:
BundleTable.EnableOptimizations = true;
答案 2 :(得分:0)
这对我有用
<system.web>
<compilation debug="false" />
</system.web>
答案 3 :(得分: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: ;
.....
分解你的捆绑,你可以隔离问题。
希望这可能有助于某人。