public class RespectGivenBundleOrder : IBundleOrderer{ public IEnumerable<Bundlefile> Orderfiles(BundleContext context,IEnumerable<Bundlefile> files) { return files; }}public static voID RegisterTestingBundle(BundleCollection bundles) { var bundle = new ScriptBundle("~/OnTheMoveWebfiles/bundles/Testing"); bundle.Orderer = new RespectGivenBundleOrder(); bundle.Include( string.Format("{0}jquery-{{version}}.Js",baseJsFolder),string.Format("{0}ua-parser.Js",string.Format("{0}OnTheMove_Core.Js",string.Format("{0}OnTheMove_TheApplication.Js",string.Format("{0}OnTheMove_JQMqueryString.Js",string.Format("{0}OnTheMove_OfflineAuditing.Js",string.Format("{0}OnTheMove_DatabaseManager.Js",string.Format("{0}OnTheMove.Js",string.Format("{0}OnTheMove_Offline.Js",string.Format("{0}OnTheMove_DatabaseLoader.Js",string.Format("{0}OnTheMove_DatabaseTestHelper.Js",string.Format("{0}OnTheMove_SmartScriptPlayer.Js",string.Format("{0}jasmine.Js",string.Format("{0}jasmine-HTML.Js",string.Format("{0}jasmine-jquery-{{version}}.Js",string.Format("{0}jasmine-OnTheMove-GenericmocksAndHelpers.Js",string.Format("{0}jasmine-OnTheMove-DatabaseManager-SIEbelTosql-Tests.Js",string.Format("{0}jasmine-OnTheMove-TreeValIDator-Tests.Js",string.Format("{0}jasmine-OnTheMove-GlobalFunction-Tests.Js",string.Format("{0}jasmine-OnTheMove-OnTheMove_BusinessComponent-Tests.Js",string.Format("{0}jasmine-OnTheMove_DatabaseTestHelper-Tests.Js",string.Format("{0}jasmine-OnTheMove_OfflineAuditing-Tests.Js",string.Format("{0}jasmine-OnTheMove-JqueryExtension-Tests.Js",baseJsFolder)); bundles.Add(bundle); }
但是当我开始缩小时,我会收到JavaScript错误,并且通过检查Chrome开发人员工具中缩小文件的开头,我可以立即看到该订单搞砸了.
在我执行var cont = new BundleResolver(Bundletable.Bundles).GetBundleContents(“〜/ OnTheMoveWebfiles / bundles / Testing”)的即时窗口中我得到
Count = 23 [0]: "~/OnTheMoveWebfiles/Js/jquery-1.7.1.Js" [1]: "~/OnTheMoveWebfiles/Js/ua-parser.Js" [2]: "~/OnTheMoveWebfiles/Js/OnTheMove_Core.Js" [3]: "~/OnTheMoveWebfiles/Js/OnTheMove_TheApplication.Js" [4]: "~/OnTheMoveWebfiles/Js/OnTheMove_JQMqueryString.Js" [5]: "~/OnTheMoveWebfiles/Js/OnTheMove_OfflineAuditing.Js" [6]: "~/OnTheMoveWebfiles/Js/OnTheMove_DatabaseManager.Js" [7]: "~/OnTheMoveWebfiles/Js/OnTheMove.Js" [8]: "~/OnTheMoveWebfiles/Js/OnTheMove_Offline.Js" [9]: "~/OnTheMoveWebfiles/Js/OnTheMove_DatabaseLoader.Js" [10]: "~/OnTheMoveWebfiles/Js/OnTheMove_DatabaseTestHelper.Js" [11]: "~/OnTheMoveWebfiles/Js/OnTheMove_SmartScriptPlayer.Js" [12]: "~/OnTheMoveWebfiles/Js/jasmine.Js" [13]: "~/OnTheMoveWebfiles/Js/jasmine-HTML.Js" [14]: "~/OnTheMoveWebfiles/Js/jasmine-jquery-1.7.0.Js" [15]: "~/OnTheMoveWebfiles/Js/jasmine-OnTheMove-GenericmocksAndHelpers.Js" [16]: "~/OnTheMoveWebfiles/Js/jasmine-OnTheMove-DatabaseManager-SIEbelTosql-Tests.Js" [17]: "~/OnTheMoveWebfiles/Js/jasmine-OnTheMove-TreeValIDator-Tests.Js" [18]: "~/OnTheMoveWebfiles/Js/jasmine-OnTheMove-GlobalFunction-Tests.Js" [19]: "~/OnTheMoveWebfiles/Js/jasmine-OnTheMove-OnTheMove_BusinessComponent-Tests.Js" [20]: "~/OnTheMoveWebfiles/Js/jasmine-OnTheMove_DatabaseTestHelper-Tests.Js" [21]: "~/OnTheMoveWebfiles/Js/jasmine-OnTheMove_OfflineAuditing-Tests.Js" [22]: "~/OnTheMoveWebfiles/Js/jasmine-OnTheMove-JqueryExtension-Tests.Js"
这表明订单正在保存,但是当我在运行中缩小它时(var contents = BundleManager.GetBundleContents(“〜/ OnTheMoveWebfiles / bundles / Testing”);)我得到了
"function TheApplication(){return window.onTheMove.theApplication}function decodequeryString(n,t,i,r){var f,u={},s,h,e,o;if(i||(i=function(){return}),...
这是OnTheMove_TheApplication.Js的开头,而不是我期待的jquery-1.7.1.Js.我看到的一个解决方案是将它拆分成更多的捆绑包并尝试以这种方式处理它.
为什么minifIEr不保留秩序?我的期望是错的吗?
public class AsIsBundleOrderer : IBundleOrderer{ public virtual IEnumerable<fileInfo> Orderfiles(BundleContext context,IEnumerable<fileInfo> files) { return files; }}internal static class BundleExtensions{ public static Bundle ForceOrdered(this Bundle sb) { sb.Orderer = new AsIsBundleOrderer(); return sb; }}
然后,您可以注册您的包
bundles.Add(new ScriptBundle("~/bundles/home") .Include("~/Scripts/leaflet-0.6.4.Js") .Include("~/Scripts/oms.Js") .Include("~/Scripts/home.Js").ForceOrdered() );总结
以上是内存溢出为你收集整理的c# – System.Web.Optimization在缩小javascript时改变js文件的顺序全部内容,希望文章能够帮你解决c# – System.Web.Optimization在缩小javascript时改变js文件的顺序所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)