( config: ResolvedBuildConfig, options: TailwindPluginOptions, )
| 103 | } |
| 104 | |
| 105 | async function initTailwind( |
| 106 | config: ResolvedBuildConfig, |
| 107 | options: TailwindPluginOptions, |
| 108 | ): Promise<postcss.Processor> { |
| 109 | const root = config.root; |
| 110 | |
| 111 | const configPath = await findTailwindConfigFile(root); |
| 112 | const url = path.toFileUrl(configPath).href; |
| 113 | const tailwindConfig = (await import(url)).default as Config; |
| 114 | |
| 115 | if (!Array.isArray(tailwindConfig.content)) { |
| 116 | throw new Error(`Expected tailwind "content" option to be an array`); |
| 117 | } |
| 118 | |
| 119 | // deno-lint-ignore no-explicit-any |
| 120 | tailwindConfig.content = tailwindConfig.content.map((pattern: any) => { |
| 121 | if (typeof pattern === "string") { |
| 122 | const relative = path.relative(Deno.cwd(), path.dirname(configPath)); |
| 123 | |
| 124 | if (!relative.startsWith("..")) { |
| 125 | return path.join(relative, pattern); |
| 126 | } |
| 127 | } |
| 128 | return pattern; |
| 129 | }); |
| 130 | |
| 131 | // PostCSS types cause deep recursion |
| 132 | const plugins = [ |
| 133 | // deno-lint-ignore no-explicit-any |
| 134 | tailwindCss(tailwindConfig) as any, |
| 135 | // deno-lint-ignore no-explicit-any |
| 136 | autoprefixer(options.autoprefixer) as any, |
| 137 | ]; |
| 138 | |
| 139 | if (config.mode === "production") { |
| 140 | plugins.push(cssnano()); |
| 141 | } |
| 142 | |
| 143 | return postcss(plugins); |
| 144 | } |
no test coverage detected