Can scripts and styles be included in the same package? (asp.net mvc5)

Trying to use css and js files with the same virtual paths package name
 1 - is this possible? (tried: but failed. can't figure out the virtual path name for both script and style)
 2 - is it possible to compile the ScriptAndStyleBundle along with a mixed package?

Just because I want to use the same name for both css and 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")

      

<h / "> result:

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

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

      

any hint? or do I want such a useless mind? (thank)

+3


source to share


2 answers


I am using Cassette which supports this feature.

Configuration:

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

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

      

BundleNames

is a helper class i with constant strings.



Links in the form:

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

      

As you would expect, this will include all the CSS and JS in the correct order.

I would also mention that I started using Cassette before ASP.Net has bundle management and I am very happy with that. I didn't find any interesting feature that ASP.Net had what I was missing.

+3


source


Package names must be unique across both styles and scripts. And since they are completely different types, you cannot mix them in the same package, because then you don't know how to reference it in the DOM: whether to use a tag <script>

or <style>

. Unfortunately, what you are asking is not possible.



+3


source







All Articles