javascriptphplaravelnpmvite

Laravel front-end changes not persisting after stopping composer run dev


I'm trying to set up a Laravel project to help myself relearn the basics after 2 years of unemployment due to health issues.

I've just installed a fresh project using the Inertia-Vue starter pack and am serving/developing it using Sail on MacOS.

I'm not familiar with the sail composer run dev command, but I noticed that while running it my changes to the front end are instantly reflected in my browser (I understand this is called 'hot module reloading'). However, after terminating the command my changes disappear, and will only return and persist if I execute sail npm run build.

Is this intended behaviour? It feels strange to have my changes disappear after they've been built already, albeit in a 'dev' script.


Solution

  • This is intended behaviour. The command sail composer run dev runs Vite in development mode, which means that assets are served from memory instead of being written to disk. Your assets exist in the system's memory temporarily, as long as the Vite development server is active.

    When you stop the development server, the in-memory asset bundle is lost, which is why your changes do not persist. The command sail npm run build creates the actual asset files and writes them to disk.