forked from freshframework/fresh
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmod.ts
More file actions
27 lines (25 loc) · 756 Bytes
/
mod.ts
File metadata and controls
27 lines (25 loc) · 756 Bytes
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
import { initTailwind } from "./compiler.ts";
import type { Builder } from "fresh/dev";
import type { App } from "fresh";
import type { TailwindPluginOptions } from "./types.ts";
export function tailwind<T>(
builder: Builder,
app: App<T>,
options: TailwindPluginOptions = {},
): void {
let processor: ReturnType<typeof initTailwind> | null;
builder.onTransformStaticFile(
{ pluginName: "tailwind", filter: /\.css$/ },
async (args) => {
if (!processor) processor = initTailwind(app.config, options);
const instance = await processor;
const res = await instance.process(args.text, {
from: args.path,
});
return {
content: res.content,
map: res.map?.toString(),
};
},
);
}