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
208 stars 6 forks source link

livewire.min.js vs livewire.js #4

Closed RoccoHoward closed 3 months ago

RoccoHoward commented 3 months ago

I've got APP_DEBUG=true but wire-extender looks for livewire.min.js instead of livewire.js.

It appears livewire.min.js is hardcoded and doesn't consider APP_DEBUG on line 22 of js/wire-extender.js.

To get around this at the moment I've added a redirect route that just creates the necessary redirect to get things working.

if (config('app.debug')) {
    Route::redirect('/livewire/livewire.min.js', '/livewire/livewire.js', 302);
}

So far, so good with the rest of setup - I'm building a live stock level embed for Shopify - which source the stock level from the internal inventory management software.

PhiloNL commented 3 months ago

Please be aware that Livewire either uses livewire.js or livewire.min.js depending on your APP_DEBUG setting. Wire extender will always attempt to load livewire/livewire.min.js. If APP_DEBUG is set to true, you will need to use the data-livewire-asset-uri attribute to override the asset url to livewire/livewire.js

This is mentioned in the docs 😄 You have to set the data-livewire-asset manually

RoccoHoward commented 3 months ago

Sorry. I missed the "will always attempt to load livewire/livewire.min.js" part of that, read it that would be based on APP_DEBUG variable too (It was late night coding session)

When sharing the embed code, setting the data-value isn't a good long term solution. Doing the route redirect is a bit more easier long term then putting the data attribute in every externally placed Wire code.

At least if someone has the issue it'll show up in their search for answer and hopefully you won't have to close more related issues!

PhiloNL commented 3 months ago

No problem. You will likely only set the data-livewire-asset-uri when you are embedding a component from a development environment. I might make a Livewire PR to keep both routes active regardless of the app environment.