diff --git a/CHANGELOG.md b/CHANGELOG.md index 85901f90c98b..db143291e276 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Added + +- Add `@reference "…"` API as a replacement for the previous `@import "…" reference` option ([#15565](https://github.com/tailwindlabs/tailwindcss/pull/15565)) + ### Fixed - Use the correct property value for `place-content-between`, `place-content-around`, and `place-content-evenly` utilities ([#15440](https://github.com/tailwindlabs/tailwindcss/pull/15440)) diff --git a/packages/tailwindcss/src/at-import.test.ts b/packages/tailwindcss/src/at-import.test.ts index dafb8af07fd5..108498216d9a 100644 --- a/packages/tailwindcss/src/at-import.test.ts +++ b/packages/tailwindcss/src/at-import.test.ts @@ -553,3 +553,36 @@ test('it crashes when inside a cycle', async () => { `[Error: Exceeded maximum recursion depth while resolving \`foo.css\` in \`/root\`)]`, ) }) + +test('resolves @reference as `@import "…" reference`', async () => { + let loadStylesheet = async (id: string, base: string) => { + expect(base).toBe('/root') + expect(id).toBe('./foo/bar.css') + return { + content: css` + @theme { + --color-red-500: red; + } + .foo { + color: red; + } + `, + base: '/root/foo', + } + } + + await expect( + run( + css` + @reference './foo/bar.css'; + @tailwind utilities; + `, + { loadStylesheet, candidates: ['text-red-500'] }, + ), + ).resolves.toMatchInlineSnapshot(` + ".text-red-500 { + color: var(--color-red-500); + } + " + `) +}) diff --git a/packages/tailwindcss/src/at-import.ts b/packages/tailwindcss/src/at-import.ts index 4a585202d531..effd33e5b203 100644 --- a/packages/tailwindcss/src/at-import.ts +++ b/packages/tailwindcss/src/at-import.ts @@ -15,9 +15,12 @@ export async function substituteAtImports( let promises: Promise[] = [] walk(ast, (node, { replaceWith }) => { - if (node.kind === 'at-rule' && node.name === '@import') { + if (node.kind === 'at-rule' && (node.name === '@import' || node.name === '@reference')) { let parsed = parseImportParams(ValueParser.parse(node.params)) if (parsed === null) return + if (node.name === '@reference') { + parsed.media = 'reference' + } features |= Features.AtImport