compileToResult function

CompileResult compileToResult(
  1. String path, {
  2. bool color = false,
  3. Logger? logger,
  4. Iterable<Importer>? importers,
  5. Iterable<String>? loadPaths,
  6. PackageConfig? packageConfig,
  7. Iterable<Callable>? functions,
  8. OutputStyle? style,
  9. bool quietDeps = false,
  10. bool verbose = false,
  11. bool sourceMap = false,
  12. bool charset = true,
  13. Iterable<Deprecation>? silenceDeprecations,
  14. Iterable<Deprecation>? fatalDeprecations,
  15. Iterable<Deprecation>? futureDeprecations,
})

Loads the Sass file at path, compiles it to CSS, and returns a CompileResult containing the CSS and additional metadata about the compilation.

If color is true, this will use terminal colors in warnings. It's ignored if logger is passed.

If logger is passed, it's used to emit all messages that are generated by Sass code. Users may pass custom subclasses of Logger.

Imports are resolved by trying, in order:

  • Loading a file relative to path.

  • Each importer in importers.

  • Each load path in loadPaths. Note that this is a shorthand for adding FilesystemImporters to importers.

  • Each load path specified in the SASS_PATH environment variable, which should be semicolon-separated on Windows and colon-separated elsewhere.

  • package: resolution using packageConfig, which is a PackageConfig from the package_resolver package. Note that this is a shorthand for adding a PackageImporter to importers.

Dart functions that can be called from Sass may be passed using functions. Each Callable defines a top-level function that will be invoked when the given name is called from Sass.

The style parameter controls the style of the resulting CSS.

If quietDeps is true, this will silence compiler warnings emitted for stylesheets loaded through importers, loadPaths, or packageConfig.

By default, once a deprecation warning for a given feature is printed five times, further warnings for that feature are silenced. If verbose is true, all deprecation warnings are printed instead.

If sourceMap is true, CompileResult.sourceMap will be set to a SingleMapping that indicates which sections of the source file(s) correspond to which in the resulting CSS. SingleMapping.targetUrl will be null. It's up to the caller to save this mapping to disk and add a source map comment to CompileResult.css pointing to it. Users using the SingleMapping API should be sure to add the source_maps package to their pubspec.

If charset is true, this will include a @charset declaration or a UTF-8 byte-order mark if the stylesheet contains any non-ASCII characters. Otherwise, it will never include a @charset declaration or a byte-order mark.

Throws a SassException if conversion fails.

Implementation

CompileResult compileToResult(String path,
        {bool color = false,
        Logger? logger,
        Iterable<Importer>? importers,
        Iterable<String>? loadPaths,
        PackageConfig? packageConfig,
        Iterable<Callable>? functions,
        OutputStyle? style,
        bool quietDeps = false,
        bool verbose = false,
        bool sourceMap = false,
        bool charset = true,
        Iterable<Deprecation>? silenceDeprecations,
        Iterable<Deprecation>? fatalDeprecations,
        Iterable<Deprecation>? futureDeprecations}) =>
    c.compile(path,
        logger: logger,
        importCache: ImportCache(
            importers: importers,
            logger: logger ?? Logger.stderr(color: color),
            loadPaths: loadPaths,
            packageConfig: packageConfig),
        functions: functions,
        style: style,
        quietDeps: quietDeps,
        verbose: verbose,
        sourceMap: sourceMap,
        charset: charset,
        silenceDeprecations: silenceDeprecations,
        fatalDeprecations: fatalDeprecations,
        futureDeprecations: futureDeprecations);