kucrut/vite-for-wp

Fix duplicate stylesheet registration when a CSS is imported by more than one entrypoints

kucrut opened this issue · 3 comments

My solution #86 relied on wordpress wp_enqueue_style removing duplicate registered handles once that is called. Was that not working properly? Or would you rather have it removed from the internal asset array?

From your example manifest file, I registered resources/js/admin.ts and resources/js/admin_menu.ts as two different assets with Vite\enqueue_asset(). Since they have different handles, the assets/Menu-c4e73a0f.css they load have different handles as well, hence the duplication.

I see what you mean now. A possible solution would be to remove the handle option as a prefix.
replace row 347

$style_handle = "{$options['handle']}-{$slug}";

with

$style_handle = $slug;

Vite is making filenames unique, so an extra prefix in the handles are not necessary for any other reason than semantics.