MVC4贝塔缩小与绑扎:订购浏览器中的文件和调试 [英] MVC4 Beta Minification and Bundling: Ordering files and debugging in browser

查看:161
本文介绍了MVC4贝塔缩小与绑扎:订购浏览器中的文件和调试的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经使用捆绑和附带MVC4测试微小启动。我遇到的几个问题吧:

I've started using bundling and minification included with the MVC4 Beta. I'm running into a few issues with it:

有关的一件事,如果我用了经典< SCRIPT SRC =文件夹/ JS类型=文/ JavaScript的/> 捆绑,它看起来像我有我的重命名文件,以确保他们在正确的顺序捆绑在一起。

For one thing, if I use the classic <script src="Folder/js" type="text/javascript"/> bundling, it seems like I have to rename my files to make sure they're bundled in the proper order.


  • 比方说,我有三个JavaScript文件:ants.js,bugs.js,insects.js

  • ants.js取决于bugs.js

  • bugs.js取决于insects.js

  • 默认捆绑似乎捆绑他们按字母顺序排列。

  • 要得到他们正确地捆绑,我必须将它们重新命名为:0.insects.js,1.bugs.js,2.ant​​s.js

  • 这是真正的hackish,并必须有一个更清洁的方式。

我有下一个问题是调试。我喜欢踩在经过我的测试浏览器的JavaScript,有没有办法关闭只是微小而在调试模式?

The next problem I'm having is debugging. I like to step through the javascript in my testing browsers, is there a way to turn off just the minification while in DEBUG mode?

编辑:要清楚,我知道我可以创建包和C#进行注册,它只是似乎真的很丑不得不这样做的。

To be clear, I know I can create bundles and register them from C#, it just seems really ugly to have to do it that way.

推荐答案

要暂时获得非缩小的输出使用这种

To temporarily get non-minified output use this

  public class NonMinifyingJavascript : IBundleTransform
{
    public void Process(BundleContext context, BundleResponse bundle)
    {
        if(bundle == null)
        {
            throw new ArgumentNullException("bundle");
        }

        context.HttpContext.Response.Cache.SetLastModifiedFromFileDependencies();

        foreach(FileInfo file in bundle.Files)
        {
            HttpContext.Current.Response.AddFileDependency(file.FullName);
        }

        bundle.ContentType = "text/javascript";
        //base.Process(context, bundle);
    }
}

如果你想它完全基于一个配置设置,我想你可以创建一个IBundle变换一个或JsMinify取决于你的配置委托给这个设置

If you wanted it based totally on a config setting, I imagine you could create an IBundle transform that delegates to this one or JsMinify depending on your config setting

为了控制你需要使用BundleFileSetOrdering的JavaScript文件的顺序

In order to control the ordering of the javascript files you need to use the BundleFileSetOrdering

 var javascriptBundle = new Bundle("~/site/js", new NonMinifyingJavascript());

         //controls ordering for javascript files, otherwise they are processed in order of AddFile calls
         var bootstrapOrdering = new BundleFileSetOrdering("bootstrap");
         //The popover plugin requires the tooltip plugin
         bootstrapOrdering.Files.Add("bootstrap-tooltip.js");
         bootstrapOrdering.Files.Add("bootstrap-popover.js");
         BundleTable.Bundles.FileSetOrderList.Add(bootstrapOrdering);
         javascriptBundle.AddDirectory("~/Scripts", "bootstrap-*.js");

这篇关于MVC4贝塔缩小与绑扎:订购浏览器中的文件和调试的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆