Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added

- Add `@tailwindcss/browser` package to run Tailwind CSS in the browser ([#15558](https://github.com/tailwindlabs/tailwindcss/pull/15558))
- Add `@reference "…"` API as a replacement for the previous `@import "…" reference` option ([#15565](https://github.com/tailwindlabs/tailwindcss/pull/15565))

### Fixed

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';
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Need to add support for this to IntelliSense. I've made a note to do that.

@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