How do I configure MVC's style bundling order?

后端 未结 2 1912
半阙折子戏
半阙折子戏 2020-12-29 05:05

My web app is using a large icon set with jquery-ui and jqgrid.
In order to easily maintain the changes to the CSS to accommodate the larger icons when upgrading jquery-

2条回答
  •  鱼传尺愫
    2020-12-29 05:48

    You can create your custom bundler and override OrderFiles method

    public class CustomBundleOrderer : IBundleOrderer
    {
        public IEnumerable OrderFiles(BundleContext context, IEnumerable files)
        {
            return files;
        }
    }
    

    then pass your css files in the order you would like them to be bundled

    var bundle = new StyleBundle("~/Content/dark-hive/allstyles")
    {
        Orderer = new CustomBundleOrderer()
    };
    
    bundle.Include(
        "~/Content/dark-hive/jquery-ui-1.8.23.custom.css",
        "~/Content/ui.jqgrid.css",
        "~/Content/jquery-ui-fixes.css",
        "~/Content/icons.css",
        "~/Content/site.css");
    
    bundles.Add(bundle);
    

提交回复
热议问题