Sass Compilation

Main types for using the Sass compiler.


Topics

Compiler

actor Compiler

A Sass compiler that uses Dart Sass as an embedded child process.

The Dart Sass compiler is bundled with this package for macOS and Ubuntu 64-bit Linux. For other platforms you need to supply this separately, see the readme.

Some debug logging is available via a swift-log Logger that produces goodpath protocol and compiler lifecycle tracing at Logger.Level.debug log level, approx 300 bytes per compile request, and protocol and lifecycle error reporting at Logger.Level.debug log level for conditions that are also reported through errors thrown from some API.

You must shut down the compiler using shutdownGracefully(...) before the last reference to the object is released otherwise the program will exit.

Custom importer resolution

Dart Sass uses a different algorithm to LibSass for processing imports. Each stylesheet is associated with the importer that loaded it – this may be an internal or hidden filesystem importer. Import resolution then goes:

  • Consult the stylesheet’s associated importer.
  • Consult every DartSass.ImportResolver given to the compiler, first the global list then the per-compilation list, in order within each list.
Declaration
Swift
public actor Compiler

Inputs

enum Syntax

Declaration
Swift
public enum Syntax: Sendable

enum CssStyle

How the Sass compiler should format the CSS it produces.

Declaration
Swift
public enum CssStyle: Sendable

enum SourceMapStyle

The kind of source map to generate for the stylesheet, returned in CompilerResults.sourceMap.

Declaration
Swift
public enum SourceMapStyle: Sendable

enum CompilerMessageStyle

Declaration
Swift
public enum CompilerMessageStyle: Sendable

enum CompilerWarningLevel

A control over warnings and debug messages produced by the compiler

Declaration
Swift
public enum CompilerWarningLevel: Sendable

enum Deprecation

A Deprecation refers to a specific feature of the Sass compiler that is deprecated or planned to become deprecated.

By default, using a deprecated feature causes a warning – that is, a CompilerMessage with type CompilerMessage.Kind.deprecation. In some future release of the compiler, use of the deprecated feature will cause an error instead.

You can customize a Sass Compiler’s treatment of deprecated behaviours using a DeprecationControl to create the compiler instance. Each individual deprecation can be ignored or promoted to an error. You can also opt in to future deprecations – features that do not currently cause a deprecation warning but are planned to do so in an upcoming release of Dart Sass.

Declaration
Swift
public enum Deprecation: Hashable, Sendable, CustomStringConvertible

struct DeprecationControl

A Compiler’s deprecation settings.

Indicates which Deprecations should be fatal, silenced, or eagerly adopted.

Declaration
Swift
public struct DeprecationControl: Sendable

Outputs

struct CompilerResults

The output from a successful compilation.

Declaration
Swift
public struct CompilerResults: Sendable

struct CompilerMessage

A diagnostic message generated by the Sass compiler that does not prevent the compilation from succeeding.

Appropriate for display to end users who own the stylesheets.

Declaration
Swift
public struct CompilerMessage: CustomStringConvertible, Sendable

struct CompilerError

Thrown as an error after a failed compilation.

Declaration
Swift
public struct CompilerError: Swift.Error, CustomStringConvertible, Sendable

struct Span

A section of a stylesheet.

Declaration
Swift
public struct Span: CustomStringConvertible, Sendable