Skip to content

Commit 8c79408

Browse files
Add @reference "…"
1 parent af33451 commit 8c79408

File tree

3 files changed

+41
-2
lines changed

3 files changed

+41
-2
lines changed

CHANGELOG.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Added
11+
12+
- Add `@reference "…"` API as a replacement for the previous `@import "…" reference` option ([#15228](https://github.com/tailwindlabs/tailwindcss/pull/15228))
13+
1014
### Fixed
1115

1216
- 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))
@@ -782,4 +786,3 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
782786
## [4.0.0-alpha.1] - 2024-03-06
783787

784788
- First 4.0.0-alpha.1 release
785-

packages/tailwindcss/src/at-import.test.ts

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -553,3 +553,36 @@ test('it crashes when inside a cycle', async () => {
553553
`[Error: Exceeded maximum recursion depth while resolving \`foo.css\` in \`/root\`)]`,
554554
)
555555
})
556+
557+
test('resolves @reference as `@import "…" reference`', async () => {
558+
let loadStylesheet = async (id: string, base: string) => {
559+
expect(base).toBe('/root')
560+
expect(id).toBe('./foo/bar.css')
561+
return {
562+
content: css`
563+
@theme {
564+
--color-red-500: red;
565+
}
566+
.foo {
567+
color: red;
568+
}
569+
`,
570+
base: '/root/foo',
571+
}
572+
}
573+
574+
await expect(
575+
run(
576+
css`
577+
@reference './foo/bar.css';
578+
@tailwind utilities;
579+
`,
580+
{ loadStylesheet, candidates: ['text-red-500'] },
581+
),
582+
).resolves.toMatchInlineSnapshot(`
583+
".text-red-500 {
584+
color: var(--color-red-500);
585+
}
586+
"
587+
`)
588+
})

packages/tailwindcss/src/at-import.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,12 @@ export async function substituteAtImports(
1515
let promises: Promise<void>[] = []
1616

1717
walk(ast, (node, { replaceWith }) => {
18-
if (node.kind === 'at-rule' && node.name === '@import') {
18+
if (node.kind === 'at-rule' && (node.name === '@import' || node.name === '@reference')) {
1919
let parsed = parseImportParams(ValueParser.parse(node.params))
2020
if (parsed === null) return
21+
if (node.name === '@reference') {
22+
parsed.media = 'reference'
23+
}
2124

2225
features |= Features.AtImport
2326

0 commit comments

Comments
 (0)