generated from alecodes/base-template
33 lines
667 B
TypeScript
33 lines
667 B
TypeScript
import type { BunPlugin, PluginBuilder } from "bun";
|
|
import type { FileImporter } from "sass";
|
|
|
|
const nodeModuleImporter: FileImporter<"async"> = {
|
|
findFileUrl(url: string) {
|
|
if (url.startsWith("@")) {
|
|
return new URL(import.meta.resolve(url));
|
|
}
|
|
|
|
return null;
|
|
},
|
|
};
|
|
|
|
const sassPlugin: BunPlugin = {
|
|
name: "Sass Loader",
|
|
async setup(build: PluginBuilder) {
|
|
const sass = await import("sass");
|
|
|
|
build.onLoad({ filter: /\.scss$/ }, async ({ path }) => {
|
|
const result = await sass.compileAsync(path, {
|
|
importers: [nodeModuleImporter],
|
|
});
|
|
|
|
return {
|
|
loader: "css",
|
|
contents: result.css,
|
|
};
|
|
});
|
|
},
|
|
};
|
|
|
|
export default sassPlugin;
|
|
|