SSR using vitejs #1038
Answered
by
ajnsn
ibrunotome
asked this question in
Help (Vue)
SSR using vitejs
#1038
-
I'm using inertia with vitejs instead webpack, everything works well but without any settings related to SSR (see below): const { resolve } = require('path')
import vue from '@vitejs/plugin-vue'
export default ({ command }) => ({
base: command === 'serve' ? '' : '/dist/',
publicDir: 'fake_dir_so_nothing_gets_copied',
build: {
manifest: true,
outDir: resolve(__dirname, 'public/dist'),
rollupOptions: {
input: 'resources/scripts/app.ts',
external: [
resolve(__dirname, 'public/img')
],
},
},
plugins: [vue()],
resolve: {
alias: {
'@': resolve('./resources/scripts'),
},
},
}) Has anyone made it with SSR? |
Beta Was this translation helpful? Give feedback.
Answered by
ajnsn
Jan 10, 2022
Replies: 1 comment 9 replies
-
Hey @ibrunotome I am also still trying out things regarding SSR in combination with Vite, but this seems to work: vite.ssr.config.js import { defineConfig } from 'vite';
import { resolve } from 'path';
import vue from '@vitejs/plugin-vue';
export default defineConfig(() => ({
publicDir: false,
build: {
ssr: true,
target: 'node17',
outDir: 'public/build-ssr',
rollupOptions: {
input: 'resources/js/ssr.js',
},
},
resolve: {
alias: {
'@': resolve(__dirname, 'resources/js'),
},
},
plugins: [vue()],
})); ssr.js import { createSSRApp, h } from 'vue';
import { renderToString } from '@vue/server-renderer';
import { createInertiaApp } from '@inertiajs/inertia-vue3';
import createServer from '@inertiajs/server';
const components = import.meta.globEager('./pages/**/*.vue');
createServer(page =>
createInertiaApp({
page,
render: renderToString,
resolve: name => components[`./pages/${name}.vue`].default,
setup({ app, props, plugin }) {
return createSSRApp({
render: () => h(app, props),
}).use(plugin);
},
}),
);
|
Beta Was this translation helpful? Give feedback.
9 replies
Answer selected by
ibrunotome
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hey @ibrunotome
I am also still trying out things regarding SSR in combination with Vite, but this seems to work:
vite.ssr.config.js
ssr.js