Add multiple Bundles inside a single Bundle in C# MVC

谁说我不能喝 提交于 2020-01-02 05:30:53

问题


For Example I Want to Create Bundles like this

/*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")

Also I want to ask that can i add reference of any file inside a bundle that is physically exist at any site server For Example:I want to add google fonts file inside a bundle like i write bellow

bundles.Add(new StyleBundle("~/Content/MYBundle1").Include(
               "http://fonts.googleapis.com/css?family=Open+Sans:300"));

回答1:


For multi-bundles you can write like:

For directories:

 bundles.Add(new Bundle("~/js/core").IncludeDirectory(@"~/Scripts/Infrastructure/JQuery", "*.js")
                                                     .IncludeDirectory(@"~/Scripts/Infrastructure/Knockout", "*.js")
                                                     .IncludeDirectory(@"~/Scripts/Infrastructure", "*.js"));

For files:

 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")

For url try this code:

var jqueryCdnPath = "http://fonts.googleapis.com/css?family=Open+Sans:300";
bundles.Add(new ScriptBundle("myfoobundle", jqueryCdnPath).Include("~/Scripts/jquery-{version}.js"));



回答2:


To add a sub directory with all it's content you can use another overload of IncludeDirectory() method that set to search & add all sub folders too.

bundles.Add( new Bundle( "~/js/core" ).IncludeDirectory( 
            @"~/Scripts/Infrastructure/JQuery", "*.js", true ) );


来源:https://stackoverflow.com/questions/31808092/add-multiple-bundles-inside-a-single-bundle-in-c-sharp-mvc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!