c# - Ignoring files in MVC Bundles -
we using feature flags (set in web.config) toggle visibility in ui of features aren't yet complete. i'd mvc bundles not include related js files since useless files client have download when feature isn't enabled.
so far i've found ignorelist.ignore can't seem work. i'm doing:
public static void registerbundles(bundlecollection bundles) { if (!appconfiguration.featurexenabled) { //skip these files if feature x not enabled! //when flag removed, these lines can deleted , files included normal bundles.ignorelist.ignore("~/app/organization/somectrl.js", optimizationmode.always); bundles.ignorelist.ignore("~/app/filters/somefilter.js", optimizationmode.always); } var globalbundle = new scriptbundle("~/bundles/app-global").include( "~/app/rootctrl.js", "~/app/directives/*.js", "~/app/services/*.js", "~/app/application.js" ); bundles.add(globalbundle); var apporgbundle = new scriptbundle("~/bundles/app-org"); apporgbundle.include( "~/app/filters/*.js", "~/app/organization/*.js" ); bundles.add(apporgbundle); } with above code, files in ignore list still being included! doing wrong here?
i have fought ignore list when using expressions well. simple work around have found implement ibundleorderer exclude files not want, , apply ordering how files included. although not intended use, find fills gap.
the ibundleorderer gets access full list of files (expression expanded files matched).
public class applicationorderer : ibundleorderer { public ienumerable<bundlefile> orderfiles(bundlecontext context, ienumerable<bundlefile> files) { if (!appsettings.featureflag_serviceintegrationsenabled) { //skip these files if service integrations feature not enabled! //when flag removed, these lines can deleted , files included normal var serviceintegrationpathstoignore = new[] { "/app/serviceintegrations/integrationsettingsmodel.js", "/app/serviceintegrations/integrationsettingsservice.js", "/app/serviceintegrations/serviceintegrationsctrl.js" }; files = files.where(x => !serviceintegrationpathstoignore.contains(x.virtualfile.virtualpath)); } return files; } } example usage:
public static void registerbundles(bundlecollection bundles) { var appbundle = new scriptbundle("~/bundles/app") .includedirectory("~/app/", "*.js", true) appbundle.orderer = new applicationorderer(); bundles.add(appbundle); }
Comments
Post a Comment