Add additional ordered bundles to a DynamicFolderBundle?

吃可爱长大的小学妹 提交于 2019-12-13 18:39:47

问题


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

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