Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Next Next commit
comment why we run optimize twice
  • Loading branch information
RobinMalfait committed Nov 6, 2024
commit 53b6aff30cfc40632a1927641199b8216f53e5fa
2 changes: 2 additions & 0 deletions packages/@tailwindcss-cli/src/commands/build/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -431,5 +431,7 @@ function optimizeCss(
}).code
}

// Running Lightning CSS twice to ensure that adjacent rules are merged after
// nesting is applied. This creates a more optimized output.
return optimize(optimize(Buffer.from(input))).toString()
}
2 changes: 2 additions & 0 deletions packages/@tailwindcss-postcss/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -239,6 +239,8 @@ function optimizeCss(
}).code
}

// Running Lightning CSS twice to ensure that adjacent rules are merged after
// nesting is applied. This creates a more optimized output.
return optimize(optimize(Buffer.from(input))).toString()
}

Expand Down
2 changes: 2 additions & 0 deletions packages/@tailwindcss-vite/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,8 @@ function optimizeCss(
}).code
}

// Running Lightning CSS twice to ensure that adjacent rules are merged after
// nesting is applied. This creates a more optimized output.
return optimize(optimize(Buffer.from(input))).toString()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if we can get away with running optimize just once if lightningcss is configured as the CSS processor... It might have a different config so probably not 😬

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah that's tricky. Our config sets Safari to a version that doesn't understand nesting yet.

One suggestion that Devon had was to put @media queries on the outside instead of nested to do the merging, but the current change is a bit easier especially once Lightning CSS can handle this natively.

}

Expand Down
2 changes: 2 additions & 0 deletions packages/tailwindcss/src/test-utils/run.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,7 @@ export function optimizeCss(
}).code
}

// Running Lightning CSS twice to ensure that adjacent rules are merged after
// nesting is applied. This creates a more optimized output.
return optimize(optimize(Buffer.from(input))).toString()
}