laravel-modules icon indicating copy to clipboard operation
laravel-modules copied to clipboard

Hot reload is not working with Vite load from modules

Open bee1194 opened this issue 1 year ago • 3 comments

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]); }

bee1194 avatar Jun 23 '24 04:06 bee1194

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.

vincentcordel avatar Jun 25 '24 21:06 vincentcordel

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]);
    }
}

stevebrainng avatar Jun 29 '24 11:06 stevebrainng

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

satrio1256 avatar Sep 17 '24 04:09 satrio1256

This https://github.com/nWidart/laravel-modules/pull/1965 address this issue, I'll be doing a new release shortly.

dcblogdev avatar Nov 16 '24 13:11 dcblogdev