Asp.net

ASP.NET Bundles 如何禁用縮小

  • August 14, 2012

我的web.config(s)debug="true"都有,我只是不希望我的包被縮小,但我做的任何事情似乎都沒有禁用它。我試過了,這是我的程式碼:enableoptimisations=false

//Javascript
bundles.Add(new ScriptBundle("~/bundles/MainJS")
           .Include("~/Scripts/regular/lib/mvc/jquery.validate.unobtrusive.js*")
           .Include("~/Scripts/regular/lib/mvc/jquery.validate*")
           .Include("~/Scripts/regular/lib/bootstrap.js")
           .IncludeDirectory("~/Scripts/regular/modules", "*.js", true)
           .IncludeDirectory("~/Scripts/regular/pages", "*.js", true)
           .IncludeDirectory("~/Scripts/regular/misc", "*.js", true));

//CSS
bundles.Add(new StyleBundle("~/bundles/MainCSS")
           .Include("~/Content/css/regular/lib/bootstrap.css*")
           .IncludeDirectory("~/Content/css/regular/modules", "*.css", true)
           .IncludeDirectory("~/Content/css/regular/pages", "*.css", true))

如果您debug="true"web.config中使用並Scripts/Styles.Render用於引用頁面中的捆綁包,則應該關閉捆綁和縮小。BundleTable.EnableOptimizations = false將始終關閉捆綁和縮小(不管調試真/假標誌)。

您可能沒有使用Scripts/Styles.Render助手嗎?如果您通過直接渲染對捆綁包的引用,BundleTable.Bundles.ResolveBundleUrl()您將始終獲得縮小/捆綁的內容。

條件編譯指令是你的朋友:

#if DEBUG
           var jsBundle = new Bundle("~/Scripts/js");
#else
           var jsBundle = new ScriptBundle("~/Scripts/js");
#endif

引用自:https://stackoverflow.com/questions/11944745