deno.land / x / lume@v2.1.4 / plugins / tailwindcss.ts

tailwindcss.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
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
import tailwind from "../deps/tailwindcss.ts";import { getExtension } from "../core/utils/path.ts";import { merge } from "../core/utils/object.ts";
import type { Config } from "../deps/tailwindcss.ts";import type Site from "../core/site.ts";
export interface Options { /** Extensions processed by this plugin to extract the utility classes */ extensions?: string[];
/** * Options passed to TailwindCSS. * @see https://tailwindcss.com/docs/configuration */ options?: Omit<Config, "content">;}
export const defaults: Options = { extensions: [".html"],};
export default function (userOptions?: Options) { const options = merge(defaults, userOptions);
return (site: Site) => { // deno-lint-ignore no-explicit-any let tailwindPlugins: any[];
if (site.hooks.postcss) { throw new Error( "PostCSS plugin is required to be installed AFTER TailwindCSS plugin", ); }
site.process(options.extensions, (pages) => { // Get the content of all HTML pages (sorted by path) const content = pages.sort((a, b) => a.src.path.localeCompare(b.src.path)) .map((page) => ({ raw: page.content as string, extension: getExtension(page.outputPath).substring(1), }));
// Create Tailwind plugin // @ts-ignore: This expression is not callable. const plugin = tailwind({ ...options.options, content, });
// Ensure PostCSS plugin is installed if (!site.hooks.postcss) { throw new Error( "PostCSS plugin is required to be installed AFTER TailwindCSS plugin", ); }
// Replace the old Tailwind plugin configuration from PostCSS plugins // deno-lint-ignore no-explicit-any site.hooks.postcss((runner: any) => { tailwindPlugins?.forEach((plugin) => { runner.plugins.splice(runner.plugins.indexOf(plugin), 1); }); tailwindPlugins = runner.normalize([plugin]); runner.plugins = runner.plugins.concat(tailwindPlugins); }); }); };}
lume

Version Info

Tagged at
7 months ago