The PostCSS config of UXF frontend projects on Tailwind CSS 3 and Next.js: the postcss.config.js most projects carry
byte for byte (108 of the 151 copies found in project checkouts). Most of the others add postcss-focus-visible in
front.
In this order:
postcss-import: inlines the @imports, so that Tailwind sees one stylesheet. Without it the build fails on the
first @apply of a class defined in another file (The uxf-typo-h6 class does not exist in @uxf/ui/css/message.css),
with webpack and with Turbopack.tailwindcss/nesting: nested rules, before Tailwind expands @apply in them.tailwindcss: Tailwind CSS 3 with the project's tailwind.config.js.autoprefixer: vendor prefixes for the browserslist (@uxf/browserslist-config).postcss-pxtorem: every px value from 1 px up becomes rem, in every property, so that the page scales with the
browser's font size.yarn add -D @uxf/postcss-config
yarn dependencies:fix
Next.js resolves each plugin by its name from the project, not from this package, so the plugins are peer
dependencies: autoprefixer, postcss, postcss-import, postcss-pxtorem and tailwindcss 3. A project with
@uxf/scripts gets the missing ones from yarn dependencies:fix; the usual UXF project has all of them already.
// postcss.config.js
module.exports = require("@uxf/postcss-config");
A project that needs one more plugin spreads the config. Key order is plugin order, so a plugin that has to run first goes first:
// postcss.config.js
const uxfPostcssConfig = require("@uxf/postcss-config");
module.exports = {
plugins: {
"postcss-focus-visible": {},
...uxfPostcssConfig.plugins,
},
};
Before keeping postcss-focus-visible, check whether the project still needs it: every browser of
@uxf/browserslist-config supports :focus-visible, so the plugin only matters for CSS written against its polyfill
(a .focus-visible class or [data-focus-visible-added]).
uxf-base/web built (next build --experimental-build-mode=compile) with its own postcss.config.js, with this
package, and with one plugin left out at a time:
With this package the webpack build wrote byte for byte the CSS of the project's own config.
@tailwindcss/postcss inlines imports, nests and prefixes on its own, so the config shrinks to
it and postcss-pxtorem. That is a major release of this package, together with @uxf/ui and
@uxf/stylelint-config.autoprefixer once projects build with Turbopack, where it changes nothing (above).