在 C# MVC 中的单个 Bundle 中添加多个 Bundle
Add multiple Bundles inside a single Bundle in C# MVC
例如,我想创建这样的捆绑包
/*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")
我还想问一下,我可以在任何站点服务器上物理存在的包中添加任何文件的引用吗
Example:I 想要在包中添加 google 字体文件,就像我在下面写的那样
bundles.Add(new StyleBundle("~/Content/MYBundle1").Include(
"http://fonts.googleapis.com/css?family=Open+Sans:300"));
对于多包你可以这样写:
对于目录:
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 ) );
例如,我想创建这样的捆绑包
/*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")
我还想问一下,我可以在任何站点服务器上物理存在的包中添加任何文件的引用吗 Example:I 想要在包中添加 google 字体文件,就像我在下面写的那样
bundles.Add(new StyleBundle("~/Content/MYBundle1").Include(
"http://fonts.googleapis.com/css?family=Open+Sans:300"));
对于多包你可以这样写:
对于目录:
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 ) );