wire-elements / wire-extender

Wire Extender allows you to embed any Livewire component on any website or even within a static HTML file.
https://wire-elements.dev/blog/embed-livewire-components-using-wire-extender
MIT License
246 stars 9 forks source link

Manually bundling Livewire and Alpine with Vite #31

Closed JGlueck-WIKA closed 2 months ago

JGlueck-WIKA commented 2 months ago

I'd like to manually bundle Livewire and Alpine so that I can use a 3rd-party Alpine plugin. This works perfectly well with wire-extender when I set the data-livewire-asset-uri attribute on the <script> tag that references wire-extender.js to the custom JS.

The problem is, that Vite will always append a randomish string to the filename in order to bust the client cache (which is great). However, this makes it impossible to determine the correct file name in a production scenario outside of my app.

Does someone have a tip for me how I can achieve that? My first idea was that it would be great if there was a backend-side configuration possibility to point to the data-livewire-asset-uri, but I'm not sure if this is possible and maybe there's a simpler solution anyhow.

PhiloNL commented 2 months ago

Browsers should follow redirects so you could point data-livewire-asset-uri to a custom route.

Route::get('livewire-asset', function(){ 
   // Get public/build/manifest.json contents
   // Lookup the "resources/js/livewire.js" key
   // Read the "file"
   // return redirect()->to($file);
}); 

This should ensure the correct version is loaded.

JGlueck-WIKA commented 2 months ago

Thanks for the tip Philo, that should certainly work. 🙂