MCPcopy
hub / github.com/freshframework/fresh / initTailwind

Function initTailwind

packages/plugin-tailwindcss-v3/src/mod.ts:105–144  ·  view source on GitHub ↗
(
  config: ResolvedBuildConfig,
  options: TailwindPluginOptions,
)

Source from the content-addressed store, hash-verified

103}
104
105async 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}

Callers 1

tailwindFunction · 0.85

Calls 2

findTailwindConfigFileFunction · 0.85
cwdMethod · 0.80

Tested by

no test coverage detected