-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsass.ts
43 lines (42 loc) · 1.09 KB
/
sass.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
/**
* The Sass preprocessor for the esbuild PostCSS Plugin.
*
* @module
*/
import type { Preprocessor, PreprocessorResults } from "./postcss.ts";
import * as sass from "sass";
/**
* Creates a Sass preprocessor for the esbuild PostCSS Plugin.
*
* ```ts
* import esbuild from "esbuild";
* import { postCSSPlugin } from "@udibo/esbuild-plugin-postcss";
* import { sassPreprocessor } from "@udibo/esbuild-plugin-postcss/sass";
*
* esbuild.build({
* plugins: [postCSSPlugin({
* preprocessors: [sassPreprocessor()],
* })],
* entryPoints: ["./src/index.scss"],
* outdir: "./dist",
* bundle: true,
* });
* ```
*
* @param options - The options for the sass preprocessor.
* @returns The sass preprocessor.
*/
export function sassPreprocessor(
options?: sass.Options<"async">,
): Preprocessor {
return {
filter: /\.(sass|scss)$/,
async compile(path: string): Promise<PreprocessorResults> {
const { css, loadedUrls } = await sass.compileAsync(path, options);
return {
css,
watchFiles: loadedUrls.map((url) => url.pathname),
};
},
};
}