From 78f5b087d4f7168f8a6b41ed56600ba7f60a612c Mon Sep 17 00:00:00 2001 From: Philipp Spiess Date: Tue, 3 Dec 2024 14:15:24 +0100 Subject: [PATCH] =?UTF-8?q?Add=20`@import=20"=E2=80=A6"=20reference`=20(#1?= =?UTF-8?q?5228)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Closes #15219 This PR adds a new feature, `@import "…" reference` that can be used to load Tailwind CSS configuration files without adding any style rules to the CSS. The idea is that you can use this in combination with your Tailwind CSS root file when you need to have access to your full CSS config outside of the main stylesheet. A common example is for Vue, Svelte, or CSS modules: ```css @import "./tailwind.css" reference; .link { @apply underline; } ``` Importing a file as a reference will convert all `@theme` block to be `reference`, so no CSS variables will be emitted. Furthermore it will strip out all custom styles from the stylesheet. Furthermore plugins registered via `@plugin` or `@config` inside reference-mode files will not add any content to the CSS file via `addBase()`. ## Test Plan Added unit test for when we handle the import resolution and when `postcss-import` does it outside of Tailwind CSS. I also changed the Svelte and Vue integration tests to use this new syntax to ensure it works end to end. --------- Co-authored-by: Jordan Pittman --- CHANGELOG.md | 11 +-- integrations/vite/svelte.test.ts | 5 +- integrations/vite/vue.test.ts | 6 +- packages/tailwindcss/src/ast.ts | 12 +-- .../src/compat/apply-compat-hooks.ts | 41 ++++++--- .../src/compat/config/resolve-config.ts | 16 ++-- .../tailwindcss/src/compat/plugin-api.test.ts | 46 ++++++++++ packages/tailwindcss/src/compat/plugin-api.ts | 8 +- packages/tailwindcss/src/index.test.ts | 86 +++++++++++++++++++ packages/tailwindcss/src/index.ts | 35 +++++++- 10 files changed, 226 insertions(+), 40 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index a8087a60e..af3d866f3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Parallelize parsing of individual source files ([#15270](https://github.com/tailwindlabs/tailwindcss/pull/15270)) +- Support Vite 6 in the Vite plugin ([#15274](https://github.com/tailwindlabs/tailwindcss/issues/15274)) +- Add a new `@import "…" reference` syntax for only importing the Tailwind CSS configurations of a stylesheets ([#15228](https://github.com/tailwindlabs/tailwindcss/pull/15228)) + ### Fixed - Ensure absolute `url()`s inside imported CSS files are not rebased when using `@tailwindcss/vite` ([#15275](https://github.com/tailwindlabs/tailwindcss/pull/15275)) @@ -15,11 +21,6 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Ensure other plugins can run after `@tailwindcss/postcss` ([#15273](https://github.com/tailwindlabs/tailwindcss/pull/15273)) - Rebase `url()` inside imported CSS files when using Vite with the `@tailwindcss/postcss` extension ([#15273](https://github.com/tailwindlabs/tailwindcss/pull/15273)) -### Added - -- Parallelize parsing of individual source files ([#15270](https://github.com/tailwindlabs/tailwindcss/pull/15270)) -- Support Vite 6 in the Vite plugin ([#15274](https://github.com/tailwindlabs/tailwindcss/issues/15274)) - ## [4.0.0-beta.4] - 2024-11-29 ### Fixed diff --git a/integrations/vite/svelte.test.ts b/integrations/vite/svelte.test.ts index b0950f9f9..0f7953c63 100644 --- a/integrations/vite/svelte.test.ts +++ b/integrations/vite/svelte.test.ts @@ -48,10 +48,7 @@ test( target: document.body, }) `, - 'src/index.css': css` - @import 'tailwindcss/theme' theme(reference); - @import 'tailwindcss/utilities'; - `, + 'src/index.css': css`@import 'tailwindcss' reference;`, 'src/App.svelte': html`