Replies: 1 comment
-
I also stumbled upon the source order problem. I found another possible solution. You can include the Package in the // tailwind.config.js
export default {
content: [
'./node_modules/frontend-lib/dist/**/*.{js,mjs,jsx,ts,tsx}',
'./src/**/*.{js,mjs,jsx,ts,tsx}',
],
} This will also include the styles of the frontend-lib package in the output CSS file. |
Beta Was this translation helpful? Give feedback.
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
TL;DR: It would be useful to be able to merge the output of two or more Tailwind builds safely, avoiding source-order issues. Might this be added either to Tailwind (as a new
@
rule), or as a separate PostCSS plug-in?In detail
We use TailwindCSS to:
As a result, we have the CSS output of two TailwindCSS builds coexisting in a single page. Ideally, we would like to maintain a single TailwindCSS configuration, so that our engineers can use the same utility class names regardless of whether they're working on a shared component or an application codebase.
Unfortunately, two identically-configured TailwindCSS builds cannot currently coexist on the same page safely, because Tailwind's CSS output depends on source order (e.g. shorthand properties like
m-0
are generated before non-shorthand properties likems-4
). Here's an example of the kind of source-order problem you encounter when you load two Tailwind stylesheets on the same page:Currently, the only way to resolve this is to configure one or both of the two Tailwind builds with a
prefix
. For example, you might configure your component library with a prefix of'lib-'
:As mentioned above, this is non-ideal because engineers need to context-switch depending on whether they are working in the shared component codebase or the application codebase.
I have written this use case up in greater detail on my blog, here: Use TailwindCSS prefixes for shared design system components
Proposal
A typical TailwindCSS stylesheet is written like this:
When we attempt to pull in the CSS file for a component library, it looks like this:
What if we could do this:
@tailwindImport
could parse the provided CSS file for Tailwind selectors matching the current build's configuration, and add them to this build'ssafelist
(i.e. the list of utilities that will be generated even if they don't appear in the project source code). The output resulting from the following three@tailwind
directives would therefore be a safe merge of the styles used by the component library and the styles used by the current application.Alternatively, I could imagine this implemented as a separate postcss plug-in, which would retrospectively de-dupe and reorder Tailwind styles found in a stylesheet containing multiple Tailwind build outputs, given the Tailwind config of those builds:
This feels harder to implement than the above
@tailwindImport
suggestion, though.Beta Was this translation helpful? Give feedback.
All reactions