Skip to content

Commit 4fed060

Browse files
Add support for PostCSS Document nodes (#7291)
* Run Tailwind CSS once for each root in a postcss document * Update changelog
1 parent cd8f109 commit 4fed060

File tree

3 files changed

+51
-1
lines changed

3 files changed

+51
-1
lines changed

CHANGELOG.md

+1
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

2626
- Allow default ring color to be a function ([#7587](https://github.com/tailwindlabs/tailwindcss/pull/7587))
2727
- Add `rgb` and `hsl` color helpers for CSS variables ([#7665](https://github.com/tailwindlabs/tailwindcss/pull/7665))
28+
- Support PostCSS `Document` nodes ([#7291](https://github.com/tailwindlabs/tailwindcss/pull/7291))
2829

2930
## [3.0.23] - 2022-02-16
3031

src/index.js

+15-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,21 @@ module.exports = function tailwindcss(configOrPath) {
1313
return root
1414
},
1515
function (root, result) {
16-
processTailwindFeatures(setupTrackingContext(configOrPath))(root, result)
16+
let context = setupTrackingContext(configOrPath)
17+
18+
if (root.type === 'document') {
19+
let roots = root.nodes.filter((node) => node.type === 'root')
20+
21+
for (const root of roots) {
22+
if (root.type === 'root') {
23+
processTailwindFeatures(context)(root, result)
24+
}
25+
}
26+
27+
return
28+
}
29+
30+
processTailwindFeatures(context)(root, result)
1731
},
1832
env.DEBUG &&
1933
function (root) {

tests/variants.test.js

+35
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import fs from 'fs'
22
import path from 'path'
3+
import postcss from 'postcss'
34

45
import { run, css, html, defaults } from './util/run'
56

@@ -568,3 +569,37 @@ test('The visited variant removes opacity support', () => {
568569
`)
569570
})
570571
})
572+
573+
it('appends variants to the correct place when using postcss documents', () => {
574+
let config = {
575+
content: [{ raw: html`<div class="underline sm:underline"></div>` }],
576+
plugins: [],
577+
corePlugins: { preflight: false },
578+
}
579+
580+
const doc = postcss.document()
581+
doc.append(postcss.parse(`a {}`))
582+
doc.append(postcss.parse(`@tailwind base`))
583+
doc.append(postcss.parse(`@tailwind utilities`))
584+
doc.append(postcss.parse(`b {}`))
585+
586+
const result = doc.toResult()
587+
588+
return run(result, config).then((result) => {
589+
return expect(result.css).toMatchFormattedCss(css`
590+
a {
591+
}
592+
${defaults}
593+
.underline {
594+
text-decoration-line: underline;
595+
}
596+
@media (min-width: 640px) {
597+
.sm\:underline {
598+
text-decoration-line: underline;
599+
}
600+
}
601+
b {
602+
}
603+
`)
604+
})
605+
})

0 commit comments

Comments
 (0)