Ensure to transpile the PostCSS Nesting plugin (tailwindcss/nesting) (#7080)
* ensure that we compile the postcss nesting plugin * re-add optional chaining This will allow us to be 100% sure that we can safely call hasOwnProperty in case we get some very strange objects. This will now also be compiled/transpiled by esbuild. * import the internal postcss nesting plugin This allows us to work on it without re-compiling while running tests. Just like we do with all other code. * update changelog
This commit is contained in:
parent
61b68a2149
commit
167668e9cf
6 changed files with 25 additions and 20 deletions
44
src/postcss-plugins/nesting/plugin.js
Normal file
44
src/postcss-plugins/nesting/plugin.js
Normal file
|
|
@ -0,0 +1,44 @@
|
|||
import postcss from 'postcss'
|
||||
import postcssNested from 'postcss-nested'
|
||||
|
||||
export function nesting(opts = postcssNested) {
|
||||
return (root, result) => {
|
||||
root.walkAtRules('screen', (rule) => {
|
||||
rule.name = 'media'
|
||||
rule.params = `screen(${rule.params})`
|
||||
})
|
||||
|
||||
root.walkAtRules('apply', (rule) => {
|
||||
rule.before(postcss.decl({ prop: '__apply', value: rule.params, source: rule.source }))
|
||||
rule.remove()
|
||||
})
|
||||
|
||||
let plugin = (() => {
|
||||
if (
|
||||
typeof opts === 'function' ||
|
||||
(typeof opts === 'object' && opts?.hasOwnProperty?.('postcssPlugin'))
|
||||
) {
|
||||
return opts
|
||||
}
|
||||
|
||||
if (typeof opts === 'string') {
|
||||
return require(opts)
|
||||
}
|
||||
|
||||
if (Object.keys(opts).length <= 0) {
|
||||
return postcssNested
|
||||
}
|
||||
|
||||
throw new Error('tailwindcss/nesting should be loaded with a nesting plugin.')
|
||||
})()
|
||||
|
||||
postcss([plugin]).process(root, result.opts).sync()
|
||||
|
||||
root.walkDecls('__apply', (decl) => {
|
||||
decl.before(postcss.atRule({ name: 'apply', params: decl.value, source: decl.source }))
|
||||
decl.remove()
|
||||
})
|
||||
|
||||
return root
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue