Rails engine support #355
Replies: 10 comments 24 replies
-
I only want to chime in that in #108 I am not necessarily talking about building multiple CSS files per se, but rather allowing a single Tailwind generator to see all of an engine's views, partials, view components, and other files that contain Tailwind classes. When Tailwind generates its CSS file it scans all the files in the content configuration to know which utility classes it needs to include. I know everyone working on this knows the above — I'm just including it for thoroughness since I didn't read this issue as exactly speaking to that.
I may be misinterpreting this, but — I think what you're saying is that each engine would know about its own files with its own config file, and Tailwind would build a CSS file per engine which would be accessible. I don't know that it would necessarily matter, but I find it preferable to have a single Tailwind-generated CSS file. I think we're the odd ducks, but my work's main app is built with something like a Component-Based Rails Application approach, and we have ~30 engines. There would end up being a lot of duplication in each Tailwind file for our use case, and it would be cumbersome in the layouts to figure out which Tailwind CSS files to include in the header when we render view components from other components (via dependency injection). Hopefully I haven't misinterpreted anything too much — thank you & all for the work on this gem & topic! |
Beta Was this translation helpful? Give feedback.
-
Would be happy to see engines supported, but imo the focus should be on expanding the files TW uses to look for classes in. Rather than trying to have multi outputs. I think in almost all cases, we're better off just producing one output for all classes found. And it'll be much easier, and we should be able to do so virtually without specific configuration. |
Beta Was this translation helpful? Give feedback.
-
We have a case where we manage the general front-end (basic assets, configuration, layout partials, some components) in a gem containing a Rails engine. Our teams are small and make many small, separate applications, so extracting most of the front-end matter lets us develop quickly and keeps updates centralized and more manageable. It would be nice for us to have a way to set up and import a standard tailwind config from the gem and merge it with customizations for each app. There is almost certainly a way to do this without building it into this gem, but I thought I'd mention it anyway. The more desired feature would be to add our gem's views and components to the paths monitored by this gem. |
Beta Was this translation helpful? Give feedback.
-
Adding my $0.02 worth - I found this thread trying to enable precisely this use case for my platform. Use case: We have one platform, which runs 3 flavors of front end (internal, client, and customer checkout), and on top of that, there's additional white labeling for each customer checkout that we need to support. Our application.tailwind.css is becoming a bit of a mess of classes, namespaces, etc, and I would really like to split these out. I am not in a position to directly contribute code, but please count me as a +1 for needing this functionality! Thanks, all! |
Beta Was this translation helpful? Give feedback.
-
I have another use case, similar to some that have already been mentioned. I have multiple websites hosted inside the same rails server process where each website is an engine mounted in the top level In fact, I don't have a top level Ideally, I would have an isolated outputted css built for each individual engine as I don't want to load styles that belong to other websites (engines). It would also be nice to be able to reference other engine's, but that's less important to me. I should also note that I'm using propshaft and not sprockets. |
Beta Was this translation helpful? Give feedback.
-
Hey 👋 I have read all posts to know how I can have two tailwind configurations and I have finish here 😁 I want to contribute with the description of my use case. I have two applications :
I need to dissociate both configurations because the design system is completely different. For the moment I choose to use tailwind without the gem and use https://tailwindcss.com/blog/tailwindcss-v3-2#multiple-config-files-in-one-project-using-config I can't contribute of the feature development because I'm a noobie in Rails yet but I will very happy if we can use many configurations of Tailwind 🫶 Thanks of lot ! |
Beta Was this translation helpful? Give feedback.
-
My two cents here. In our case we have the main application with its public and private part (it is not relevant here to optimize the styles by separating them into two different files) and then we generate PDFs using HTML and this is where it may be interesting to be able to separate the styles to avoid sending the converter the styles that are not necessary, but I think a bit like dhh, it is more for optimization than a technical necessity. Thanks for the effort! |
Beta Was this translation helpful? Give feedback.
-
While waiting for a response to the thread here, I decided to explore different approaches and implement an installation script that collects tailwind classes from |
Beta Was this translation helpful? Give feedback.
-
Hey there ! Same need here : |
Beta Was this translation helpful? Give feedback.
-
Did we get any traction on engine support. I am off trying it today and expected it to just work out the box until it didn't. What the current best way to work with engines? |
Beta Was this translation helpful? Give feedback.
-
I wanted to start a discussion thread about support for Rails Engines and multiple Tailwind CSS files. This is an attempt to bring a few related conversations together and start to drive towards a clear understanding of the problem(s) people need solved and talk about potential solutions.
Context
There have been a few issues and pull requests around a similar set of problems. In chronological order:
The topics from #108, #151, and #242 are related: how to support multiple CSS files, whether those are in engines/gems or elsewhere in the Rails application.
Issue #150 is slightly different and relates to full support for Rails engine generators. If we want to implement build-time support for Engines using tailwindcss, then we logically should implement generator support for Engines, too.
(The Stack Overflow thread touches on both topics.)
The problem space
Here's my first draft of articulating a problem statement (feedback welcome):
The current tailwindcss-rails generator and its configuration both assume it's running in a top-level Rails application, and hardcodes some of those assumptions into, e.g.,
config/tailwind.config.js
. The gem doesn't provide any ways to dynamically configure or extend this behavior.As a result, people have fallen back on hacks like generating
tailwind.config.js
dynamically or forking out to bundler withintailwind.config.js
to inject additional paths.This problem statement doesn't explicitly include the "multiple Tailwind CSS files in an app" scenario from #242. In that discussion, @dhh gently pushed back on having multiple files in an app, which I think is healthy. But I suspect, if tailwindcss-rails provides a mechanism for building against assets in engines or gems, whatever mechanism we implement can be used by people to declare their separate Tailwind CSS files if they really want to do it.
The solution space
I think the broad strokes of how an engine integrates into railties are pretty well-known at this point, but broadly:
tailwindcss-rails
gemconfig.tailwindcss_rails.config_files
Then, the gem's rake tasks
tailwindcss:build
andtailwindcss:watch
, as well as the Puma plugin and/or the engine server hook from #347, would be extended to build multiple Tailwind CSS files.We would also implement support for the plugin generator so that if an engine is created via
rails plugin new --css tailwind
then the above configuration is already in place.Next steps
Heading into Rails Conf in about 10 days, I'm going to be at the Hack Day and would like to work on this there.
I'd love feedback from y'all on either the problem statement (did I miss a use case? does the problem statement presume too much about the shape of the solution? are there alternatives you'd like to offer) or the solution space. Thank you!
Beta Was this translation helpful? Give feedback.
All reactions