vitrify 0.21.0 → 0.23.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bin/cli.js +3 -3
- package/dist/bin/dev.js +26 -39
- package/dist/frameworks/vue/fastify-ssr-plugin.js +58 -19
- package/dist/frameworks/vue/prerender.js +4 -4
- package/dist/frameworks/vue/server.js +5 -1
- package/dist/hooks/index.js +1 -0
- package/dist/index.js +80 -94
- package/dist/plugins/index.js +2 -1
- package/dist/plugins/pinia/index.js +61 -0
- package/dist/plugins/quasar/index.js +226 -0
- package/dist/types/frameworks/vue/fastify-ssr-plugin.d.ts +6 -3
- package/dist/types/frameworks/vue/prerender.d.ts +3 -3
- package/dist/types/frameworks/vue/server.d.ts +4 -4
- package/dist/types/hooks/index.d.ts +2 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/plugins/index.d.ts +13 -2
- package/dist/types/plugins/pinia/index.d.ts +5 -0
- package/dist/types/plugins/{quasar.d.ts → quasar/index.d.ts} +5 -5
- package/dist/types/vitrify-config.d.ts +87 -12
- package/package.json +37 -25
- package/src/node/bin/cli.ts +13 -7
- package/src/node/bin/dev.ts +30 -41
- package/src/node/frameworks/vue/fastify-ssr-plugin.ts +85 -28
- package/src/node/frameworks/vue/prerender.ts +6 -6
- package/src/node/frameworks/vue/server.ts +11 -2
- package/src/node/hooks/index.ts +19 -0
- package/src/node/index.ts +114 -130
- package/src/node/plugins/index.ts +20 -3
- package/src/node/plugins/pinia/index.ts +96 -0
- package/src/node/plugins/quasar/index.ts +318 -0
- package/src/node/vitrify-config.ts +120 -21
- package/src/vite/fastify/server.ts +3 -0
- package/src/vite/vue/RootComponent.vue +1 -1
- package/src/vite/vue/main.ts +52 -22
- package/src/vite/vue/ssr/app.ts +3 -2
- package/src/vite/vue/ssr/entry-server.ts +22 -41
- package/src/vite/vue/ssr/prerender.ts +2 -2
- package/dist/plugins/quasar.js +0 -217
- package/src/node/plugins/quasar.ts +0 -307
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitrify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.23.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Stefan van Herwijnen",
|
|
6
6
|
"description": "Vite as your Full Stack development tool",
|
|
@@ -30,9 +30,13 @@
|
|
|
30
30
|
"./client": {
|
|
31
31
|
"types": "./client.d.ts"
|
|
32
32
|
},
|
|
33
|
-
"./
|
|
34
|
-
"types": "./dist/types/plugins/
|
|
35
|
-
"import": "./dist/plugins/
|
|
33
|
+
"./plugins": {
|
|
34
|
+
"types": "./dist/types/plugins/index.d.ts",
|
|
35
|
+
"import": "./dist/plugins/index.js"
|
|
36
|
+
},
|
|
37
|
+
"./hooks": {
|
|
38
|
+
"types": "./dist/types/hooks/index.d.ts",
|
|
39
|
+
"import": "./dist/hooks/index.d.ts"
|
|
36
40
|
}
|
|
37
41
|
},
|
|
38
42
|
"engines": {
|
|
@@ -49,60 +53,68 @@
|
|
|
49
53
|
"homepage": "https://github.com/simsustech/vitrify/tree/main/#readme",
|
|
50
54
|
"dependencies": {
|
|
51
55
|
"@fastify/middie": "^9.0.3",
|
|
52
|
-
"@fastify/
|
|
53
|
-
"@
|
|
54
|
-
"@unocss/
|
|
55
|
-
"@unocss/preset-
|
|
56
|
-
"@unocss/preset-
|
|
57
|
-
"@
|
|
56
|
+
"@fastify/one-line-logger": "^2.0.2",
|
|
57
|
+
"@fastify/static": "^8.2.0",
|
|
58
|
+
"@unocss/core": "^66.1.2",
|
|
59
|
+
"@unocss/preset-uno": "^66.1.2",
|
|
60
|
+
"@unocss/preset-web-fonts": "66.1.2",
|
|
61
|
+
"@unocss/preset-wind": "^66.1.2",
|
|
62
|
+
"@vitejs/plugin-vue": "^5.2.4",
|
|
58
63
|
"ajv": "^8.17.1",
|
|
59
64
|
"animated-unocss": "^0.0.6",
|
|
60
65
|
"cac": "^6.7.14",
|
|
61
66
|
"chalk": "^5.4.1",
|
|
62
67
|
"cross-env": "^7.0.3",
|
|
63
|
-
"
|
|
64
|
-
"
|
|
68
|
+
"devalue": "^5.1.1",
|
|
69
|
+
"esbuild": "^0.25.4",
|
|
70
|
+
"fastify": "^5.3.3",
|
|
65
71
|
"glob": "^11.0.2",
|
|
66
|
-
"happy-dom": "^17.4.
|
|
72
|
+
"happy-dom": "^17.4.7",
|
|
67
73
|
"is-port-reachable": "^4.0.0",
|
|
68
74
|
"magic-string": "^0.30.17",
|
|
69
75
|
"merge-deep": "^3.0.3",
|
|
70
76
|
"readline": "^1.3.0",
|
|
71
77
|
"rollup-plugin-visualizer": "^5.14.0",
|
|
72
|
-
"sass": "1.
|
|
78
|
+
"sass": "1.89.0",
|
|
79
|
+
"stringify-object": "^5.0.0",
|
|
73
80
|
"ts-node": "^10.9.2",
|
|
74
|
-
"unocss": "^66.
|
|
81
|
+
"unocss": "^66.1.2",
|
|
75
82
|
"unplugin-vue-components": "^28.5.0",
|
|
76
|
-
"vite": "^6.3.
|
|
83
|
+
"vite": "^6.3.5",
|
|
77
84
|
"vite-plugin-pwa": "^1.0.0",
|
|
78
85
|
"vitefu": "^1.0.6",
|
|
79
|
-
"vitest": "^3.1.
|
|
86
|
+
"vitest": "^3.1.4",
|
|
80
87
|
"workbox-window": "^7.3.0"
|
|
81
88
|
},
|
|
82
89
|
"devDependencies": {
|
|
83
90
|
"@iconify-json/mdi": "^1.2.3",
|
|
84
|
-
"@
|
|
91
|
+
"@pinia/colada": "^0.16.1",
|
|
92
|
+
"@quasar/extras": "^1.17.0",
|
|
85
93
|
"@quasar/quasar-ui-qmarkdown": "^2.0.5",
|
|
86
94
|
"@quasar/quasar-ui-qmediaplayer": "^2.0.0-beta.0",
|
|
87
95
|
"@types/connect": "^3.4.38",
|
|
88
96
|
"@types/glob": "^8.1.0",
|
|
89
97
|
"@types/merge-deep": "^3.0.3",
|
|
90
|
-
"@types/node": "^22.15.
|
|
98
|
+
"@types/node": "^22.15.21",
|
|
99
|
+
"@types/stringify-object": "^4.0.5",
|
|
91
100
|
"@types/ws": "^8.18.1",
|
|
92
|
-
"@unocss/preset-icons": "^66.
|
|
93
|
-
"@vue/runtime-core": "^3.5.
|
|
94
|
-
"beasties": "^0.3.
|
|
101
|
+
"@unocss/preset-icons": "^66.1.2",
|
|
102
|
+
"@vue/runtime-core": "^3.5.14",
|
|
103
|
+
"beasties": "^0.3.4",
|
|
95
104
|
"css": "^3.0.0",
|
|
96
105
|
"css-to-tailwind-translator": "^1.2.8",
|
|
106
|
+
"pinia": "^3.0.2",
|
|
97
107
|
"quasar": "^2.18.1",
|
|
98
|
-
"rollup": "^4.
|
|
108
|
+
"rollup": "^4.41.0",
|
|
99
109
|
"typescript": "^5.8.3",
|
|
100
110
|
"vue": "^3.5.13",
|
|
101
111
|
"vue-router": "^4.5.1"
|
|
102
112
|
},
|
|
103
113
|
"peerDependencies": {
|
|
104
|
-
"@fastify/static": "^8.
|
|
105
|
-
"
|
|
114
|
+
"@fastify/static": "^8.2.0",
|
|
115
|
+
"@pinia/colada": "^0.16.1",
|
|
116
|
+
"fastify": "^5.3.3",
|
|
117
|
+
"pinia": "^3.0.2",
|
|
106
118
|
"quasar": "^2.18.1",
|
|
107
119
|
"vue": "^3.5.13",
|
|
108
120
|
"vue-router": "^4.5.1"
|
package/src/node/bin/cli.ts
CHANGED
|
@@ -24,7 +24,6 @@ cli
|
|
|
24
24
|
const { build } = await import('./build.js')
|
|
25
25
|
let appDir: URL
|
|
26
26
|
let prerender
|
|
27
|
-
let onRendered
|
|
28
27
|
if (options.appDir) {
|
|
29
28
|
if (options.appDir.slice(-1) !== '/') options.appDir += '/'
|
|
30
29
|
appDir = new URL(`file://${options.appDir}`)
|
|
@@ -90,11 +89,17 @@ cli
|
|
|
90
89
|
new URL('ssr/server/prerender.mjs', baseOutDir).pathname
|
|
91
90
|
))
|
|
92
91
|
|
|
93
|
-
const {
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
92
|
+
const {
|
|
93
|
+
template,
|
|
94
|
+
manifest,
|
|
95
|
+
render,
|
|
96
|
+
getRoutes,
|
|
97
|
+
onRendered,
|
|
98
|
+
onTemplateRendered
|
|
99
|
+
} = await loadSSRAssets({
|
|
100
|
+
mode: 'ssg',
|
|
101
|
+
distDir: baseOutDir
|
|
102
|
+
})
|
|
98
103
|
const routes = await getRoutes()
|
|
99
104
|
|
|
100
105
|
prerender({
|
|
@@ -103,7 +108,8 @@ cli
|
|
|
103
108
|
manifest,
|
|
104
109
|
render,
|
|
105
110
|
routes,
|
|
106
|
-
onRendered
|
|
111
|
+
onRendered,
|
|
112
|
+
onTemplateRendered
|
|
107
113
|
})
|
|
108
114
|
break
|
|
109
115
|
default:
|
package/src/node/bin/dev.ts
CHANGED
|
@@ -5,7 +5,10 @@ import type { Server } from 'net'
|
|
|
5
5
|
import fastify from 'fastify'
|
|
6
6
|
import type { FastifyServerOptions } from 'fastify'
|
|
7
7
|
import { fastifySsrPlugin } from '../frameworks/vue/fastify-ssr-plugin.js'
|
|
8
|
-
import type {
|
|
8
|
+
import type {
|
|
9
|
+
OnTemplateRenderedHook,
|
|
10
|
+
VitrifyConfig
|
|
11
|
+
} from '../vitrify-config.js'
|
|
9
12
|
import isPortReachable from 'is-port-reachable'
|
|
10
13
|
import { exitLogs } from '../helpers/logger.js'
|
|
11
14
|
import { fileURLToPath } from 'url'
|
|
@@ -49,8 +52,6 @@ export async function createVitrifyDevServer({
|
|
|
49
52
|
'../app-urls.js'
|
|
50
53
|
)
|
|
51
54
|
|
|
52
|
-
const cliDir = getCliDir()
|
|
53
|
-
|
|
54
55
|
if (!appDir) appDir = getAppDir()
|
|
55
56
|
let config: InlineConfig = {}
|
|
56
57
|
let ssrMode: 'server' | 'fastify' | undefined
|
|
@@ -66,52 +67,32 @@ export async function createVitrifyDevServer({
|
|
|
66
67
|
base
|
|
67
68
|
})
|
|
68
69
|
|
|
69
|
-
config.logLevel = logLevel
|
|
70
|
-
|
|
71
|
-
config.define = {
|
|
72
|
-
...config.define,
|
|
73
|
-
__HOST__: `'${host}'`
|
|
74
|
-
}
|
|
75
|
-
|
|
76
70
|
const wsPort = await getFirstOpenPort(24678)
|
|
77
71
|
if (config.server?.https) {
|
|
78
72
|
exitLogs.push(
|
|
79
73
|
`[warning] HTTPS mode enabled. Visit https://{hostname}:${wsPort} to enable a security exception for HMR.`
|
|
80
74
|
)
|
|
81
75
|
}
|
|
82
|
-
config.server = {
|
|
83
|
-
https: config.server?.https,
|
|
84
|
-
hmr: {
|
|
85
|
-
protocol: config.server?.https ? 'wss' : 'ws',
|
|
86
|
-
port: wsPort
|
|
87
|
-
},
|
|
88
|
-
port,
|
|
89
|
-
// middlewareMode: mode === 'ssr' ? 'ssr' : undefined,
|
|
90
|
-
middlewareMode: ssr ? true : false,
|
|
91
|
-
fs: {
|
|
92
|
-
strict: false, // https://github.com/vitejs/vite/issues/8175
|
|
93
|
-
allow: [
|
|
94
|
-
searchForWorkspaceRoot(process.cwd()),
|
|
95
|
-
searchForWorkspaceRoot(fileURLToPath(appDir)),
|
|
96
|
-
searchForWorkspaceRoot(fileURLToPath(cliDir)),
|
|
97
|
-
fileURLToPath(appDir)
|
|
98
|
-
]
|
|
99
|
-
},
|
|
100
|
-
watch: {
|
|
101
|
-
// During tests we edit the files too fast and sometimes chokidar
|
|
102
|
-
// misses change events, so enforce polling for consistency
|
|
103
|
-
usePolling: true,
|
|
104
|
-
interval: 100
|
|
105
|
-
},
|
|
106
|
-
host
|
|
107
|
-
}
|
|
108
|
-
if (ssr) config.appType = 'custom'
|
|
109
76
|
|
|
110
77
|
const vitrifyDevServer = await (
|
|
111
78
|
await import('vite')
|
|
112
79
|
).createServer({
|
|
113
80
|
configFile: false,
|
|
114
|
-
...config
|
|
81
|
+
...config,
|
|
82
|
+
logLevel,
|
|
83
|
+
define: {
|
|
84
|
+
...config.define,
|
|
85
|
+
__HOST__: `'${host}'`
|
|
86
|
+
},
|
|
87
|
+
server: {
|
|
88
|
+
...config.server,
|
|
89
|
+
host,
|
|
90
|
+
port,
|
|
91
|
+
hmr: {
|
|
92
|
+
protocol: config.server?.https ? 'wss' : 'ws',
|
|
93
|
+
port: wsPort
|
|
94
|
+
}
|
|
95
|
+
}
|
|
115
96
|
})
|
|
116
97
|
|
|
117
98
|
return vitrifyDevServer
|
|
@@ -160,7 +141,7 @@ export async function createServer({
|
|
|
160
141
|
let setup
|
|
161
142
|
let app: FastifyInstance | undefined
|
|
162
143
|
let server: Server
|
|
163
|
-
let
|
|
144
|
+
let onTemplateRendered: OnTemplateRenderedHook[]
|
|
164
145
|
let vitrifyConfig: VitrifyConfig
|
|
165
146
|
|
|
166
147
|
console.log(`Development mode: ${ssr ? ssr : 'csr'}`)
|
|
@@ -170,9 +151,17 @@ export async function createServer({
|
|
|
170
151
|
? fileURLToPath(new URL('src/vite/fastify/entry.ts', cliDir))
|
|
171
152
|
: fileURLToPath(new URL(`src/vite/${framework}/ssr/app.ts`, cliDir))
|
|
172
153
|
|
|
173
|
-
|
|
154
|
+
const environment = vite.environments.ssr
|
|
155
|
+
;({ setup, onTemplateRendered, vitrifyConfig } =
|
|
156
|
+
// @ts-expect-error missing types
|
|
157
|
+
await environment.runner.import(entryUrl))
|
|
158
|
+
// console.log(module)
|
|
159
|
+
// ;({ setup, onRendered, vitrifyConfig } = await vite.ssrLoadModule(entryUrl))
|
|
174
160
|
app = fastify({
|
|
175
161
|
logger: {
|
|
162
|
+
transport: {
|
|
163
|
+
target: '@fastify/one-line-logger'
|
|
164
|
+
},
|
|
176
165
|
level: process.env.DEBUG
|
|
177
166
|
? 'debug'
|
|
178
167
|
: process.env.PINO_LOG_LEVEL || 'info'
|
|
@@ -191,7 +180,7 @@ export async function createServer({
|
|
|
191
180
|
await app.register(fastifySsrPlugin, {
|
|
192
181
|
appDir,
|
|
193
182
|
mode: 'development',
|
|
194
|
-
|
|
183
|
+
onTemplateRendered,
|
|
195
184
|
host
|
|
196
185
|
})
|
|
197
186
|
}
|
|
@@ -8,8 +8,14 @@ import {
|
|
|
8
8
|
appendToHead
|
|
9
9
|
} from '../../helpers/utils.js'
|
|
10
10
|
import type { ViteDevServer } from 'vite'
|
|
11
|
-
import type {
|
|
11
|
+
import type {
|
|
12
|
+
OnRenderedHook,
|
|
13
|
+
OnTemplateRenderedHook,
|
|
14
|
+
SSRContext
|
|
15
|
+
} from '../../vitrify-config.js'
|
|
12
16
|
import { getAppDir } from '../../app-urls.js'
|
|
17
|
+
import { stringify } from 'devalue'
|
|
18
|
+
import stringifyObject from 'stringify-object'
|
|
13
19
|
|
|
14
20
|
type ProvideFn = (
|
|
15
21
|
req: FastifyRequest,
|
|
@@ -23,6 +29,7 @@ export interface FastifySsrOptions {
|
|
|
23
29
|
vite?: ViteDevServer
|
|
24
30
|
// frameworkDir?: URL
|
|
25
31
|
onRendered?: OnRenderedHook[]
|
|
32
|
+
onTemplateRendered?: OnTemplateRenderedHook[]
|
|
26
33
|
appDir?: URL
|
|
27
34
|
publicDir?: URL
|
|
28
35
|
mode?: string
|
|
@@ -79,7 +86,10 @@ const fastifySsrPlugin: FastifyPluginAsync<FastifySsrOptions> = async (
|
|
|
79
86
|
const entryUrl = fileURLToPath(
|
|
80
87
|
new URL('ssr/entry-server.ts', frameworkDir)
|
|
81
88
|
)
|
|
82
|
-
const
|
|
89
|
+
const environment = vite.environments.ssr
|
|
90
|
+
// @ts-expect-error missing type
|
|
91
|
+
const { render } = await environment.runner.import(entryUrl)
|
|
92
|
+
// const render = (await vite!.ssrLoadModule(entryUrl)).render
|
|
83
93
|
let manifest
|
|
84
94
|
// TODO: https://github.com/vitejs/vite/issues/2282
|
|
85
95
|
try {
|
|
@@ -89,11 +99,12 @@ const fastifySsrPlugin: FastifyPluginAsync<FastifySsrOptions> = async (
|
|
|
89
99
|
}
|
|
90
100
|
|
|
91
101
|
const html = await renderHtml({
|
|
92
|
-
|
|
93
|
-
|
|
102
|
+
req,
|
|
103
|
+
res,
|
|
94
104
|
url: url ?? '/',
|
|
95
105
|
provide,
|
|
96
106
|
onRendered: options.onRendered,
|
|
107
|
+
onTemplateRendered: options.onTemplateRendered,
|
|
97
108
|
template,
|
|
98
109
|
manifest,
|
|
99
110
|
render
|
|
@@ -124,16 +135,18 @@ const fastifySsrPlugin: FastifyPluginAsync<FastifySsrOptions> = async (
|
|
|
124
135
|
const url = req.raw.url?.replace(options.baseUrl!, '/')
|
|
125
136
|
const provide = options.provide ? await options.provide(req, res) : {}
|
|
126
137
|
|
|
127
|
-
const { template, manifest, render, onRendered } =
|
|
128
|
-
|
|
129
|
-
|
|
138
|
+
const { template, manifest, render, onRendered, onTemplateRendered } =
|
|
139
|
+
await loadSSRAssets({
|
|
140
|
+
distDir: new URL('./dist/', options.appDir)
|
|
141
|
+
})
|
|
130
142
|
|
|
131
143
|
const html = await renderHtml({
|
|
132
|
-
|
|
133
|
-
|
|
144
|
+
req,
|
|
145
|
+
res,
|
|
134
146
|
url: url ?? '/',
|
|
135
147
|
provide,
|
|
136
148
|
onRendered,
|
|
149
|
+
onTemplateRendered,
|
|
137
150
|
template,
|
|
138
151
|
manifest,
|
|
139
152
|
render
|
|
@@ -165,34 +178,77 @@ const renderTemplate = ({
|
|
|
165
178
|
|
|
166
179
|
const renderHtml = async (options: {
|
|
167
180
|
url: string
|
|
168
|
-
|
|
169
|
-
|
|
181
|
+
req: FastifyRequest | { headers: Record<string, unknown>; url: string }
|
|
182
|
+
res: FastifyReply | Record<string, unknown>
|
|
170
183
|
provide: Record<string, unknown>
|
|
171
184
|
onRendered?: OnRenderedHook[]
|
|
185
|
+
onTemplateRendered?: OnTemplateRenderedHook[]
|
|
172
186
|
template: string
|
|
173
187
|
manifest: Record<string, unknown>
|
|
174
188
|
render: any
|
|
175
189
|
}) => {
|
|
176
|
-
const
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
190
|
+
const ssrContextOnRendered: (() => unknown)[] = []
|
|
191
|
+
const ssrContext: SSRContext = {
|
|
192
|
+
req: options.req,
|
|
193
|
+
res: options.res,
|
|
194
|
+
provide: options.provide,
|
|
195
|
+
initialState: {},
|
|
196
|
+
_modules: new Set(),
|
|
197
|
+
_meta: {},
|
|
198
|
+
__qMetaList: [],
|
|
199
|
+
onRenderedList: ssrContextOnRendered,
|
|
200
|
+
onRendered: (fn: () => unknown) => {
|
|
201
|
+
ssrContextOnRendered.push(fn)
|
|
202
|
+
}
|
|
180
203
|
}
|
|
181
204
|
|
|
182
205
|
const onRendered = options.onRendered ?? []
|
|
206
|
+
const onTemplateRendered = options.onTemplateRendered ?? []
|
|
183
207
|
|
|
184
|
-
const
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
)
|
|
208
|
+
const {
|
|
209
|
+
html: appHtml,
|
|
210
|
+
preloadLinks,
|
|
211
|
+
app
|
|
212
|
+
} = await options.render(options.url, options.manifest, ssrContext)
|
|
213
|
+
|
|
214
|
+
if (ssrContextOnRendered?.length) {
|
|
215
|
+
for (const ssrFunction of ssrContextOnRendered) {
|
|
216
|
+
await ssrFunction()
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
|
|
220
|
+
if (onRendered?.length) {
|
|
221
|
+
for (const ssrFunction of onRendered) {
|
|
222
|
+
await ssrFunction({ app, ssrContext })
|
|
223
|
+
}
|
|
224
|
+
}
|
|
189
225
|
|
|
190
|
-
if (!ssrContext.initialState) ssrContext.initialState = {}
|
|
226
|
+
// if (!ssrContext.initialState) ssrContext.initialState = {}
|
|
191
227
|
ssrContext.initialState.provide = options.provide
|
|
192
228
|
|
|
229
|
+
const ssrContextInitialStateStringified: Record<
|
|
230
|
+
keyof SSRContext['initialState'],
|
|
231
|
+
string
|
|
232
|
+
> = {}
|
|
233
|
+
for (const key in ssrContext.initialState) {
|
|
234
|
+
if (key === 'provide') {
|
|
235
|
+
ssrContextInitialStateStringified[key] = JSON.stringify(
|
|
236
|
+
ssrContext.initialState.provide
|
|
237
|
+
)
|
|
238
|
+
} else if (key === 'piniaColada') {
|
|
239
|
+
ssrContextInitialStateStringified[key] = JSON.stringify(
|
|
240
|
+
ssrContext.initialState.piniaColada
|
|
241
|
+
)
|
|
242
|
+
} else {
|
|
243
|
+
ssrContextInitialStateStringified[key] = stringify(
|
|
244
|
+
ssrContext.initialState[key]
|
|
245
|
+
)
|
|
246
|
+
}
|
|
247
|
+
}
|
|
248
|
+
|
|
193
249
|
const initialStateScript = `
|
|
194
250
|
<script>
|
|
195
|
-
__INITIAL_STATE__ =
|
|
251
|
+
__INITIAL_STATE__ = ${stringifyObject(ssrContextInitialStateStringified)}
|
|
196
252
|
</script>`
|
|
197
253
|
|
|
198
254
|
let html = renderTemplate({
|
|
@@ -202,9 +258,9 @@ const renderHtml = async (options: {
|
|
|
202
258
|
preloadLinks
|
|
203
259
|
})
|
|
204
260
|
|
|
205
|
-
if (
|
|
206
|
-
for (const ssrFunction of
|
|
207
|
-
html = ssrFunction(html, ssrContext)
|
|
261
|
+
if (onTemplateRendered?.length) {
|
|
262
|
+
for (const ssrFunction of onTemplateRendered) {
|
|
263
|
+
html = await ssrFunction({ html, ssrContext })
|
|
208
264
|
}
|
|
209
265
|
}
|
|
210
266
|
|
|
@@ -226,7 +282,7 @@ const loadSSRAssets = async (
|
|
|
226
282
|
const baseOutDir = distDir || new URL('dist/', appDir)
|
|
227
283
|
|
|
228
284
|
let templatePath, manifestPath, entryServerPath
|
|
229
|
-
const
|
|
285
|
+
const vitrifyHooksPath = fileURLToPath(
|
|
230
286
|
new URL('ssr/server/virtual_vitrify-hooks.mjs', baseOutDir)
|
|
231
287
|
)
|
|
232
288
|
if (mode === 'ssg') {
|
|
@@ -251,14 +307,15 @@ const loadSSRAssets = async (
|
|
|
251
307
|
const manifest = JSON.parse(readFileSync(manifestPath).toString())
|
|
252
308
|
const entryServer = await import(entryServerPath)
|
|
253
309
|
const { render, getRoutes } = entryServer
|
|
254
|
-
const onRendered =
|
|
310
|
+
const { onTemplateRendered, onRendered } = await import(vitrifyHooksPath)
|
|
255
311
|
|
|
256
312
|
return {
|
|
257
313
|
template,
|
|
258
314
|
manifest,
|
|
259
315
|
render,
|
|
260
316
|
getRoutes,
|
|
261
|
-
onRendered
|
|
317
|
+
onRendered,
|
|
318
|
+
onTemplateRendered
|
|
262
319
|
}
|
|
263
320
|
} catch (e) {
|
|
264
321
|
console.error(e)
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { existsSync, promises as fs, mkdirSync } from 'fs'
|
|
2
|
-
import type {
|
|
2
|
+
import type { OnTemplateRenderedHook } from 'src/node/vitrify-config.js'
|
|
3
3
|
import { routesToPaths } from '../../helpers/routes.js'
|
|
4
4
|
import { renderHtml } from './fastify-ssr-plugin.js'
|
|
5
5
|
import { type RouteRecordRaw } from 'vue-router'
|
|
@@ -10,14 +10,14 @@ export const prerender = async ({
|
|
|
10
10
|
manifest,
|
|
11
11
|
render,
|
|
12
12
|
routes,
|
|
13
|
-
|
|
13
|
+
onTemplateRendered
|
|
14
14
|
}: {
|
|
15
15
|
outDir: string
|
|
16
16
|
template: string
|
|
17
17
|
manifest: Record<string, unknown>
|
|
18
18
|
render: unknown
|
|
19
19
|
routes: RouteRecordRaw[]
|
|
20
|
-
|
|
20
|
+
onTemplateRendered: OnTemplateRenderedHook[]
|
|
21
21
|
}) => {
|
|
22
22
|
const promises = []
|
|
23
23
|
const paths = routesToPaths(routes).filter(
|
|
@@ -49,10 +49,10 @@ export const prerender = async ({
|
|
|
49
49
|
manifest,
|
|
50
50
|
provide: {},
|
|
51
51
|
render,
|
|
52
|
-
|
|
53
|
-
|
|
52
|
+
req: { headers: {}, url },
|
|
53
|
+
res: {},
|
|
54
54
|
template,
|
|
55
|
-
|
|
55
|
+
onTemplateRendered
|
|
56
56
|
})
|
|
57
57
|
html = await beasties.process(html)
|
|
58
58
|
|
|
@@ -1,6 +1,9 @@
|
|
|
1
|
-
import type { FastifyInstance } from 'fastify'
|
|
2
1
|
import fastify from 'fastify'
|
|
3
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
OnTemplateRenderedHook,
|
|
4
|
+
OnSetupHook,
|
|
5
|
+
OnRenderedHook
|
|
6
|
+
} from '../../vitrify-config.js'
|
|
4
7
|
import type { FastifyCsrPlugin } from './fastify-csr-plugin.js'
|
|
5
8
|
import type { FastifySsrPlugin } from './fastify-ssr-plugin.js'
|
|
6
9
|
|
|
@@ -10,6 +13,7 @@ export const createApp = ({
|
|
|
10
13
|
baseUrl,
|
|
11
14
|
fastifyPlugin,
|
|
12
15
|
onRendered,
|
|
16
|
+
onTemplateRendered,
|
|
13
17
|
vitrifyDir,
|
|
14
18
|
mode
|
|
15
19
|
}: {
|
|
@@ -18,11 +22,15 @@ export const createApp = ({
|
|
|
18
22
|
baseUrl?: string
|
|
19
23
|
fastifyPlugin: FastifySsrPlugin | FastifyCsrPlugin
|
|
20
24
|
onRendered?: OnRenderedHook[]
|
|
25
|
+
onTemplateRendered?: OnTemplateRenderedHook[]
|
|
21
26
|
vitrifyDir?: URL
|
|
22
27
|
mode: string
|
|
23
28
|
}) => {
|
|
24
29
|
const app = fastify({
|
|
25
30
|
logger: {
|
|
31
|
+
transport: {
|
|
32
|
+
target: '@fastify/one-line-logger'
|
|
33
|
+
},
|
|
26
34
|
level: process.env.DEBUG ? 'debug' : process.env.PINO_LOG_LEVEL || 'info'
|
|
27
35
|
}
|
|
28
36
|
})
|
|
@@ -32,6 +40,7 @@ export const createApp = ({
|
|
|
32
40
|
appDir,
|
|
33
41
|
vitrifyDir,
|
|
34
42
|
onRendered,
|
|
43
|
+
onTemplateRendered,
|
|
35
44
|
mode
|
|
36
45
|
})
|
|
37
46
|
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import type {
|
|
2
|
+
OnBootHook,
|
|
3
|
+
onAppCreatedHook,
|
|
4
|
+
OnMountedHook,
|
|
5
|
+
OnRenderedHook,
|
|
6
|
+
OnTemplateRenderedHook,
|
|
7
|
+
OnSetupFile,
|
|
8
|
+
OnSetupHook
|
|
9
|
+
} from '../vitrify-config.js'
|
|
10
|
+
|
|
11
|
+
export {
|
|
12
|
+
OnBootHook,
|
|
13
|
+
onAppCreatedHook,
|
|
14
|
+
OnMountedHook,
|
|
15
|
+
OnRenderedHook,
|
|
16
|
+
OnTemplateRenderedHook,
|
|
17
|
+
OnSetupFile,
|
|
18
|
+
OnSetupHook
|
|
19
|
+
}
|