Sass Compiler Library for .NET 6 and above. without node, using dart-sass as a compiler
$ dotnet add package AspNetCore.SassCompilerSass Compiler Library for .NET Core 3.x/5.x. without node.
The installation of this package is quite simple, you can install this package using NuGet with the following command:
# Package Manager
PM> Install-Package AspNetCore.SassCompiler
# .NET CLI
dotnet add package AspNetCore.SassCompiler
After adding the package, the Sass styles from the SourceFolder (defaults to: Styles) will automatically be compiled into .css files in the TargetFolder (defaults to: wwwroot\css) on build.
You can also adjust the default (--style=compressed) dart-sass Arguments in the appsettings.json.
To adjust any of the default configuration, please add one or more of the following settings to the appsettings.json:
{
"SassCompiler": {
"SourceFolder": "Styles",
"TargetFolder": "wwwroot\\css",
"Arguments": "--style=compressed"
}
}
To use the Sass watcher in your project, you must add the following code to your startup.cs:
public void ConfigureServices(IServiceCollection services)
{
#if DEBUG
services.AddSassCompiler();
#endif
}
I recommend adding the #if DEBUG statement to only use a watcher during debug mode.
As an example, a configured version of a .NET 5.0 project is added in the /Samples folder. Please see the link below for quick access