CokraMehinka's avatar

Laravel Blade Hot Refresh With Vite not working

I have a fresh Laravel 9 installed. I have run npm install, included @vite(['resources/css/app.css', 'resources/js/app.js']) in the head tag, and started the vite server but when I change something in the welcome.blade.php the page doesn't refresh and I'm not getting any errors. I've checked out the documentation but I haven't noticed missing anything.

Vite config file

import { defineConfig } from 'vite'; import laravel from 'laravel-vite-plugin';

export default defineConfig({ plugins: [ laravel({ input: ['resources/css/app.css', 'resources/js/app.js'], refresh: true, }), ], });

0 likes
12 replies
Sinnbeck's avatar

When you change things, do you see the vite server do anything. Check the terminal while changing the file

newbie360's avatar

when you run npm run dev , you need in browser refresh the page (once only), then in the browser dev tools, you should see something like this

[vite] connecting...
[vite] connected.

in local dev, i also temp add this to my main layout , after the project finished, just delete this line

<head>
    <script src="https://cdn.tailwindcss.com"></script>
</head>
Sinnbeck's avatar

@newbie360 Does use the tailwind cdn. Use vite instead to build it. The cdn is for testing stuff, not production :)

newbie360's avatar

@Sinnbeck no , the cdn is used for local dev only, because i don't know have you got the same problem

after npm run dev, all the new Tailwind css make up is no effect, until npm run build

so i don't want to keep repeat to npm run build, just added the CDN, when the probject almost finished, then remove the CDN

Sinnbeck's avatar

@newbie360 Using tailwindcss with vite and and dev, shouldnt be that hard :) No need for the cdn.

Just run npm run dev while developing the site

newbie360's avatar

@Sinnbeck without the CDN, you can try npm run dev, and add this for example,

add some css is never used before, because bg-zinc-400 isn't in the builded asset

<div class="mt-96 bg-zinc-400">
    test
</div>

this is no effect on the browser

newbie360's avatar

@Sinnbeck this weird, may be the problem is i'm using Homestead, i go to solve it later, thankyou for your time

jtphelan's avatar

@newbie360 I have the exact same issue with tailwind in both Herd or ddev. Did you ever figure out the issue?

Please or to participate in this conversation.