Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: detect Tailwind in PostCSS plugins object #6468

Merged
merged 1 commit into from
May 24, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions .changeset/gorgeous-fireants-fry.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
---
"@remix-run/dev": patch
---

Fix Tailwind performance issue when `postcss.config.js` contains `plugins: { tailwindcss: {} }` and `remix.config.js` contains both `tailwind: true` and `postcss: true`.

Note that this was _not_ an issue when the plugin function had been explicitly called, i.e. `plugins: [tailwindcss()]`. Remix avoids adding the Tailwind plugin to PostCSS if it's already present but we were failing to detect when the plugin function hadn't been called — either because the plugin function itself had been passed, i.e. `plugins: [require('tailwindcss')]`, or the plugin config object syntax had been used, i.e. `plugins: { tailwindcss: {} }`.
11 changes: 8 additions & 3 deletions packages/remix-dev/compiler/utils/postcss.ts
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ export async function loadPostcssPlugins({

if (config.tailwind) {
let tailwindPlugin = await loadTailwindPlugin(config);
if (tailwindPlugin && !hasTailwindPlugin(plugins)) {
if (tailwindPlugin && !hasTailwindPlugin(plugins, tailwindPlugin)) {
plugins.push(tailwindPlugin);
}
}
Expand Down Expand Up @@ -94,10 +94,15 @@ export async function getPostcssProcessor({
return processor;
}

function hasTailwindPlugin(plugins: Array<AcceptedPlugin>) {
function hasTailwindPlugin(
plugins: Array<AcceptedPlugin>,
tailwindPlugin: AcceptedPlugin
) {
return plugins.some(
(plugin) =>
"postcssPlugin" in plugin && plugin.postcssPlugin === "tailwindcss"
plugin === tailwindPlugin ||
(typeof plugin === "function" && plugin.name === "tailwindcss") ||
("postcssPlugin" in plugin && plugin.postcssPlugin === "tailwindcss")
);
}

Expand Down