Skip to content

Commit c6e0a55

Browse files
Ensure files with only @theme produce no output when built (#18979)
Closes #18978
1 parent 9a5bae2 commit c6e0a55

File tree

3 files changed

+20
-0
lines changed

3 files changed

+20
-0
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2525
- Use `default` export condition for `@tailwindcss/vite` ([#18948](https://github.com/tailwindlabs/tailwindcss/pull/18948))
2626
- Re-throw errors from PostCSS nodes ([#18373](https://github.com/tailwindlabs/tailwindcss/pull/18373))
2727
- Detect classes in markdown inline directives ([#18967](https://github.com/tailwindlabs/tailwindcss/pull/18967))
28+
- Ensure files with only `@theme` produce no output when built ([#18979](https://github.com/tailwindlabs/tailwindcss/pull/18979))
2829

2930
## [4.1.13] - 2025-09-03
3031

packages/tailwindcss/src/index.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5965,4 +5965,18 @@ describe('feature detection', () => {
59655965
expect(compiler.features & Features.AtImport).toBeTruthy()
59665966
expect(compiler.features & Features.Utilities).toBeFalsy()
59675967
})
5968+
5969+
test('using `@theme`', async () => {
5970+
let compiler = await compile(css`
5971+
@theme {
5972+
--tracking-narrower: -0.02em;
5973+
}
5974+
`)
5975+
5976+
// We see @theme
5977+
expect(compiler.features & Features.AtTheme).toBeTruthy()
5978+
5979+
// And this produces no output because no other CSS is present
5980+
expect(compiler.build([])).toEqual('')
5981+
})
59685982
})

packages/tailwindcss/src/index.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,9 @@ export const enum Features {
133133

134134
// `@variant` was used
135135
Variants = 1 << 5,
136+
137+
// `@theme` was used
138+
AtTheme = 1 << 6,
136139
}
137140

138141
async function parseCss(
@@ -540,6 +543,8 @@ async function parseCss(
540543
if (node.name === '@theme') {
541544
let [themeOptions, themePrefix] = parseThemeOptions(node.params)
542545

546+
features |= Features.AtTheme
547+
543548
if (context.reference) {
544549
themeOptions |= ThemeOptions.REFERENCE
545550
}

0 commit comments

Comments
 (0)