Add Vite support for configurable Lightning CSS options and polyfills#19942
Add Vite support for configurable Lightning CSS options and polyfills#19942lubomirblazekcz wants to merge 1 commit intotailwindlabs:mainfrom
Conversation
WalkthroughThese changes expand the Vite plugin's configuration capabilities by introducing support for granular Lightning CSS settings and polyfill control. The 🚥 Pre-merge checks | ✅ 2✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
Actionable comments posted: 1
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Inline comments:
In `@packages/`@tailwindcss-vite/README.md:
- Around line 80-82: Add a short caveat to the "Controlling Tailwind polyfills"
section clarifying that although Tailwind emits supported polyfills by default,
this Vite adapter masks the Polyfills.AtProperty for .module.css files to avoid
introducing global/non-pure selectors; reference the polyfills option and
Polyfills.AtProperty so readers know this is an intentional Vite-specific
exception and not a bug in Tailwind.
🪄 Autofix (Beta)
Fix all unresolved CodeRabbit comments on this PR:
- Push a commit to this branch (recommended)
- Create a new PR with the fixes
ℹ️ Review info
⚙️ Run configuration
Configuration used: Repository UI
Review profile: CHILL
Plan: Pro
Run ID: fd6d4611-67fc-4c2f-b347-15d2aff136de
📒 Files selected for processing (4)
integrations/vite/index.test.tspackages/@tailwindcss-node/src/optimize.tspackages/@tailwindcss-vite/README.mdpackages/@tailwindcss-vite/src/index.ts
| ## Controlling Tailwind polyfills | ||
|
|
||
| By default, Tailwind emits all supported CSS polyfills. You can customize this behavior using the `polyfills` option: |
There was a problem hiding this comment.
Mention the CSS Modules polyfill exception.
Line 82 says Tailwind emits all supported polyfills by default, but the Vite implementation masks Polyfills.AtProperty for .module.css files to avoid global non-pure selectors. A short caveat here would keep the docs aligned with the implementation.
📝 Proposed wording
-By default, Tailwind emits all supported CSS polyfills. You can customize this behavior using the `polyfills` option:
+By default, Tailwind emits all supported CSS polyfills. In Vite CSS Modules, the `@property` fallback polyfill is still suppressed because it emits global selectors. You can customize this behavior using the `polyfills` option:📝 Committable suggestion
‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.
| ## Controlling Tailwind polyfills | |
| By default, Tailwind emits all supported CSS polyfills. You can customize this behavior using the `polyfills` option: | |
| ## Controlling Tailwind polyfills | |
| By default, Tailwind emits all supported CSS polyfills. In Vite CSS Modules, the `@property` fallback polyfill is still suppressed because it emits global selectors. You can customize this behavior using the `polyfills` option: |
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@packages/`@tailwindcss-vite/README.md around lines 80 - 82, Add a short
caveat to the "Controlling Tailwind polyfills" section clarifying that although
Tailwind emits supported polyfills by default, this Vite adapter masks the
Polyfills.AtProperty for .module.css files to avoid introducing global/non-pure
selectors; reference the polyfills option and Polyfills.AtProperty so readers
know this is an intentional Vite-specific exception and not a bug in Tailwind.
|
I'm considering removing the additional Lightning CSS options as setting from this PR. Setting But I think ability to configuring polyfills would be neat. Thoughts? |
Summary
This updates the
@tailwindcss/viteplugin so theoptimizeoption can pass through additional Lightning CSS settings instead of only supportingminify. In addition tominify, Vite users can now configuredrafts,nonStandard,include,exclude, andtargets.It also adds a
polyfillsoption to the Vite plugin and threads that through to the Tailwind compiler, matching the behavior that already exists in the PostCSS and Webpack integrations. CSS Modules continue to disable the@propertyfallback polyfill so they do not emit global non-pure selectors.While making this change, the Vite integration now only overrides
minifywhen it is explicitly provided inoptimize, which preserves Vite's existingbuild.cssMinifybehavior when users only want to customize other Lightning CSS options.Test plan
pnpm vitest --root=./integrations run vite/index.test.ts -t "optimize option: disabled|optimize option: enabled with minify disabled|optimize option: advanced Lightning CSS settings|optimize option: advanced Lightning CSS exclude|polyfills option: disabled"Screenshots not applicable; this change is covered by the Vite integration tests above.