forked from LePichu/esbuild-plugin-sass-deno
-
Notifications
You must be signed in to change notification settings - Fork 0
/
mod.ts
30 lines (25 loc) · 778 Bytes
/
mod.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
import { esbuild, path, sass } from "./deps.ts";
interface Option {
loader: "css" | "text";
}
const sassPlugin = (option?: Option): esbuild.Plugin => {
// TODO: cache sass compilation result
return {
name: "esbuild-plugin-sass-deno",
setup: (build) => {
build.onLoad({ filter: /\.s[ac]ss/ }, async (args) => {
const resolvedPath = path.resolve(args.path);
const result = await sass.compileAsync(resolvedPath);
const watchFiles = result.loadedUrls
.filter((url) => url.href.startsWith("file:"))
.map((url) => path.fromFileUrl(url));
return {
contents: result.css,
loader: option?.loader ?? "css",
watchFiles,
};
});
},
};
};
export default sassPlugin;