RodrigoTomeES / astro-rename

Astro-Rename is an Astro integration that brings postcss-rename functionality to your Astro project without the need for configuration.
https://www.npmjs.com/package/astro-rename
GNU General Public License v3.0
15 stars 4 forks source link

Implementing SSR support for astro-rename #4

Open jkhaui opened 9 months ago

jkhaui commented 9 months ago

Hey,

I came across this plugin from https://github.com/google/postcss-rename/issues/43, funnily enough I had the exact same idea so it was nice seeing the great work you've already done to build this integration.

I'm just wondering if you can provide a high-level description of what the main blocker is atm for supporting SSR? That way, I can hopefully contribute to its implementation if I have time and it's not too complex. From a brief glance at the source maybe we'd need to hook into Astro's build:ssr step. Thanks!

RodrigoTomeES commented 8 months ago

Hi,

Sorry, I missed this issue. The main issue in SSR is process the file on the fly to transform his classes and keep the state of the transformed classes map.

I think that Astro should be have a hook to implement this but I didn't have time to explore it. Any help would be welcome.

In addition, I found this utiltiy that implement SSR transform for Next.JS but only for Tailwind CSS https://github.com/sonofmagic/tailwindcss-mangle. But maybe it would be interested to take a look of how Sonofmagic implemented it.

Tanguy-Magnaudet commented 7 months ago

Hey there,

Astro released in 3.5.0 the ability to use Middlewares in an integration : https://github.com/withastro/astro/releases/tag/astro%403.5.0

It should now be possible to replace classes names using a middleware like it is shown in the doc here : https://docs.astro.build/en/guides/middleware/#example-redacting-sensitive-information

It will probably be slow but as most of content website have cache, I guess it's ok for now ?

RodrigoTomeES commented 7 months ago

@Tanguy-Magnaudet hi!

Maybe can be implemented with a middlewares but I think it more interesting investigate the use the hook "astro:build:ssr". With it you can perform the replacement directly after the generation.

Right now I am working on the v2 of this plugin that will be bring more stability and a safety replacements of the classes. After that I will take this issue, I will investigate also your suggestion.

Thanks!

RodrigoTomeES commented 1 week ago

hi, @jkhaui @Tanguy-Magnaudet you can test the early support to SSR in v2 alpha-6 version of the package => https://www.npmjs.com/package/astro-rename/v/2.0.0-alpha6

jkhaui commented 1 week ago

hi, @jkhaui @Tanguy-Magnaudet you can test the early support to SSR in v2 alpha-6 version of the package => https://www.npmjs.com/package/astro-rename/v/2.0.0-alpha6

Very nice, great work! 👏 I'll try it and let you know my thoughts

Sorry I never got a chance to try implement it myself