Skip to content

Commit

Permalink
Set-up SSR
Browse files Browse the repository at this point in the history
  • Loading branch information
claudiodekker committed Jan 18, 2022
1 parent 47d3cae commit b1eb5b0
Show file tree
Hide file tree
Showing 10 changed files with 2,323 additions and 2,199 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"ext-gd": "*",
"fruitcake/laravel-cors": "^2.0",
"guzzlehttp/guzzle": "^7.0.1",
"inertiajs/inertia-laravel": "^0.4.5",
"inertiajs/inertia-laravel": "^0.5.3",
"laravel/framework": "^8.65",
"laravel/sanctum": "^2.11",
"laravel/tinker": "^2.5",
Expand Down
791 changes: 404 additions & 387 deletions composer.lock

Large diffs are not rendered by default.

62 changes: 62 additions & 0 deletions config/inertia.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
<?php

return [

/*
|--------------------------------------------------------------------------
| Server Side Rendering
|--------------------------------------------------------------------------
|
| These options configures if and how Inertia uses Server Side Rendering
| to pre-render the initial visits made to your application's pages.
|
| Do note that enabling these options will NOT automatically make SSR work,
| as a separate rendering service needs to be available. To learn more,
| please visit https://inertiajs.com/server-side-rendering
|
*/

'ssr' => [

'enabled' => true,

'url' => 'http://127.0.0.1:13714/render',

],

/*
|--------------------------------------------------------------------------
| Testing
|--------------------------------------------------------------------------
|
| The values described here are used to locate Inertia components on the
| filesystem. For instance, when using `assertInertia`, the assertion
| attempts to locate the component as a file relative to any of the
| paths AND with any of the extensions specified here.
|
*/

'testing' => [

'ensure_pages_exist' => true,

'page_paths' => [

resource_path('js/Pages'),

],

'page_extensions' => [

'js',
'jsx',
'svelte',
'ts',
'tsx',
'vue',

],

],

];
23 changes: 14 additions & 9 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,26 +2,30 @@
"private": true,
"scripts": {
"dev": "npm run development",
"development": "mix",
"development": "mix && npm run ssr:build",
"fix:eslint": "eslint --ext .js,.vue resources/js/ --fix",
"fix:prettier": "prettier --write --loglevel warn 'resources/js/**/*.vue'",
"fix-code-style": "npm run fix:prettier && npm run fix:eslint",
"watch": "mix watch",
"watch-poll": "mix watch -- --watch-options-poll=1000",
"hot": "mix watch --hot",
"prod": "npm run production",
"production": "mix --production",
"heroku-postbuild": "npm run prod"
"production": "mix --production && npm run ssr:build",
"heroku-postbuild": "npm run prod",
"ssr:build": "mix --production --mix-config=webpack.ssr.mix.js",
"ssr:serve": "node public/js/ssr.js"
},
"dependencies": {
"@inertiajs/inertia": "^0.10.1",
"@inertiajs/inertia-vue3": "^0.5.2",
"@inertiajs/progress": "^0.2.6",
"@inertiajs/inertia": "^0.11.0",
"@inertiajs/inertia-vue3": "^0.6.0",
"@inertiajs/progress": "^0.2.7",
"@inertiajs/server": "^0.1.0",
"@popperjs/core": "^2.11.0",
"@vue/server-renderer": "^3.2.27",
"autoprefixer": "^10.4.0",
"eslint": "^8.4.1",
"eslint-plugin-vue": "^8.2.0",
"laravel-mix": "^6.0.39",
"laravel-mix": "^6.0.41",
"lodash": "^4.17.21",
"postcss": "^8.4.4",
"postcss-import": "^12.0.1",
Expand All @@ -30,7 +34,8 @@
"prettier-plugin-tailwind": "^2.2.12",
"tailwindcss": "^2.0.3",
"uuid": "^8.3.2",
"vue": "^3.2.24",
"vue-loader": "^16.2.0"
"vue": "^3.2.27",
"vue-loader": "^16.2.0",
"webpack-node-externals": "^3.0.0"
}
}
2 changes: 1 addition & 1 deletion resources/js/app.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ InertiaProgress.init()

createInertiaApp({
resolve: name => require(`./Pages/${name}`),
title: title => `${title} - Ping CRM`,
title: title => title ? `${title} - Ping CRM` : 'Ping CRM',
setup({ el, App, props, plugin }) {
createApp({ render: () => h(App, props) })
.use(plugin)
Expand Down
16 changes: 16 additions & 0 deletions resources/js/ssr.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { createSSRApp, h } from 'vue'
import { renderToString } from '@vue/server-renderer'
import { createInertiaApp } from '@inertiajs/inertia-vue3'
import createServer from '@inertiajs/server'

createServer((page) => createInertiaApp({
page,
render: renderToString,
resolve: name => require(`./Pages/${name}`),
title: title => title ? `${title} - Ping CRM` : 'Ping CRM',
setup({ app, props, plugin }) {
return createSSRApp({
render: () => h(app, props),
}).use(plugin)
},
}))
1 change: 1 addition & 0 deletions resources/views/app.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
<script src="https://polyfill.io/v3/polyfill.min.js?features=String.prototype.startsWith" defer></script>

<script src="{{ mix('/js/app.js') }}" defer></script>
@inertiaHead
</head>
<body class="font-sans leading-none text-gray-700 antialiased">
@inertia
Expand Down
1 change: 0 additions & 1 deletion webpack.mix.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
const path = require('path')
const process = require('process')
const mix = require('laravel-mix')
const cssImport = require('postcss-import')
Expand Down
13 changes: 13 additions & 0 deletions webpack.ssr.mix.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
const mix = require('laravel-mix')
const webpackNodeExternals = require('webpack-node-externals')
const webpackConfig = require('./webpack.config')

mix
.options({ manifest: false })
.js('resources/js/ssr.js', 'public/js')
.vue({ version: 3, options: { optimizeSSR: true } })
.webpackConfig({
...webpackConfig,
target: 'node',
externals: [webpackNodeExternals()],
})
Loading

0 comments on commit b1eb5b0

Please sign in to comment.