This commit is contained in:
Alex
2024-04-27 02:18:44 -04:00
parent 8010c774cd
commit 2a3e7390cf
5 changed files with 63 additions and 44 deletions

View File

@ -1,11 +1,12 @@
import hash from "@emotion/hash";
import type { Config } from "tailwindcss";
import type { SetRequired } from "type-fest";
import type postcss from "postcss";
import { memoize } from "lodash";
import { type ClassNameCollector, babelTailwind } from "./babel-tailwind";
import { esbuildPlugin } from "./esbuild-postcss";
import { vitePlugin } from "./vite-plugin";
import { type StyleMap, createPostCSS, type tailwindDirectives } from "./shared";
import { type StyleMap, createPostCSS } from "./shared";
export { babelPlugin } from "./esbuild-babel";
export { createPostCSS } from "./shared";
@ -25,9 +26,14 @@ export interface TailwindPluginOptions {
tailwindConfig?: Omit<Config, "content">;
/**
* Directives to prefix to all Tailwind stylesheets
* Prefix to all Tailwind stylesheets
*
* @example
* tailwind base;
* tailwind components;
* tailwind utilities;
*/
directives?: (typeof tailwindDirectives)[number][] | "all" | undefined;
prefix?: string;
/**
* Additional PostCSS plugins (optional)
@ -76,10 +82,19 @@ export interface TailwindPluginOptions {
* @example
* async css => (await postcss.process(css, { plugins: [tailwindcss()] })).css
*/
compile(css: string): Promise<string>;
compile?(css: string): Promise<string>;
}
export type ResolveTailwindOptions = Required<TailwindPluginOptions>;
export type ResolveTailwindOptions = SetRequired<
TailwindPluginOptions,
| "clsx"
| "jsxAttributeAction"
| "jsxAttributeName"
| "postCSSPlugins"
| "styleMap"
| "tailwindConfig"
| "taggedTemplateName"
>;
/**
* Hashes and prefixes a string of Tailwind class names.
@ -105,7 +120,6 @@ export const getClassName: GetClassName = cls => "tw-" + hash(cls);
*/
export function getTailwindPlugins(options: TailwindPluginOptions) {
const resolvedOptions: ResolveTailwindOptions = {
directives: undefined,
getClassName,
jsxAttributeAction: "delete",
jsxAttributeName: "css",