This solution is working for me:
I have two NuGet packages:
- dotless
- dotless adapter for system.web.optimization
In my web.config
, I have these 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 for 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 finally, Site.less
:
/* I have to redefine some bootstrap mixins and variables,
so importing bootstrap and extending happens here: */
@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 the Content folder. bootstrap-extends
holds all needed @import
directives, which are usually listed in ~/Content/bootstrap/bootstrap.less
.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…