问题
I have a DynamicFoldewrBundle
:
bundles.Add(new DynamicFolderBundle("userScripts", "*.js", true, new JsMinify()));
So If I run :
http://optimization.localtest.me/files/templates/designs/HelloTreble/userScripts
...It will render all Javascript files bundled and minified in the HelloTreble
folder.
OK.
Question :
But how can I add custom ordered bundles to DynamicFolderBundle
?
I have tried this :
bundles.Add(new DynamicFolderBundle("userScripts", "*.js",new JsMinify())
.Include("~/Scripts/A.js").Include("~/Scripts/B.js"))
Which does work.
But the output is :
- First : A.JS
- Second : B.js
- Third : [All
HelloTreble
's js files , minified]
(In one file of course)
But what I'm really after is :
- First : [All
HelloTreble
's js files , minified] - Second : A.js
- Third : B.js
(In one file of course)
回答1:
You can implement IBundleOrderer
interface like
public class MyBundleOrderer : IBundleOrderer
{
public IEnumerable<BundleFile> OrderFiles(BundleContext context, IEnumerable<BundleFile> files)
{
var list = new List<BundleFile>(files);
list.Reverse();
return list;
}
}
and then attach this to your DynamicFolderBundle
like
var myDynamicBundle = new DynamicFolderBundle("userScripts", "*.js",true,new JsMinify())
.Include("~/Scripts/bootstrap.js")
.Include("~/Scripts/respond.js");
myDynamicBundle.Orderer = new MyBundleOrderer();
bundles.Add(myDynamicBundle);
Your scripts will be rendered in order respond.js
, then bootstrap.js
, then your scripts in userScripts
bundle.
来源:https://stackoverflow.com/questions/32474440/add-additional-ordered-bundles-to-a-dynamicfolderbundle