I have a regular expression to minify the result of the code generated by Laravel's view compiler. The regular expression does nothing more than minify the HTML when compiling a view. I'm having trouble setting the regex to ignore attributes starting with ":" and "@" (eg ... @click="hide(true)" :class="{collapsed: !open}">
), since alpinejs uses them.
In the HTML code:
<select
id="version-switcher"
:class="{test: true}"
aria-label="Localhost version"
class="appearance-none"
@change="window.location = $event.target.value"
>
<option value="https://localhost">Test</option>
<option selected value="https://localhost">Foo</option>
</select>
The result should be:
<select id="version-switcher" :class="{test: true}" aria-label="Localhost version" class="appearance-none" @change="window.location = $event.target.value"><option value="https://localhost">Test</option><option selected value="https://localhost">Foo</option></select>
However, the output is:
<select id="version-switcher":class="{test: true}" aria-label="Localhost version" class="appearance-none"@change="window.location = $event.target.value"><option value="https://localhost">Test</option><option selected value="https://localhost">Foo</option></select>
Note that the attribute starting with : and the one starting with @ are not separate from the previous attribute. The regular expression is: return preg_replace('/<!--(.*?)-->|\s\B/um', '', $html);
Can someone help me with this problem please?