Closed maxkoretskyi closed 2 years ago
Styles are compiled with the library before rendering in the app. So it has no idea what @apply
is.
Either put the Tailwind classes inside the tsx
file in the className
prop directly, or copy both postcss.config.js
and tailwind.config.js
into the lib root. As for the Tailwind config, here's how to prevent the duplication:
// libs/ui/tailwind.config.js
/** @type {import('tailwindcss').Config} */
module.exports = { presets: [require('../../apps/me/tailwind.config.js')] };
This issue is due to the postcss.config.js
not applying to the UI library. By default, postcss will apply the closest postcss.config.js
file to the file being processed.
In this case, there is no postcss.config.js
for the library, so nothing is applied.
You can fix by manually setting the app's postcss config to be applied to everything (and opt out of the default behavior).
{
// ...
"targets": {
"build": {
"executor": "@nrwl/web:webpack",
"outputs": ["{options.outputPath}"],
"defaultConfiguration": "production",
"options": {
// ...
"postcssConfig": "apps/me/postcss.config.js", // <--- This is the fix
"webpackConfig": "@nrwl/react/plugins/webpack"
},
// ...
}
I'll update the guide to include this information. The reason why we cannot just make this the default behavior is that the libraries may have their own postcss/tailwind config.
@jaysoo appreciate quick reply! yeah, it would be great to have this in the doc :)
This issue has been closed for more than 30 days. If this issue is still occuring, please open a new issue with more recent context.
Current Behavior
Tailwind
@apply
directive isn't processed by Tailwind in a React library.All works good with the main application.
Expected Behavior
Tailwind
@apply
directive should be processed by Tailwind in libraries same way as in the main application.Steps to Reproduce
nx g lib ui
. Added@apply
tailwind directive to the styles of the generated component.I did a bit of debugging, and it seems that
...createGlobPatternsForDependencies(__dirname),
correctly adds second entry to thecontent
property of thetailwind.config.js
. Here is what I saw while debugging:Minimal github repo is here. Here's generated tailwind.config.js and postcss.config.js.
Environment