How to use ASP.Net MVC 4 to Bundle LESS files in Release mode?

后端 未结 5 1331
佛祖请我去吃肉
佛祖请我去吃肉 2020-12-04 13:46

I\'m trying to have LESS files in my web project, and have the MVC 4 bundling functionality call into the dotLess library to turn the LESS into CSS, then minify the result a

5条回答
  •  生来不讨喜
    2020-12-04 14:21

    Already some great answers, here's a very simple solution I found for myself when trying to add MVC bundles that regard less files.

    After creating your less file (for example, test.less), right click on it and under Web Compiler (get it here) option, select Compile File.

    This generates the resulting css file from your less one, and also its minified version. (test.css and test.min.css).

    On your bundle, just refer to the generated css file

    style = new StyleBundle("~/bundles/myLess-styles")
        .Include("~/Content/css/test.css", new CssRewriteUrlTransform());
    
    bundles.Add(style);
    

    And on your view, reference that bundle:

    @Styles.Render("~/bundles/myLess-styles")
    

    It should just work fine.

提交回复
热议问题