diff --git a/CHANGELOG.md b/CHANGELOG.md index 79f3c2f30c65..15701c0e8b21 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Use `default` export condition for `@tailwindcss/vite` ([#18948](https://github.com/tailwindlabs/tailwindcss/pull/18948)) - Re-throw errors from PostCSS nodes ([#18373](https://github.com/tailwindlabs/tailwindcss/pull/18373)) - Detect classes in markdown inline directives ([#18967](https://github.com/tailwindlabs/tailwindcss/pull/18967)) +- Ensure files with only `@theme` produce no output when built ([#18979](https://github.com/tailwindlabs/tailwindcss/pull/18979)) ## [4.1.13] - 2025-09-03 diff --git a/packages/tailwindcss/src/index.test.ts b/packages/tailwindcss/src/index.test.ts index cfd0d1db8909..ce8b7f6013c9 100644 --- a/packages/tailwindcss/src/index.test.ts +++ b/packages/tailwindcss/src/index.test.ts @@ -5965,4 +5965,18 @@ describe('feature detection', () => { expect(compiler.features & Features.AtImport).toBeTruthy() expect(compiler.features & Features.Utilities).toBeFalsy() }) + + test('using `@theme`', async () => { + let compiler = await compile(css` + @theme { + --tracking-narrower: -0.02em; + } + `) + + // We see @theme + expect(compiler.features & Features.AtTheme).toBeTruthy() + + // And this produces no output because no other CSS is present + expect(compiler.build([])).toEqual('') + }) }) diff --git a/packages/tailwindcss/src/index.ts b/packages/tailwindcss/src/index.ts index ca2a0b0df16b..8c668b6946fb 100644 --- a/packages/tailwindcss/src/index.ts +++ b/packages/tailwindcss/src/index.ts @@ -133,6 +133,9 @@ export const enum Features { // `@variant` was used Variants = 1 << 5, + + // `@theme` was used + AtTheme = 1 << 6, } async function parseCss( @@ -540,6 +543,8 @@ async function parseCss( if (node.name === '@theme') { let [themeOptions, themePrefix] = parseThemeOptions(node.params) + features |= Features.AtTheme + if (context.reference) { themeOptions |= ThemeOptions.REFERENCE }