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

SSR example #30

Open
JonathanDavisDev opened this issue Jan 8, 2025 · 1 comment
Open

SSR example #30

JonathanDavisDev opened this issue Jan 8, 2025 · 1 comment

Comments

@JonathanDavisDev
Copy link

Hey there! Great project, been looking into it as Inertia is very interesting. I've seen you've been actively updating this repo so here's a question.

Currently the docs make a reference to enabling SSR but there's no reference to changing the Vite config to generate a SSR bundle or an example of starting the "ssr server" mentioned here in Inertia's docs.

Is there any way you could give a quick example of your vite config necessary to rendering the app with SSR? Is it possible to start the SSR server without using the php command ("php artisan inertia:start-ssr")?

Thanks for any help!

@kapi2289
Copy link
Owner

kapi2289 commented Jan 8, 2025

Hi! To generate an SSR bundle, you can follow the Inertia.js documentation and Laravel documentation (only the Javascript part).

The SSR bundle generates by default in the /bootstrap/ssr/ directory. You can change that in the vite.config.js file:

export default defineConfig({
    plugins: [
        laravel({
            input: ['src/app.js'],
            ssr: 'src/ssr.js',
            publicDirectory: 'wwwroot/',
            ssrOutputDirectory: '[...]',
        }),
    ]
);

The php artisan inertia:start-ssr command is nothing more than just:

> node ./bootstrap/ssr/ssr.mjs

Please verify the generated file name, because you might get a different name or extension.

You can then use for example pm2 for deploying it as a process, which gives you also ability to monitor and auto-restart on fail.

If you have any further questions, don't hesitate to ask.

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

No branches or pull requests

2 participants