问题
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