UNPKG

4.03 kBTypeScriptView Raw
1import {RawSourceMap} from 'source-map-js';
2
3import {Options, StringOptions} from './options';
4
5/**
6 * The result of compiling Sass to CSS. Returned by [[compile]],
7 * [[compileAsync]], [[compileString]], and [[compileStringAsync]].
8 *
9 * @category Compile
10 */
11export interface CompileResult {
12 /**
13 * The generated CSS.
14 *
15 * Note that this *never* includes a `sourceMapUrl` comment—it's up to the
16 * caller to determine where to save the source map and how to link to it from
17 * the stylesheet.
18 */
19 css: string;
20
21 /**
22 * The canonical URLs of all the stylesheets that were loaded during the
23 * Sass compilation. The order of these URLs is not guaranteed.
24 */
25 loadedUrls: URL[];
26
27 /**
28 * The object representation of the source map that maps locations in the
29 * generated CSS back to locations in the Sass source code.
30 *
31 * This typically uses absolute `file:` URLs to refer to Sass files, although
32 * this can be controlled by having a custom [[Importer]] return
33 * [[ImporterResult.sourceMapUrl]].
34 *
35 * This is set if and only if [[Options.sourceMap]] is `true`.
36 */
37 sourceMap?: RawSourceMap;
38}
39
40/**
41 * Synchronously compiles the Sass file at `path` to CSS. If it succeeds it
42 * returns a [[CompileResult]], and if it fails it throws an [[Exception]].
43 *
44 * This only allows synchronous [[Importer]]s and [[CustomFunction]]s.
45 *
46 * @example
47 *
48 * ```js
49 * const sass = require('sass');
50 *
51 * const result = sass.compile("style.scss");
52 * console.log(result.css);
53 * ```
54 *
55 * @category Compile
56 * @compatibility dart: "1.45.0", node: false
57 */
58export function compile(path: string, options?: Options<'sync'>): CompileResult;
59
60/**
61 * Asynchronously compiles the Sass file at `path` to CSS. Returns a promise
62 * that resolves with a [[CompileResult]] if it succeeds and rejects with an
63 * [[Exception]] if it fails.
64 *
65 * This only allows synchronous or asynchronous [[Importer]]s and
66 * [[CustomFunction]]s.
67 *
68 * **Heads up!** When using Dart Sass, **[[compile]] is almost twice as fast as
69 * [[compileAsync]]**, due to the overhead of making the entire evaluation
70 * process asynchronous.
71 *
72 * @example
73 *
74 * ```js
75 * const sass = require('sass');
76 *
77 * const result = await sass.compileAsync("style.scss");
78 * console.log(result.css);
79 * ```
80 *
81 * @category Compile
82 * @compatibility dart: "1.45.0", node: false
83 */
84export function compileAsync(
85 path: string,
86 options?: Options<'async'>
87): Promise<CompileResult>;
88
89/**
90 * Synchronously compiles a stylesheet whose contents is `source` to CSS. If it
91 * succeeds it returns a [[CompileResult]], and if it fails it throws an
92 * [[Exception]].
93 *
94 * This only allows synchronous [[Importer]]s and [[CustomFunction]]s.
95 *
96 * @example
97 *
98 * ```js
99 * const sass = require('sass');
100 *
101 * const result = sass.compileString(`
102 * h1 {
103 * font-size: 40px;
104 * code {
105 * font-face: Roboto Mono;
106 * }
107 * }`);
108 * console.log(result.css);
109 * ```
110 *
111 * @category Compile
112 * @compatibility dart: "1.45.0", node: false
113 */
114export function compileString(
115 source: string,
116 options?: StringOptions<'sync'>
117): CompileResult;
118
119/**
120 * Asynchronously compiles a stylesheet whose contents is `source` to CSS.
121 * Returns a promise that resolves with a [[CompileResult]] if it succeeds and
122 * rejects with an [[Exception]] if it fails.
123 *
124 * This only allows synchronous or asynchronous [[Importer]]s and
125 * [[CustomFunction]]s.
126 *
127 * **Heads up!** When using Dart Sass, **[[compile]] is almost twice as fast as
128 * [[compileAsync]]**, due to the overhead of making the entire evaluation
129 * process asynchronous.
130 *
131 * @example
132 *
133 * ```js
134 * const sass = require('sass');
135 *
136 * const result = await sass.compileStringAsync(`
137 * h1 {
138 * font-size: 40px;
139 * code {
140 * font-face: Roboto Mono;
141 * }
142 * }`);
143 * console.log(result.css);
144 * ```
145 *
146 * @category Compile
147 * @compatibility dart: "1.45.0", node: false
148 */
149export function compileStringAsync(
150 source: string,
151 options?: StringOptions<'async'>
152): Promise<CompileResult>;