Plugin system using compiled Tailwind CSS files? #19240
Replies: 5 comments 5 replies
-
Does the plugin install in a consistent directory relative to the project, like Otherwise, if the plugin would not install in a consistent directory, consider if there is some way to symlink it inside the project. In this case, presumably, the project has some way to read the plugin code, so perhaps use the same logic to perform some kind of post-install script to symlink the plugin inside the project to a consistent directory. Then you should be able to use |
Beta Was this translation helpful? Give feedback.
-
|
Related: |
Beta Was this translation helpful? Give feedback.
-
|
Thanks for the suggestions! I quickly figured I had a different use-case and updated the questions. I left the original question in at the bottom. The use-case is with compiled files. |
Beta Was this translation helpful? Give feedback.
-
|
Consider using a unique prefix per each plugin. This will ensure class names for that plugin would only be applied to its own code. Though this does mean you will get some duplicate rules, but differentiated by the prefix. |
Beta Was this translation helpful? Give feedback.
-
|
You can avoid CSS conflicts in Avo and its plugins by namespacing each plugin’s Tailwind CSS and shipping it precompiled: 1.Prefix classes in tailwind.config.js for each plugin: 2.Precompile CSS in the plugin repo so users don’t need to run Tailwind: 3.Include the CSS in the Rails app: |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Updated: Compiled files scenario
Hey,
I'm trying to build a plugin system in Rails which ships the compiled Tailwind CSS for the Main app and each plugin.
I don't want to force the user of our product to run a Tailwind build command.
Entities
Avo should be able to load its CSS (compiled using Tailwind) and all of the plugins' CSS (still compiled with Tailwind) and not have clashes and specificity conflicts.
When Avo loads both compiled CSS files we end up with specificity conflicts from the two files (Avo and plugin 1).
The question
How could I build that plugin system and have it be safe and contain all the compiled classes from the main app and all the plugins to play well together?
Thanks!
Original question
Hey,
I'm trying to build a plugin system in Rails which ships the compiled Tailwind CSS for each plugin.
That's rather easy to do.
The more difficult thing is to ensure that the build system on the main app (which uses the plugins) keeps the plugins classes in the compiled output.
Example
We have a Main app (Rails) which loads Plugin 1. The main app has a Tailwind build system which does its thing (scans the project and keeps the used classes).
Plugin 1 has a
divide-yclass somewhere in a component. We ship that class inside a component (https://github.com/ViewComponent/view_component) so the Main app does not see or scan the plugin structure and thus, it can't see thedivide-yclass and strips it out.Initial solution
We had a Tailwind build process in both the main app and the plugin and when we ran the project, we loaded both output tailwind files (the compiled ones with the final CSS).
That proved to not be ok because we would have clashes and specificity issues between them.
This goes bad really fast when you add more plugins to the mix.
Potential solution
What we could do is to have a Tailwind build system in the library which finds the used classes and outputs them to a
plugin-safelist.txtfile and then the main app would see those classes in the safelist and keep them in the final output.I mean, the tailwind CLI already scans the whole content from plugin 1 and knows which classes it needs to keep. Could we have a flag or command to export them to a file?
The question
How could I build that plugin system and have it be safe and contain all the compiled classes from the main app and all the plugins to play well together?
FAQ
node_modulesfor libraries).Thanks!
Beta Was this translation helpful? Give feedback.
All reactions