javascript – MVC4 Beta Minifying and Bundling:在浏览器中排序文件和调试

栏目: 后端 · 发布时间: 7年前

内容简介:代码日志版权声明:翻译自:http://stackoverflow.com/questions/9657412/mvc4-beta-minification-and-bundling-ordering-files-and-debugging-in-browser

我已经开始使用MVC4 Beta附带的捆绑和缩小.我遇到了一些问题:

一方面,如果我使用经典的<script src =“Folder / js”type =“text / javascript”/>捆绑,似乎我必须重命名我的文件,以确保它们按照正确的顺序捆绑.

假设我有三个javascript文件:“ants.js”,“bugs.js”,“insects.js”

> ants.js依赖于bugs.js

bugs.js取决于insects.js

>默认捆绑似乎按字母顺序捆绑.

>为了使它们正确绑定,我必须将它们重命名为:“0.insects.js”,“1.bugs.js”,“2.ants.js”

这真的是黑客,必须有一个更清洁的方式.

我遇到的下一个问题是调试.我喜欢在我的测试浏览器中浏览javascript,有没有办法在DEBUG模式下关闭简化?

编辑:要清楚,我知道我可以创建捆绑包,并从C#注册它,它似乎真的很丑,要这样做.

暂时得到非最小化的输出使用这个

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

为了控制javascript文件的顺序,您需要使用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");

代码日志版权声明:

翻译自:http://stackoverflow.com/questions/9657412/mvc4-beta-minification-and-bundling-ordering-files-and-debugging-in-browser


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Responsive Web Design

Responsive Web Design

Ethan Marcotte / Happy Cog / 2011-6 / USD 18.00

From mobile browsers to netbooks and tablets, users are visiting your sites from an increasing array of devices and browsers. Are your designs ready? Learn how to think beyond the desktop and craft be......一起来看看 《Responsive Web Design》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

html转js在线工具
html转js在线工具

html转js在线工具

UNIX 时间戳转换
UNIX 时间戳转换

UNIX 时间戳转换