这个解决方案对我有用:
我有两个 NuGet 包:
- dotless
-dotless adapter for system.web.optimization
在我的web.config
中,我有以下几行:
<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>
请注意,您应该根据需要定义无点参数。
在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
}
最后,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
并且bootstrap-extends.less
位于 Content 文件夹内。 bootstrap-extends
包含所有需要@import
的指令,这些指令通常列在~/Content/bootstrap/bootstrap.less
.