[英]Running an ASP.NET MVC 4 app in release mode does not bundle and minifiy the js files
當我在發布模式下運行我的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>
感謝aleyush的評論, Web.release.config
僅在發布應用程序時使用,而不是在本地運行時使用,我可以通過在BundleConfig.cs
文件中添加以下行來修復它:
#if !DEBUG
BundleTable.EnableOptimizations = true;
#endif
由於調試模式將定義DEBUG
常量,並且在釋放模式期間未定義,因此該行僅在釋放模式期間執行。 (您可以通過設置斷點來測試它)
如果在Web.config文件中將debug設置為true,則不會捆綁或縮小任何內容,以便您可以輕松地調試輸出。
如果要覆蓋它,只需將以下代碼行添加到BundleConfig文件中:
BundleTable.EnableOptimizations = true;
這對我有用
<system.web>
<compilation debug="false" />
</system.web>
我的捆綁太大了。 我不得不把它分成更小的部分,它工作得很好。 也許某些變量在縮小后會發生沖突。
將此行放在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: ;
.....
分解你的捆綁,你可以隔離問題。
希望這可以幫助某人。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.