c# MVC BundleConfig詳解


前言

因為有很多庫在.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屬性,那么就會壓縮。


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM