Ordering of Files within a bundle - What are the known libraries?

若如初见. 提交于 2019-11-27 06:42:28

问题


In Bundling and Minification, I've known that the bundler will move around certain known file types -- so that things like jQuery will be moved to the front.

By default, when files are bundled by ASP.NET they are sorted alphabetically first, just like they are shown in Solution Explorer. Then they are automatically shifted around so that known libraries and their custom extensions such as jQuery, MooTools and Dojo are loaded before anything else. -source

But after reading this recent question: ASP.NET MVC - Bundle Config order, which shows how a file is getting moved by the bundler even when the user has specified the load order, I realized I didn't know WHAT these known file types are, or the ORDER they will be listed in.

I've never seen a list explaining this, and in searching, I came up with nothing.

Is there a list the shows what the known file types are and the order they will be rendered in? I would think this is something the ASP.NET team should provide developers as a resource.


回答1:


Its in the doc comments for BundleCollection.AddDefaultFileOrderings:

    /// <summary>
    /// Add default file ordering for common popuular script and style libraries.
    /// </summary>
    /// <param name="list">A collection of <see cref="BundleFileSetOrdering"/> objects to populate with default values.</param>
    /// <remarks>
    /// The purpose for applying these default file ordering values is to ensure that common libraries such as jquery are always located 
    /// at or close to the top within a bundle. These values can be all removed with <see cref="ResetAll"/>.
    /// 
    /// The default ordering values are as follows:
    /// <list type="bullet">
    ///     <item><description>reset.css</description></item>
    ///     <item><description>normalize.css</description></item>
    ///     <item><description>jquery.js</description></item>
    ///     <item><description>jquery-min.js</description></item>
    ///     <item><description>jquery-*</description></item>
    ///     <item><description>jquery-ui*</description></item>
    ///     <item><description>jquery.ui*</description></item>
    ///     <item><description>jquery.unobtrusive*</description></item>
    ///     <item><description>jquery.validate*</description></item>
    ///     <item><description>modernizr-*</description></item>
    ///     <item><description>dojo.*</description></item>
    ///     <item><description>mootools-core*</description></item>
    ///     <item><description>mootools-*</description></item>
    ///     <item><description>prototype.js</description></item>
    ///     <item><description>prototype-*</description></item>
    ///     <item><description>scriptaculous-*</description></item>
    ///     <item><description>ext.js</description></item>
    ///     <item><description>ext-*</description></item>
    /// </list>
    /// </remarks>
    public static void AddDefaultFileOrderings(IList<BundleFileSetOrdering> list) {
        if (list == null) {
            throw new ArgumentNullException("list");
        }

        BundleFileSetOrdering css = new BundleFileSetOrdering("css");
        css.Files.Add("reset.css");
        css.Files.Add("normalize.css");
        list.Add(css);

        BundleFileSetOrdering jquery = new BundleFileSetOrdering("jquery");
        jquery.Files.Add("jquery.js");
        jquery.Files.Add("jquery-min.js");
        jquery.Files.Add("jquery-*");
        jquery.Files.Add("jquery-ui*");
        jquery.Files.Add("jquery.ui*");
        jquery.Files.Add("jquery.unobtrusive*");
        jquery.Files.Add("jquery.validate*");
        list.Add(jquery);

        BundleFileSetOrdering mod = new BundleFileSetOrdering("modernizr");
        mod.Files.Add("modernizr-*");
        list.Add(mod);

        BundleFileSetOrdering dojo = new BundleFileSetOrdering("dojo");
        dojo.Files.Add("dojo.*");
        list.Add(dojo);

        BundleFileSetOrdering moo = new BundleFileSetOrdering("moo");
        moo.Files.Add("mootools-core*");
        moo.Files.Add("mootools-*");
        list.Add(moo);

        BundleFileSetOrdering proto = new BundleFileSetOrdering("prototype");
        proto.Files.Add("prototype.js");
        proto.Files.Add("prototype-*");
        proto.Files.Add("scriptaculous-*");
        list.Add(proto);

        BundleFileSetOrdering ext = new BundleFileSetOrdering("ext");
        ext.Files.Add("ext.js");
        ext.Files.Add("ext-*");
        list.Add(ext);
    }


来源:https://stackoverflow.com/questions/19325487/ordering-of-files-within-a-bundle-what-are-the-known-libraries

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