Citizen17.DartSass 1.1.0

There is a newer version of this package available.
See the version list below for details.
dotnet add package Citizen17.DartSass --version 1.1.0                
NuGet\Install-Package Citizen17.DartSass -Version 1.1.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="Citizen17.DartSass" Version="1.1.0" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Citizen17.DartSass --version 1.1.0                
#r "nuget: Citizen17.DartSass, 1.1.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 Citizen17.DartSass as a Cake Addin
#addin nuget:?package=Citizen17.DartSass&version=1.1.0

// Install Citizen17.DartSass as a Cake Tool
#tool nuget:?package=Citizen17.DartSass&version=1.1.0                

Citizen17.DartSass

Library for compiling SASS using Dart Sass runtime.

Install

Install package using NuGet.

Runtime

By default package doesn't contain Dart Sass runtime. It can use installed in system Dart Sass or you can one of packages with runtime:

  • DartSass.Native.win-x64
  • DartSass.Native.win-x86
  • DartSass.Native.linux-x64
  • DartSass.Native.linux-arm64
  • DartSass.Native.linux-x86
  • DartSass.Native.macos-x64
  • DartSass.Native.macos-arm64

Usage

Create DartSassCompiller instance.

using Citizen17.DartSass;

var compiler = new DartSassCompiller();

When instance creates it try find Dart Sass runtime. First it search in project. If not found it try search in system using environmen variable PATH.

If you have dedicated Dart Sass runtime you can pass it as parameter to constructor.

var compiler = new DartSassCompiller("/path/to/sass/executable");

Options

You can set default options that will be used on evert compile.

compiler.CompileOptions = new SassCompileOptions
{
    StyleType = StyleType.Expanded,
    EmitCharset = true,
    Update = false,
    ImportPaths = new List<string>
    {
        "/path/to/imports1",
        "/path/to/imports2"
    },

    GenerateSourceMap = true,
    SourceMapUrlType = SourceMapUrlType.Relative,
    EmbedSources = false,
    EmbedSourceMap = false,

};

Also every compile method can accept options. If options passed they override defaults.

Compile from file

Use CompileAsync method to get compiled code from file source.

var compiledCss = await compiler.CompileAsync("/path/to/source.scss");

Compile from code

Use CompileCodeAsync method to get compiled code from string source.

var sourceSassCode = ".some-class { color: red; }";
var compiledCss = await compiler.CompileCodeAsync(sourceSassCode);

Compile from file to file

Use CompileToFileAsync method to compile source SASS file to CSS.

var listOfProducedFiles = await compiler.CompileToFileAsync("/path/to/source/source.scss");

Result file: /path/to/source/source.css and /path/to/source/source.css.map if Source maps enabled.

Also you can pass custom name for output file.

var listOfProducedFiles = await compiler.CompileToFileAsync("/path/to/source/source.scss", "dest.css");

Result file: /path/to/source/dest.css and /path/to/source/dest.css.map if Source maps enabled.

var listOfProducedFiles = await compiler.CompileToFileAsync("/path/to/source/source.scss", "/path/to/dest/dest.css");

Result file: /path/to/dest/dest.css and /path/to/dest/dest.css.map if Source maps enabled.

Compile multiple files

Use CompileToFilesAsync method to compile multiple files. It has 2 overload.

First accept list of strings with source files.

var sourceFiles = new string[]
{
    "path/to/source1.sass",
    "path/to/source2.sass"
};

var listOfProducedFiles = await compiler.CompileToFilesAsync(sourceFiles);

All output files will be placed near it source file. Or you can pass additional parameter to specify output directory.

var listOfProducedFiles = await compiler.CompileToFilesAsync(sourceFiles, "/path/to/dest");

Second accept dictionary where key is source file and value is output file.

var sourceFiles = new Dictionaty<string, string>
{
    { "path/to/source.sass", "dest.css" }, // Will be placed near source file
    { "path/to/source2.sass", "path/to/dest2.css" },
    { "path/to/source3.sass", null } // Will be generated source3.css file and placed near source file
    { "path/to/source4.sass", "path/to/dest/" } // Will be generated source4.css file and placed in path/to/dest/
}

var listOfProducedFiles = await compiler.CompileToFilesAsync(sourceFiles);

Also you can pass as second parameter output directory and all files without reletive or ablsolute path will be placed in that directory

Version

Also you can get version of used Dart Sass runtime.

var version = await compiler.GetVersionAsync();
Product Compatible and additional computed target framework versions.
.NET net5.0 is compatible.  net5.0-windows was computed.  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 was computed.  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 was computed.  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.
  • net5.0

    • No dependencies.
  • net6.0

    • No dependencies.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Citizen17.DartSass:

Package Downloads
BootstrapEmail.Net

Bootstrap stylesheet, compiler, and inliner for responsive and consistent emails with the Bootstrap syntax you know and love.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
2.7.0 187 10/17/2024
2.6.0 220 9/19/2024
2.5.0 122 9/5/2024
2.4.0 736 5/2/2024
2.3.0 369 2/29/2024
2.2.0 127 1/31/2024
2.1.0 2,755 8/31/2022
2.0.0 389 8/3/2022
1.1.0 423 6/9/2022
1.0.0 420 12/1/2021

v 1.1.0:
* Added support of Linux Arm64 and MacOS arm64
* Added support of -q flag