ASP.Net MVC Style Bundle Not Including Most Files

后端 未结 1 1312
囚心锁ツ
囚心锁ツ 2020-12-29 07:17

Recently, my local copy of a project completely lost most of its styling. Took me a while to figure it out, as most of the styling was done in one file and the rest were min

相关标签:
1条回答
  • 2020-12-29 08:12

    By default, files with names ending in ".min.css" will only be included in release builds.

    The recommended bundle configuration is to only include non-minified .css and .js files, then the .min version will be automatically selected (if it exists) in release builds, i.e. <compilation debug="false">in your Web.config.

    You can control this behavior by clearing and then adding ignore rules to the BundleCollection.IgnoreList. An example BundleConfig could look like this:

    public static class BundleConfig
    {
        public static void RegisterBundles(BundleCollection bundles)
        {
            ConfigureIgnoreList(bundles.IgnoreList);
    
            // Setup your bundles...
        }
    
        public static void ConfigureIgnoreList(IgnoreList ignoreList)
        {
            if (ignoreList == null) throw new ArgumentNullException("ignoreList");
    
            ignoreList.Clear(); // Clear the list, then add the new patterns.
    
            ignoreList.Ignore("*.intellisense.js");
            ignoreList.Ignore("*-vsdoc.js");
            ignoreList.Ignore("*.debug.js", OptimizationMode.WhenEnabled);
            // ignoreList.Ignore("*.min.js", OptimizationMode.WhenDisabled);
            ignoreList.Ignore("*.min.css", OptimizationMode.WhenDisabled);
        }
    }
    

    You can also explicitly enable/disable the optimization by setting BundleTable.EnableOptimizations.

    0 讨论(0)
提交回复
热议问题