我怎么可以指定一个明确的ScriptBundle包括订单? [英] How can I specify an explicit ScriptBundle include order?

查看:183
本文介绍了我怎么可以指定一个明确的ScriptBundle包括订单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想出来的 MVC4 System.Web.Optimization 1.0 ScriptBundle功能

我有以下配置:

public class BundleConfig
{
    public static void RegisterBundles(BundleCollection bundles)
    {
        // shared scripts
        Bundle canvasScripts =
            new ScriptBundle(BundlePaths.CanvasScripts)
                .Include("~/Scripts/modernizr-*")
                .Include("~/Scripts/json2.js")
                .Include("~/Scripts/columnizer.js")
                .Include("~/Scripts/jquery.ui.message.min.js")
                .Include("~/Scripts/Shared/achievements.js")
                .Include("~/Scripts/Shared/canvas.js");
        bundles.Add(canvasScripts);
    }
}

和以下观点:

<script type="text/javascript" src="@Scripts.Url(BundlePaths.CanvasScripts)"></script>

其中, BundlePaths.CanvasScripts 〜/包/脚本/帆布。它呈现这样的:

<script type="text/javascript" src="/bundles/scripts/canvas?v=UTH3XqH0UXWjJzi-gtX03eU183BJNpFNg8anioG14_41"></script>

到目前为止好,除了〜/脚本/共享/ achievements.js 是捆绑源的第一个脚本。这取决于在 ScriptBundle 包括之前的每脚本。 我怎么能保证它在荣誉,我添加包括语句捆绑的顺序?

So far so good, except ~/Scripts/Shared/achievements.js is the first script in the bundled source. It depends on every script included before it in the ScriptBundle. How can I ensure that it honors the order in which I add include statements to the bundle?

更新

这是一个相对较新的ASP.NET MVC应用4,但它引用了优化框架pre发布包。我删除,并从增加了RTM包<一个href=\"http://nuget.org/packages/Microsoft.AspNet.Web.Optimization\">http://nuget.org/packages/Microsoft.AspNet.Web.Optimization.随着RTM版本的调试=在web.config中真, @ Scripts.Render(〜/包/脚本/帆布)呈现在正确的顺序各个脚本标签。

This was a relatively new ASP.NET MVC 4 application, but it was referencing the optimization framework pre release package. I removed it and added the RTM package from http://nuget.org/packages/Microsoft.AspNet.Web.Optimization. With the RTM version with debug=true in web.config, @Scripts.Render("~/bundles/scripts/canvas") renders the individual script tags in the correct order.

使用调试=在web.config中虚假的,合并后的脚本首先有achievements.js剧本,但因为它的函数的定义(对象构造)这就是后来被称为,它运行没有错误。也许minifier是足够聪明弄清楚依赖?

With debug=false in web.config, the combined script has the achievements.js script first, but since its a function definition (object constructor) that's called later, it runs without error. Perhaps the minifier is smart enough to figure out dependencies?

我也试过 IBundleOrderer 实现,达林季米特洛夫建议用RTM既调试选项,它的表现是一样的。

I also tried the IBundleOrderer implementation that Darin Dimitrov suggested with RTM with both debug options and it behaved the same.

所以缩小的版本是不是我期待的顺序,但它的作品。

So the minified version is not in the order I expect, but it works.

推荐答案

我没有看到在RTM位此行为,您使用的是微软的ASP.NET Web优化框架1.0.0位:<一href=\"http://nuget.org/packages/Microsoft.AspNet.Web.Optimization\">http://nuget.org/packages/Microsoft.AspNet.Web.Optimization ?

I'm not seeing this behavior on the RTM bits, are you using the Microsoft ASP.NET Web Optimization Framework 1.0.0 bits: http://nuget.org/packages/Microsoft.AspNet.Web.Optimization ?

我用了一个类似摄制您的样品,根据掀起了新MVC4互联网应用的网站。

I used a similar repro to your sample, based off of a new MVC4 Internet application website.

我加入BundleConfig.RegisterBundles:

I added to BundleConfig.RegisterBundles:

        Bundle canvasScripts =
            new ScriptBundle("~/bundles/scripts/canvas")
                .Include("~/Scripts/modernizr-*")
                .Include("~/Scripts/Shared/achievements.js")
                .Include("~/Scripts/Shared/canvas.js");
        bundles.Add(canvasScripts); 

然后在默认的索引页,我说:

And then in the default index page, I added:

<script src="@Scripts.Url("~/bundles/scripts/canvas")"></script>

和我核实,在捆绑包的精缩的JavaScript的achievements.js内容是后Modernizr的...

And I verified that in the minified javascript for the bundle, the contents of achievements.js was after modernizr...

这篇关于我怎么可以指定一个明确的ScriptBundle包括订单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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