Skip to content

Commit

Permalink
fix #11
Browse files Browse the repository at this point in the history
  • Loading branch information
fabio-ivona committed Aug 3, 2022
1 parent 2023843 commit 6a5683c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 9 deletions.
24 changes: 17 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
# Vite Livewire Plugin

> **Warning**
> V3 of Vitejs introduced a forced full reload when a tailwindcss change is triggered by a change in a blade file. This prevents our plugin for applying Livewire Hot Reload. We are actively working with the Vite team to solve this issue (see vitejs/vite#9512 for more info)


<a href="https://www.npmjs.com/package/@defstudio/vite-livewire-plugin"><img src="https://img.shields.io/npm/dt/@defstudio/vite-livewire-plugin" alt="Total Downloads"></a>
<a href="https://www.npmjs.com/package/@defstudio/vite-livewire-plugin"><img src="https://img.shields.io/npm/v/@defstudio/vite-livewire-plugin" alt="Latest Stable Version"></a>
<a href="https://www.npmjs.com/package/@defstudio/vite-livewire-plugin"><img src="https://img.shields.io/npm/l/@defstudio/vite-livewire-plugin" alt="License"></a>
Expand Down Expand Up @@ -73,8 +68,23 @@ From now on, when a `.blade.php` or Livewire `.php` class is updated, the hot re
```

> **Warning**
> This Vite plugin, as Livewire needs to persist in page, is not fully compatible with other plugins that full refresh the page when a `.blade.php` file changes (i.e. laravel/vite-plugin with blade option active)
> in order to make them work together, `blade` files in `**/livewire/**` should be excluded from blade hot reload.
> This Vite plugin, as Livewire needs to persist in page, is not fully compatible with other plugins that full refresh the page when a `.blade.php` file changes (i.e. laravel/vite-plugin with refresh option active)
> in order to make them work together, `blade` files in `**/livewire/**` should be excluded from blade hot reload. For Laravel Vite plugin, this config would solve the issue:
```js
// vite.config.js
export default defineConfig({
//...
plugins: [
//...

laravel({
// ...
refresh: false,
})
],
});
```

### Watching files for hot reload trigger

Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@defstudio/vite-livewire-plugin",
"version": "0.2.1",
"version": "0.2.2",
"author": {
"name": "Fabio Ivona"
},
Expand Down
7 changes: 6 additions & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export default function livewire(config?: PluginConfig | string | string[]): Liv
checkbox.type = 'checkbox';
checkbox.style.cssText = "width: 12px; height: 12px; cursor: pointer";
checkbox.id = "livewire_hot_reload";
checkbox.checked = sessionStorage.getItem("livewire_hot_reload") === "1";
checkbox.checked = (sessionStorage.getItem("livewire_hot_reload") ?? "1") === "1";
sessionStorage.setItem("livewire_hot_reload", checkbox.checked ? "1" : "0");
console.log("[vite] livewire hot reload " + (checkbox.checked ? "enabled." : "disabled."));
Expand Down Expand Up @@ -237,9 +237,14 @@ export default function livewire(config?: PluginConfig | string | string[]): Liv
}
},
handleHotUpdate(ctx) {
if (minimatch(ctx.file, '**/storage/framework/views/**/*.php')) {
return [];
}

for (const pattern of pluginConfig.watch) {
if (minimatch(ctx.file, pattern)) {
refresh(ctx, pluginConfig)
return [];
}
}
}
Expand Down

0 comments on commit 6a5683c

Please sign in to comment.