Dotless - Can't reference less variable in separate file with MVC Bundling

最后都变了- 提交于 2019-11-28 13:27:08

this sollution is working for me:
i have two nuget packages:
dotless
dotless adapter for system.web.optimization

in web.config i have this lines

<configuration>
    <configSections>
        <section name="dotless" type="dotless.Core.configuration.DotlessConfigurationSectionHandler, dotless.Core" />
    </configSections>
    <system.web>
        <httpHandlers>
            <add path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler, dotless.Core" />
        </httpHandlers>
    </system.web>
    <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />
        <handlers>
            <add name="dotless" path="*.less" verb="GET" type="dotless.Core.LessCssHttpHandler,dotless.Core" resourceType="File" preCondition="" />
        </handlers>
    </system.webServer>
    <dotless minifyCss="true" cache="true" web="false" disableParameters="true" />
</configuration>

note that you should define dotless params by your needs.

in BundleConfig.cs

public static void RegisterBundles(BundleCollection bundles)
{
    bundles.Add(new LessBundle("~/bundles/styles/").Include(
        "~/Content/site.less"
    ));
    BundleTable.EnableOptimizations = True; //false if you want to debug css
}

and finaly Site.less

/*i have to redefine some bootstrap mixin and variables, so importing bootstrap and extending happings there*/
@import "bootstrap-extends.less";

/* all other needed less should be included here too
   for example:
   @import "admin.less";
   @import "controls.less";
   etc
*/

body{

}

site.less and bootstrap-extends.less are inside Content folder.
bootstrap-extends holds all needed @import directives which are usualy listed in ~/Content/bootstrap/bootstrap.less

i hope this helps

Have you looked into the LESS bundle transformer?

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!