c# MVC BundleConfig詳解
阿新 • • 發佈:2020-04-29
前言
因為有很多庫在.net core還沒有實現遷移,所以呢,我們有時候還是需要的。
這些事什麼意思呢?
舉一個例子:
bundles.Add(new StyleBundle("~/Content/css").Include(
"~/Content/bootstrap.css","~/Content/site.css"));
點進去看下解釋:
"~/Content/css"這個引數,為我們是提供一個虛擬路徑。
Include 這個方法,將裡面的引數對映到虛擬路徑上。
我們來到view/shared/_layout.cshtml看到這個:
//
// 摘要:
// Renders link tags for a set of paths.
//
// 引數:
// paths:
// Set of virtual paths for which to generate link tags.
//
// 返回結果:
// A HTML string containing the link tag or tags for the bundle.
我直接進去檢視其中的含義,其實就是從這個虛擬路徑中渲染link。
效果如下:
現在在這裡我們知道有一個好處就是可以控制好版本,然後呢,可以省去一大筆時間去寫相同的url。
當你打包後:
![](https://img2020.cnblogs.com/blog/1289794/202004/1289794-20200429110210665-349987020.png)
自動會幫你壓縮好。
關鍵屬性在:
<system.web>
<compilation debug="true" targetFramework="4.6.1"/>
<httpRuntime targetFramework="4.6.1"/>
</system.web>
debug="true"
如果設定為false就會壓縮。
我們再來看下我們release的配置。
<compilation xdt:Transform="RemoveAttributes(debug)" />
移除了debug屬性,那麼就會壓縮。