I am currently working on an application that consists of two main parts:
- (
X
) an older AngularJs legacy application with its own set of CSS classes. - (
Y
) a new React application contained within adiv
. This new part (Y
) is built using webpack, postcss, and TailwindCSS.
My main concern is ensuring that the TailwindCSS classes used in part Y
do not clash with the stylesheets of part X
, and vice versa, without making significant changes to the existing codebase.
Challenges to Overcome
Although I have explored some possible solutions, most of them seem to involve drastic modifications:
- One option involves utilizing the TailwindCSS prefix configuration, but I am hesitant to prefix a large number of classes due to the length of the prefix itself.
- Another approach is to use css-modules with local imports. However, I am uncertain about how well this method integrates with TailwindCSS, and I find the process of locally importing classes from various sources to be verbose and cumbersome.
Possible Solutions
While I have come across a couple of postcss plugins that seem promising, they have their limitations:
postcss-rename
is effective, but it does not address the renaming of classes within*.js
files.purgecss
can identify classes based on their presence in*.js
files and remove them from the output list, but it lacks the ability to rename classes.
One feature that appears to be missing in existing solutions is the parser for *.js
files within purgecss
.
An Ongoing Challenge
Is there a way to automatically apply a custom transformation (e.g., renaming) to all postcss classes, including those used in HTML/JSX elements? Alternatively, is there a method for webpack to automatically resolve CSS class conflicts?