在c# MVC的一个Bundle中添加多个Bundle
本文关键字:Bundle 添加 一个 MVC | 更新日期: 2023-09-27 18:06:11
例如我想创建这样的bundle
/*These are my Two separate Bundles*/
bundles.Add(new StyleBundle("~/Content/MYBundle1").Include(
"~/Content/css/style.css"));
bundles.Add(new StyleBundle("~/Content/MYBundle2").Include(
"~/Content/css/media.css"));
/*Now i want to use above two bundles as a single bundle */
bundles.Add(new StyleBundle("~/Content/AllPageBundles").Include(
"~/Content/MYBundle1",
"~/Content/MYBundle2")
我还想问,我可以在任何站点服务器上物理存在的捆绑包中添加任何文件的引用吗例如:我想在一个bundle中添加google字体文件,就像我在下面写
bundles.Add(new StyleBundle("~/Content/MYBundle1").Include(
"http://fonts.googleapis.com/css?family=Open+Sans:300"));
对于多个bundle,你可以这样写:
目录: bundles.Add(new Bundle("~/js/core").IncludeDirectory(@"~/Scripts/Infrastructure/JQuery", "*.js")
.IncludeDirectory(@"~/Scripts/Infrastructure/Knockout", "*.js")
.IncludeDirectory(@"~/Scripts/Infrastructure", "*.js"));
为文件: bundles.Add(
new Bundle("~/js/kendo").Include("~/Scripts/kendo/kendo.core.min.js")
.Include("~/Scripts/kendo/kendo.data.min.js")
.Include("~/Scripts/kendo/kendo.binder.min.js")
.Include("~/Scripts/kendo/kendo.calendar.min.js")
对于url,试试下面的代码:
var jqueryCdnPath = "http://fonts.googleapis.com/css?family=Open+Sans:300";
bundles.Add(new ScriptBundle("myfoobundle", jqueryCdnPath).Include("~/Scripts/jquery-{version}.js"));
要添加包含所有内容的子目录,您可以使用另一个重载IncludeDirectory()方法,该方法设置为搜索&添加所有子文件夹。
bundles.Add( new Bundle( "~/js/core" ).IncludeDirectory(
@"~/Scripts/Infrastructure/JQuery", "*.js", true ) );