Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
211 views
in Technique[技术] by (71.8m points)

c# - Bundler不包括.min文件(Bundler not including .min files)

I have a weird issue with the mvc4 bundler not including files with extension .min.js(我有一个奇怪的问题,mvc4捆绑包不包括扩展名为.min.js的文件)

In my BundleConfig class, I declare(在我的BundleConfig类中,我声明了) public static void RegisterBundles(BundleCollection bundles) { bundles.Add(new ScriptBundle("~/Scripts/jquery") .Include("~/Scripts/jquery-1.8.0.js") .Include("~/Scripts/jquery.tmpl.min.js")); } In my view, I declare(在我看来,我宣布) <html> <head> @Scripts.Render("~/Scripts/jquery") </head><body>test</body> </html> And when it renders, it only renders(当它呈现时,它只会呈现) <html> <head> <script src="/Scripts/jquery-1.8.0.js"></script> </head> <body>test</body> </html> If I rename the jquery.tmpl.min.js to jquery.tmpl.js (and update the path in the bundle accordingly), both scripts are rendered correctly.(如果我将jquery.tmpl.min.js重命名为jquery.tmpl.js(并相应地更新bundle中的路径),则会正确呈现这两个脚本。) Is there some config setting that is causing it to ignore '.min.js' files?(是否有一些配置设置导致它忽略'.min.js'文件?)   ask by Fatal translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

The solution I originally posted is questionable (is a dirty hack).(我最初发布的解决方案是有问题的(是一个肮脏的黑客)。)

The tweaked behaviour has changed in Microsoft.AspNet.Web.Optimization package and the tweak does not work anymore, as pointed out by many commenters.(正如许多评论者所指出的那样,在Microsoft.AspNet.Web.Optimization包中调整的行为已经改变,调整不再起作用了。) Right now I cannot reproduce the issue at all with the version 1.1.3 of the package.(现在我无法使用软件包的1.1.3版重现该问题。) Please see sources of System.Web.Optimization.BundleCollection (you can use dotPeek for example) for better understanding of what you are about to do.(请参阅System.Web.Optimization.BundleCollection的源代码(例如,您可以使用dotPeek )以更好地了解您将要执行的操作。) Also read Max Shmelev's answer .(另请阅读Max Shmelev的回答 。) Original answer :(原始答案 :) Either rename .min.js to .js or do something like(将.min.js重命名为.js或执行类似的操作) public static void AddDefaultIgnorePatterns(IgnoreList ignoreList) { if (ignoreList == null) throw new ArgumentNullException("ignoreList"); 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); } public static void RegisterBundles(BundleCollection bundles) { bundles.IgnoreList.Clear(); AddDefaultIgnorePatterns(bundles.IgnoreList); //NOTE: it's bundles.DirectoryFilter in Microsoft.AspNet.Web.Optimization.1.1.3 and not bundles.IgnoreList //...your code }

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...