Skip to content

Instantly share code, notes, and snippets.

@reinink
Last active November 12, 2022 18:44
Show Gist options
  • Save reinink/8f2556ce9e779838ecc2e878a446d0d6 to your computer and use it in GitHub Desktop.
Save reinink/8f2556ce9e779838ecc2e878a446d0d6 to your computer and use it in GitHub Desktop.
Inertia and Vite SSR setup
import { createSSRApp, h } from 'vue'
import { renderToString } from '@vue/server-renderer'
import { createInertiaApp } from '@inertiajs/inertia-vue3'
import { resolvePageComponent } from 'laravel-vite-plugin/inertia-helpers';
import createServer from '@inertiajs/server'
createServer(page =>
createInertiaApp({
page,
render: renderToString,
resolve: (name) => resolvePageComponent(`./Pages/${name}.vue`, import.meta.glob('./Pages/**/*.vue')),
setup({ app, props, plugin }) {
return createSSRApp({
render: () => h(app, props),
}).use(plugin)
},
}),
)
import { defineConfig } from 'vite'
import laravel from 'laravel-vite-plugin'
import vue from '@vitejs/plugin-vue'
export default defineConfig({
plugins: [
laravel({
input: 'resources/js/app.js',
ssr: 'resources/js/ssr.js',
}),
vue({
template: {
transformAssetUrls: {
base: null,
includeAbsolute: false,
},
},
}),
],
ssr: {
noExternal: ['@inertiajs/server'],
},
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment