3

尝试使用具有相同虚拟路径包名称
1 的 css 和 js 文件 - 可以吗?(尝试过:但失败了。不能为脚本和样式定义相同的虚拟路径名)
2 - 可以将 ScriptAndStyleBundle 与混合包一起构建吗?

只是因为我想对 css 和 js使用相同的名称。

//in BundleConfig.cs
bundles.Add(new ScriptBundle("~/bundles/doMenu")
            .Include("~/Plugins/doMenu/files/js/doMenu.js")
            );

        bundles.Add(new StyleBundle("~/bundles/doMenu")
            .Include("~/Plugins/doMenu/files/css/doMenu.css")
            );

//in _PartialLayoutMenu.cs
@Scripts.Render("~/bundles/doMenu")
@Styles.Render("~/bundles/doMenu")


结果是:

<!--MENU LAYOUT-->
<script src="/Plugins/doMenu/files/css/doMenu.css"></script>

<link href="/Plugins/doMenu/files/css/doMenu.css" rel="stylesheet"/>
<!--/MENU LAYOUT-->

有什么线索吗?或者我想要这样一个无用的头脑?(谢谢)

4

2 回答 2

3

Bundle names should be unique within the both styles and scripts. And since they are entirely different types you cannot mix them into a single bundle because then you wouldn't know how to reference it in the DOM: whether you should use a <script> or a <style> tag. Unfortunately what you are asking for is not possible.

于 2015-04-26T08:06:41.543 回答
3

我正在使用Cassette,它确实支持此功能。

配置:

bundles.Add<ScriptBundle>(BundleNames.Grid,
                          new[] {"~/Scripts/Grid.js"},
                          bundle => bundle.AddReference("~/" + BundleNames.Base));

bundles.Add<StylesheetBundle>(BundleNames.Grid,
                              new[] {"~/Content/Grid.less"});

BundleNames是我拥有的带有常量字符串的助手类。

视图中的参考包:

@{
    Bundles.Reference(BundleNames.Grid);
}

如您所料,这将包括所有 CSS 和 JS,以正确的顺序。

我还要提一下,在 ASP.Net 进行捆绑管理之前,我已经开始使用 Cassette,我对此非常满意。我没有发现 ASP.Net 缺少的任何有趣的功能。

于 2015-04-26T08:25:25.517 回答