snipervld.WebOptimizer.Dotless 3.3.0

dotnet add package snipervld.WebOptimizer.Dotless --version 3.3.0                
NuGet\Install-Package snipervld.WebOptimizer.Dotless -Version 3.3.0                
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="snipervld.WebOptimizer.Dotless" Version="3.3.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add snipervld.WebOptimizer.Dotless --version 3.3.0                
#r "nuget: snipervld.WebOptimizer.Dotless, 3.3.0"                
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install snipervld.WebOptimizer.Dotless as a Cake Addin
#addin nuget:?package=snipervld.WebOptimizer.Dotless&version=3.3.0

// Install snipervld.WebOptimizer.Dotless as a Cake Tool
#tool nuget:?package=snipervld.WebOptimizer.Dotless&version=3.3.0                

A LESS compiler for ASP.NET Core using dotless

NuGet

This package compiles LESS files into CSS by hooking into the LigerShark.WebOptimizer pipeline.

Install

Add the NuGet package snipervld.WebOptimizer.Dotless to any ASP.NET Core project supporting .NET 6.0 or higher.

> dotnet add package snipervld.WebOptimizer.Dotless

Versions

Version Support
>= 3.x ASP.NET Core 6.0 and above

Usage

Here's an example of how to compile a.less and b.less from inside the wwwroot folder and bundle them into a single .css file called /all.css:

In Startup.cs, modify the ConfigureServices method:

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc();
    services.AddWebOptimizer(pipeline =>
    {
        pipeline.AddLessBundle("/all.css", "a.less", "b.less");
    });
}

...and add app.UseWebOptimizer() to the Configure method anywhere before app.UseStaticFiles, like so:

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    if (env.IsDevelopment())
    {
        app.UseDeveloperExceptionPage();
    }

    app.UseWebOptimizer();

    app.UseStaticFiles();
    app.UseMvc(routes =>
    {
        routes.MapRoute(
            name: "default",
            template: "{controller=Home}/{action=Index}/{id?}");
    });
}

Now the path http://domain/all.css will return a compiled, bundled and minified CSS document based on the two source files.

You can also reference any .less files directly in the browser (http://domain/a.less) and a compiled and minified CSS document will be served. To set that up, do this:

services.AddWebOptimizer(pipeline =>
{
    pipeline.CompileLessFiles();
});

Or if you just want to limit what .less files will be compiled, do this:

services.AddWebOptimizer(pipeline =>
{
    pipeline.CompileLessFiles("/path/file1.less", "/path/file2.less");
});

Setup TagHelpers

In _ViewImports.cshtml register the TagHelpers by adding @addTagHelper *, WebOptimizer.Core to the file. It may look something like this:

@addTagHelper *, WebOptimizer.Core
@addTagHelper *, Microsoft.AspNetCore.Mvc.TagHelpers

Differences From twenzel's WebOptimizer.Dotless

  • Added an ability to pass css settings to minificator.
  • It's now possible to include regular .css files into .less bundles. .css files are not processed by LessEngine.
  • LessEngines imports are reset between each .less file compilation, when there are multiple .less files per bundle. It fixes an issue, when multiple files with import statements are located in different directories, but due to LessEngine's imports caching mechanism, LessEngine handles them incorrectly, e.g. if two .less files dir/a.less and b.less imports the same root.less, LessEngine tries to get content of root.less from incorrect location, when transforning b.less.
  • Added a support for abstract IFileProviders, e.g. ManifestEmbeddedFileProvider.
  • Use custom dotless.Core compiler, which fixes bug in ResetImports method, whech prevents the user to compile multiple .less files in the same directory, which reference imports the same file.
  • Drop support for old frameworks. Add support for .NET 7.0 and .NET 8.0.
Product Compatible and additional computed target framework versions.
.NET net6.0 is compatible.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 is compatible.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.3.0 775 10/17/2024
3.2.2 340 6/27/2024
3.2.1 503 8/6/2023
3.2.0 1,510 8/10/2022