Add multiple bundles inside one package in C # MVC

As an example, I want to create packages 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 if I can add a link to any file inside the package that physically exists on any site server For example: I want to add a google font file inside the package as I write below

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

      

+3


source to share


2 answers


For multi-linked, you can write:

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

      

+12


source


To add a subdirectory with all its contents, you can use another overload of the IncludeDirectory () method, which is also configured to search and add all subfolders.



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

      

0


source







All Articles