laravel / vite-plugin

Laravel plugin for Vite.
MIT License
790 stars 148 forks source link

[0.8.x] Fallback pages #271

Closed timacdonald closed 9 months ago

timacdonald commented 9 months ago

This PR is an alternative to https://github.com/laravel/vite-plugin/pull/252 and https://github.com/laravel/vite-plugin/pull/259.

It allows the path to be a string (current behaviour) or an array (new behaviour).

This enables two features:

  1. A "fallback" so that users do not see a "whitescreen of death", where ./Pages/Whoops.vue is the fallback:
createInertiaApp({
    // ...
    resolve: (name) => resolvePageComponent([`./Pages/${name}.vue`, './Pages/Whoops.vue'], import.meta.glob('./Pages/**/*.vue')),
});

Of course, if the fallback isn't present things can still go wrong.

  1. Easier migration from one file type to another without having to deal with error control, e.g., when migrating from .jsx to .tsx
createInertiaApp({
    // ...
    resolve: (name) => resolvePageComponent([`./Pages/${name}.tsx`, `./Pages/${name}.jsx`], import.meta.glob('./Pages/**/*.[tj]sx')),
});
sh-sabbir commented 9 months ago

@timacdonald Now that I see yours, it's indeed a better solution than mine