Conversation
| |> List.flatten() | ||
| end | ||
|
|
||
| defp maybe_link_node_modules! do |
There was a problem hiding this comment.
Now one could argue that this is JavaScript specific, but you can also use @import to import from node_modules in CSS if using esbuild, so I guess it's fine?
| # Hardcoded for now | ||
| Phoenix.LiveView.ColocatedJS, | ||
| Phoenix.LiveView.ColocatedCSS |
There was a problem hiding this comment.
I'm not too happy about this, but not sure what a better way would be.
| Path.wildcard(Path.join(path, "*")) |> Enum.filter(&File.dir?(&1)) | ||
| end | ||
|
|
||
| defp warn_for_outdated_config! do |
There was a problem hiding this comment.
I decided to unify the configuration and deprecate the old key.
|
|
||
| Colocated CSS uses the same folder structures as Colocated JS. See `Phoenix.LiveView.ColocatedJS` for more information. | ||
|
|
||
| To bundle and use colocated CSS with esbuild, you can import it like this in your `app.js` file: |
There was a problem hiding this comment.
I created a PR for TailwindCSS to make this work with Tailwind out of the box (at least in newer versions as soon as it is released): tailwindlabs/tailwindcss#19617
@SteffenDE your other PR #4140 and this comment got me thinking... perhaps we could take a similar approach here as you are in #4140, but for ColocatedCSS, by providing a behaviour that people can implement to "transform" the CSS at compile-time and actually perform the scoping? I can see people wanting to scope their CSS via other methodologies than using I think this could also potentially give a way forward for ColocatedCSS that plays nicely with your idea of a separate experimental library for now - we could potentially merge the stripped-down version of ColocatedCSS itself without having to worry about the "gotchas" with the current I am thinking perhaps the callback module could return a set of directives for ColocatedCSS to apply as well as the transformed CSS string, or something along those lines. We may also need to add an additional It might let us also kick the can down the road on your concerns about ColocatedJS and ColocatedCSS being hardcoded in the ColocatedAssets implementation, at least a bit. Let me know what you think 🙂 |
|
@green-david that sounds good to me! I'll adjust this PR (or send another one) some time next week :) |
@SteffenDE If you would like me to make a PR adding the tag_attribute directive, and/or put up a PR off this branch adding the behaviour and ripping out the |
563e917 to
316c77a
Compare
Supersedes #4133.
So the idea here is to have a generic way to colocate "assets" (currently JS + CSS) where template parts are extracted to a
phoenix-colocatedfolder with a specific structure:This fits both colocated JS (hooks) and CSS, which can share the same folder layout using different manifest files. The question is if this is the right level of abstraction. It allows us to extract all of the common code into
ColocatedAssets, but it assumes that all types of colocated assets can work with this layout.I'm also not quite happy that the
configured_callbacksin ColocatedAssets still need to hardcode the list of supported modules. It would be great if dependencies could (theoretically, the API is private for now) also implement colocated assets without us needing to change LiveView code. For example, I could imagine colocated CSS being implemented by annotating all tags with an attribute and then using apostcssplugin that rewrites the CSS rules (similar to https://github.com/SteffenDE/liveview_colocated_demo/blob/main/lib/colocated_demo_web/colocated_css.ex).