We're having a growing number of packages in this repository. This PR moves them into a `packages/` directory like it's commonly done in other projects.
32 lines
843 B
TypeScript
32 lines
843 B
TypeScript
import type { Builder } from "fresh/dev";
|
|
import twPostcss from "@tailwindcss/postcss";
|
|
import postcss from "postcss";
|
|
import type { TailwindPluginOptions } from "./types.ts";
|
|
|
|
// Re-export types for public API
|
|
export type { TailwindPluginOptions } from "./types.ts";
|
|
|
|
export function tailwind(
|
|
builder: Builder,
|
|
options: TailwindPluginOptions = {},
|
|
): void {
|
|
const { exclude, ...tailwindOptions } = options;
|
|
const instance = postcss(twPostcss({
|
|
optimize: builder.config.mode === "production",
|
|
...tailwindOptions,
|
|
}));
|
|
|
|
builder.onTransformStaticFile(
|
|
{ pluginName: "tailwind", filter: /\.css$/, exclude },
|
|
async (args) => {
|
|
const res = await instance.process(args.text, {
|
|
from: args.path,
|
|
});
|
|
return {
|
|
content: res.content,
|
|
map: res.map?.toString(),
|
|
};
|
|
},
|
|
);
|
|
}
|