mandrasch / ddev-craftcms-vite

Demo repository for CraftCMS + DDEV + vite, including support for GitHub codespaces.
Creative Commons Zero v1.0 Universal
9 stars 0 forks source link

doesn't reload css after .twig refresh.. #11

Closed LorenzoDossi closed 1 day ago

LorenzoDossi commented 2 days ago

when I change+save a .twig file, the css on the website disappear.. is it something that you are experiencing too ? please let me know.. thanks!

LorenzoDossi commented 2 days ago

feel free to book a call if you wanna discuss this problem a bit further https://cal.com/lorenzodossi/30min

mandrasch commented 2 days ago

Hi!

Please provide more context

Do you use my example repository or your own custom implementation?

LorenzoDossi commented 2 days ago

sure!

here is a short video showcasing the problem -> https://streamable.com/6gesiq edit html -> all good edit scss -> all good edit html again -> doesn't work -> need to reload manually the page

mandrasch commented 1 day ago

Hey,

thanks for detailed description + video! 👍

First of all: Twig reloading is not really "Hot Module Replacement" (hmr) in craftcms vite plugin, the whole page needs a reload after twig changes (because twig is not tighly integrated like css changes in Vite). But this is done automatically - if ...

Second: After you run ddev npm run dev, you need to reload your browser manually once to get the Vite dev server active. Otherwise manifest.json from previous builds will be used. See config/vite.php:

// this will ping $devServerInternal to make sure it's running, 
// otherwise it falls back to web/dist/manifest.json
'checkDevServer' => true,

You can check in devtools if Vite connected - or not:

image

When you use browser reload once after ddev npm run dev - and Vite devserver is connected, each twig change should cause a browser refresh automatically:

https://github.com/mandrasch/ddev-craftcms-vite/assets/777278/a8a4b914-077f-48c1-849f-4bd8d687d1fc

This is handled by https://www.npmjs.com/package/vite-plugin-restart, see vite.config.js

plugins: [
        ViteRestart({
        restart: [
            './templates/**/*',
        ],
    })]

Hope that helps?

LorenzoDossi commented 1 day ago

"Second: After you run ddev npm run dev, you need to reload your browser manually once to get the Vite dev server active." that was the problem! Thanks immensely

btw if you need some help related to css/motion stuff, don't hesitate to hit me up, I owe you a favor! https://www.lorenzodossi.com/

mandrasch commented 1 day ago

Happy to help! 👍