nWidart / laravel-modules

Module Management In Laravel
https://docs.laravelmodules.com
MIT License
5.5k stars 954 forks source link

Hot reload is not working with Vite load from modules #1880

Open bee1194 opened 3 months ago

bee1194 commented 3 months ago

I have a module Admin. I want to load its own assets. These steps:

  1. {{ module_vite('build-admin', 'resources/assets/sass/app.scss') }}
  2. Run npm run dev
  3. Reload the page
  4. Get this error Vite manifest not found at: /var/www/html/public/build-admin/manifest.json After debugging, I saw Module_vite is using "storage_path('vite.hot')", but my hot file is not in storage, It is in public. It will work when I replace storage_path('vite.hot') with ViteFacade::hotFile()

function module_vite($module, $asset): Vite { return ViteFacade::useHotFile(ViteFacade::hotFile())->useBuildDirectory($module)->withEntryPoints([$asset]); }

vincentcordel commented 3 months ago

I got the same problem. Your fix works and doesn't :)

It does fix the problem in the module but if you have another npm run dev on the root, you need to refresh it to get the update. I can't get both running at the same time.

... and my vite knowledge is too limited to understand what's going on.

stevebrainng commented 3 months ago

I rather did this instead.

Created a new function.

Then copied the hot file to modules build directory and I don't need to refresh on modules page or non-modules pages.

if (! function_exists('panel_module_vite')) {
    function panel_module_vite($module, $asset): Vite
    {
        //public_path('/build-tenant/hot')
       return ViteFacade::useHotFile(public_path($module.'/hot'))
            ->useBuildDirectory($module)
            ->withEntryPoints([$asset]);
    }
}
satrio1256 commented 2 weeks ago

I see that in my case adding this line under plugins.laravel works:

hotFile: "../../storage/vite.hot",

It'll be somewhat like this for me, maybe this can be adjusted so that each module can have their own hotfile?

export default defineConfig({
  ...
  plugins: [
    laravel({
      ...
      publicDirectory: "../../public",
      hotFile: "../../storage/vite.hot"
      ...
    })
  ]
  ...
})

Edit: Still need to adjust the module_vite helper though if you want to hot-run multiple module simultaneously