Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Inertia Helpers #4

Merged
merged 2 commits into from
May 25, 2022
Merged

Add Inertia Helpers #4

merged 2 commits into from
May 25, 2022

Conversation

jessarcher
Copy link
Member

@jessarcher jessarcher commented May 24, 2022

This PR adds a helper for resolving page components from Vite when using Inertia.

Usage:

import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';

createInertiaApp({
    title: (title) => `${title} - ${appName}`,
    resolve: (name) => resolvePageComponent(`./Pages/${name}.jsx`, import.meta.glob('./Pages/**/*.jsx')),
    setup({ el, App, props }) {
        // ...
    },
});

It requires a separate build because it needs to be compiled as an ES module, rather than the CommonJS of the Vite plugin. It can't be exported from a single index without causing all sorts of breakages (this function is essentially front end while the plugin is back end).

It must therefore be imported from a path (laravel-vite-plugin/inertia-helpers) rather than directly from the plugin entry point. TypeScript did recently add support for multiple exports from packages, but it's only in the current RC, and it requires a specific setting in the consuming applications tsconfig.json. Vite will build it fine, but IDEs will about being unable to find the definition.

@jessarcher jessarcher marked this pull request as ready for review May 25, 2022 01:39
@timacdonald
Copy link
Member

What. A. Ride. 🥵

Copy link
Member

@timacdonald timacdonald left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oh hell yea.

@jessarcher jessarcher merged commit 273285f into main May 25, 2022
@jessarcher jessarcher deleted the inertia-helpers branch May 25, 2022 01:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants