I have setup new Laravel project with Breeze package + Inertia SSR support
php artisan breeze:install vue --ssr
I do everything according Inertia SSR guide. At the end I run commands:
npx mix
npx mix --mix-config=webpack.ssr.mix.js
node public/js/ssr.js
I open localhost and I see this error
Unable to locate Mix file: /css/app.css.
I open app.blade.php and remove mix function from assets. Now page is working.
I navigate to localhost/login and press CTRL+U (to view page source). And there is no prerendered html, just usual SPA code. SSR app logs no activity except when starting
Starting SSR server on port 13714...
Inertia SSR server started.
How do I fix it?
P.S. My project is running on WSL virtual machine. Could it be the problem?
app.blade.php
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title inertia>{{ config('app.name', 'Laravel') }}</title>
<!-- Styles -->
<link rel="stylesheet" href="/css/app.css">
<!-- Scripts -->
@routes
<script src="/js/app.js" defer></script>
@inertiaHead
</head>
<body class="font-sans antialiased">
@inertia
@env ('local')
<script src="/js/bundle.js"></script>
@endenv
</body>
</html>
ssr.js
import { createSSRApp, h } from 'vue';
import { renderToString } from '@vue/server-renderer';
import { createInertiaApp } from '@inertiajs/inertia-vue3';
import createServer from '@inertiajs/server';
import route from 'ziggy';
const appName = 'Laravel';
createServer((page) =>
createInertiaApp({
page,
render: renderToString,
title: (title) => `${title} - ${appName}`,
resolve: (name) => require(`./Pages/${name}.vue`),
setup({ app, props, plugin }) {
return createSSRApp({ render: () => h(app, props) })
.use(plugin)
.mixin({
methods: {
route: (name, params, absolute) => {
return route(name, params, absolute, {
...page.props.ziggy,
location: new URL(page.props.ziggy.url),
});
},
},
});
},
})
);
webpack.ssr.mix.js
const mix = require('laravel-mix');
const webpackNodeExternals = require('webpack-node-externals');
mix.js('resources/js/ssr.js', 'public/js')
.vue({
version: 3,
useVueStyleLoader: true,
options: { optimizeSSR: true },
})
.alias({
'@': 'resources/js',
ziggy: 'vendor/tightenco/ziggy/dist/index',
})
.webpackConfig({
target: 'node',
externals: [webpackNodeExternals()],
});