Add support for PostCSS Document nodes (#7291)

* Run Tailwind CSS once for each root in a postcss document

* Update changelog
This commit is contained in:
Jordan Pittman 2022-02-25 14:52:20 -05:00 committed by GitHub
parent cd8f109981
commit 4fed060b7c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 51 additions and 1 deletions

View File

@ -25,6 +25,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Allow default ring color to be a function ([#7587](https://github.com/tailwindlabs/tailwindcss/pull/7587))
- Add `rgb` and `hsl` color helpers for CSS variables ([#7665](https://github.com/tailwindlabs/tailwindcss/pull/7665))
- Support PostCSS `Document` nodes ([#7291](https://github.com/tailwindlabs/tailwindcss/pull/7291))
## [3.0.23] - 2022-02-16

View File

@ -13,7 +13,21 @@ module.exports = function tailwindcss(configOrPath) {
return root
},
function (root, result) {
processTailwindFeatures(setupTrackingContext(configOrPath))(root, result)
let context = setupTrackingContext(configOrPath)
if (root.type === 'document') {
let roots = root.nodes.filter((node) => node.type === 'root')
for (const root of roots) {
if (root.type === 'root') {
processTailwindFeatures(context)(root, result)
}
}
return
}
processTailwindFeatures(context)(root, result)
},
env.DEBUG &&
function (root) {

View File

@ -1,5 +1,6 @@
import fs from 'fs'
import path from 'path'
import postcss from 'postcss'
import { run, css, html, defaults } from './util/run'
@ -568,3 +569,37 @@ test('The visited variant removes opacity support', () => {
`)
})
})
it('appends variants to the correct place when using postcss documents', () => {
let config = {
content: [{ raw: html`<div class="underline sm:underline"></div>` }],
plugins: [],
corePlugins: { preflight: false },
}
const doc = postcss.document()
doc.append(postcss.parse(`a {}`))
doc.append(postcss.parse(`@tailwind base`))
doc.append(postcss.parse(`@tailwind utilities`))
doc.append(postcss.parse(`b {}`))
const result = doc.toResult()
return run(result, config).then((result) => {
return expect(result.css).toMatchFormattedCss(css`
a {
}
${defaults}
.underline {
text-decoration-line: underline;
}
@media (min-width: 640px) {
.sm\:underline {
text-decoration-line: underline;
}
}
b {
}
`)
})
})