Skip to content

Commit

Permalink
Add @reference "…"
Browse files Browse the repository at this point in the history
  • Loading branch information
philipp-spiess committed Jan 7, 2025
1 parent d4f693f commit 60f4ddf
Show file tree
Hide file tree
Showing 3 changed files with 41 additions and 1 deletion.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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))
Expand Down
33 changes: 33 additions & 0 deletions packages/tailwindcss/src/at-import.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
"
`)
})
5 changes: 4 additions & 1 deletion packages/tailwindcss/src/at-import.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,12 @@ export async function substituteAtImports(
let promises: Promise<void>[] = []

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

Expand Down

0 comments on commit 60f4ddf

Please sign in to comment.