CompilerResults
public struct CompilerResults: Sendable
The output from a successful compilation.
Topics
var css: String
var css: String
var sourceMap: String?
var sourceMap: String?
The JSON sourcemap for css
, style according to the SourceMapStyle
provided at compile time.
Declaration
public let sourceMap: String?
var messages: [CompilerMessage]
var messages: [CompilerMessage]
Any compiler warnings and debug statements.
Declaration
public let messages: [CompilerMessage]
var loadedURLs: [URL]
var loadedURLs: [URL]
Source Map URL Control
enum URLStyle
enum URLStyle
How to reference source map resources from CSS.
There are two references here: the CSS pointing at the source map, and the source map
pointing at the original sources. The Sass compiler uses absolute (typically file:
) URLs
for original sources. This can be modified and the CSS -> source map reference added using
CompilerResults.withFileLocations(...)
.
If you plan to ship the source map (so it is accessed through http:
URLs by a browser)
then you need to use one of the .relative
options to avoid file:
URLs that won’t
make sense to clients.
Declaration
public enum URLStyle
func withFileLocations(cssFileURL: URL, sourceMapFileURL: URL, style: URLStyle) -> CompilerResults
func withFileLocations(cssFileURL: URL, sourceMapFileURL: URL, style: URLStyle) -> CompilerResults
Add filenames to the CSS and its source map.
The CSS and source map come out of the Sass compiler without references to each other. Sources are referenced from the source map using absolute URLs. This routine updates various metadata to make the source map load correctly in a browser.
This routine does not write any files.
Declaration
public func withFileLocations(
cssFileURL: URL, sourceMapFileURL: URL, style: URLStyle = .relative
) throws -> CompilerResults
Parameters
cssFileURL |
The file URL for the CSS. This is used to update the source map
with the name of the file it’s describing and, if |
sourceMapFileURL |
The file URL for the source map. This is used to generate the sourceMappingURL comment in the CSS. |
style |
How to reference the source map from the CSS and the sources from the
source map. See |
Throws
If the CompilerResults
does not have a source map, or if JSON encoding/
decoding goes wrong.
Return Value
A new CompilerResults
with updated css
and sourceMap
fields. The
messages
and loadedURLs
fields are copied over unchanged.