MVC4 Less Bundle @import Directory

前端 未结 10 818
南方客
南方客 2020-12-12 17:02

I\'m trying to use MVC4 bundling to group some of my less files, but it looks like the import path I\'m using is off. My directory structure is:

static/
             


        
10条回答
  •  抹茶落季
    2020-12-12 17:40

    Addendum to Ben Cull's answer:

    I know that this "should be a comment to Ben Cull's post", but it adds a little extra that would be impossible to add in a comment. So vote me down if you must. Or close me.

    Ben's blog post does it all, except it doesn't specify minification.

    So install the BundleTransformer.Less package as Ben suggests and then, if you want minification of your css, do the following (in ~/App_Start/BundleConfig.cs):

    var cssTransformer = new CssTransformer();
    var jsTransformer = new JsTransformer();
    var nullOrderer = new NullOrderer();
    
    var css = new Bundle("~/bundles/css")
        .Include("~/Content/site.less");
    css.Transforms.Add(cssTransformer);
    css.Transforms.Add(new CssMinify());
    css.Orderer = nullOrderer;
    
    bundles.Add(css);
    

    The added line is:

    css.Transforms.Add(new CssMinify());
    

    Where CssMinify is in System.Web.Optimizations

    I am so relieved to get around the @import issue and the resulting file with .less extension not found that I don't care who votes me down.

    If, on the contrary, you feel the urge to vote for this answer, please give your vote to Ben.

    So there.

提交回复
热议问题