vitrify 0.24.2 → 0.25.1
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/README.md +7 -22
- package/dist/bin/cli.js +2 -2
- package/dist/bin/dev.js +3 -3
- package/dist/frameworks/vue/fastify-ssr-plugin.js +13 -13
- package/dist/frameworks/vue/server.js +2 -2
- package/dist/index.js +69 -15
- package/dist/plugins/pinia/index.js +5 -5
- package/dist/plugins/quasar/index.js +2 -2
- package/dist/types/frameworks/vue/fastify-ssr-plugin.d.ts +4 -4
- package/dist/types/frameworks/vue/server.d.ts +3 -3
- package/dist/types/hooks/index.d.ts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/types/vitrify-config.d.ts +28 -13
- package/package.json +20 -20
- package/src/node/bin/cli.ts +2 -2
- package/src/node/bin/dev.ts +5 -4
- package/src/node/frameworks/vue/fastify-ssr-plugin.ts +16 -16
- package/src/node/frameworks/vue/server.ts +4 -4
- package/src/node/hooks/index.ts +14 -8
- package/src/node/index.ts +93 -28
- package/src/node/plugins/pinia/index.ts +14 -8
- package/src/node/plugins/quasar/index.ts +4 -4
- package/src/node/vitrify-config.ts +30 -20
- package/src/vite/vue/main.ts +4 -4
- package/src/vite/vue/ssr/app.ts +7 -3
package/src/node/bin/dev.ts
CHANGED
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { LogLevel, InlineConfig, ViteDevServer } from 'vite'
|
|
2
|
-
import { searchForWorkspaceRoot } from 'vite'
|
|
3
2
|
import { baseConfig } from '../index.js'
|
|
4
3
|
import type { Server } from 'net'
|
|
5
4
|
import fastify from 'fastify'
|
|
@@ -7,6 +6,7 @@ import type { FastifyServerOptions } from 'fastify'
|
|
|
7
6
|
import { fastifySsrPlugin } from '../frameworks/vue/fastify-ssr-plugin.js'
|
|
8
7
|
import type {
|
|
9
8
|
OnTemplateRenderedHook,
|
|
9
|
+
OnAppRenderedHook,
|
|
10
10
|
VitrifyConfig
|
|
11
11
|
} from '../vitrify-config.js'
|
|
12
12
|
import isPortReachable from 'is-port-reachable'
|
|
@@ -142,6 +142,7 @@ export async function createServer({
|
|
|
142
142
|
let app: FastifyInstance | undefined
|
|
143
143
|
let server: Server
|
|
144
144
|
let onTemplateRendered: OnTemplateRenderedHook[]
|
|
145
|
+
let onAppRendered: OnAppRenderedHook[]
|
|
145
146
|
let vitrifyConfig: VitrifyConfig
|
|
146
147
|
|
|
147
148
|
console.log(`Development mode: ${ssr ? ssr : 'csr'}`)
|
|
@@ -152,11 +153,10 @@ export async function createServer({
|
|
|
152
153
|
: fileURLToPath(new URL(`src/vite/${framework}/ssr/app.ts`, cliDir))
|
|
153
154
|
|
|
154
155
|
const environment = vite.environments.ssr
|
|
155
|
-
;({ setup, onTemplateRendered, vitrifyConfig } =
|
|
156
|
+
;({ setup, onTemplateRendered, onAppRendered, vitrifyConfig } =
|
|
156
157
|
// @ts-expect-error missing types
|
|
157
158
|
await environment.runner.import(entryUrl))
|
|
158
|
-
|
|
159
|
-
// ;({ setup, onRendered, vitrifyConfig } = await vite.ssrLoadModule(entryUrl))
|
|
159
|
+
|
|
160
160
|
app = fastify({
|
|
161
161
|
logger: {
|
|
162
162
|
transport: {
|
|
@@ -181,6 +181,7 @@ export async function createServer({
|
|
|
181
181
|
appDir,
|
|
182
182
|
mode: 'development',
|
|
183
183
|
onTemplateRendered,
|
|
184
|
+
onAppRendered,
|
|
184
185
|
host
|
|
185
186
|
})
|
|
186
187
|
}
|
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
} from '../../helpers/utils.js'
|
|
10
10
|
import type { ViteDevServer } from 'vite'
|
|
11
11
|
import type {
|
|
12
|
-
|
|
12
|
+
OnAppRenderedHook,
|
|
13
13
|
OnTemplateRenderedHook,
|
|
14
14
|
SSRContext
|
|
15
15
|
} from '../../vitrify-config.js'
|
|
@@ -28,7 +28,7 @@ export interface FastifySsrOptions {
|
|
|
28
28
|
vitrifyDir?: URL
|
|
29
29
|
vite?: ViteDevServer
|
|
30
30
|
// frameworkDir?: URL
|
|
31
|
-
|
|
31
|
+
onAppRendered?: OnAppRenderedHook[]
|
|
32
32
|
onTemplateRendered?: OnTemplateRenderedHook[]
|
|
33
33
|
appDir?: URL
|
|
34
34
|
publicDir?: URL
|
|
@@ -103,7 +103,7 @@ const fastifySsrPlugin: FastifyPluginAsync<FastifySsrOptions> = async (
|
|
|
103
103
|
res,
|
|
104
104
|
url: url ?? '/',
|
|
105
105
|
provide,
|
|
106
|
-
|
|
106
|
+
onAppRendered: options.onAppRendered,
|
|
107
107
|
onTemplateRendered: options.onTemplateRendered,
|
|
108
108
|
template,
|
|
109
109
|
manifest,
|
|
@@ -135,7 +135,7 @@ const fastifySsrPlugin: FastifyPluginAsync<FastifySsrOptions> = async (
|
|
|
135
135
|
const url = req.raw.url?.replace(options.baseUrl!, '/')
|
|
136
136
|
const provide = options.provide ? await options.provide(req, res) : {}
|
|
137
137
|
|
|
138
|
-
const { template, manifest, render,
|
|
138
|
+
const { template, manifest, render, onAppRendered, onTemplateRendered } =
|
|
139
139
|
await loadSSRAssets({
|
|
140
140
|
distDir: new URL('./dist/', options.appDir)
|
|
141
141
|
})
|
|
@@ -145,7 +145,7 @@ const fastifySsrPlugin: FastifyPluginAsync<FastifySsrOptions> = async (
|
|
|
145
145
|
res,
|
|
146
146
|
url: url ?? '/',
|
|
147
147
|
provide,
|
|
148
|
-
|
|
148
|
+
onAppRendered,
|
|
149
149
|
onTemplateRendered,
|
|
150
150
|
template,
|
|
151
151
|
manifest,
|
|
@@ -181,13 +181,13 @@ const renderHtml = async (options: {
|
|
|
181
181
|
req: FastifyRequest | { headers: Record<string, unknown>; url: string }
|
|
182
182
|
res: FastifyReply | Record<string, unknown>
|
|
183
183
|
provide: Record<string, unknown>
|
|
184
|
-
|
|
184
|
+
onAppRendered?: OnAppRenderedHook[]
|
|
185
185
|
onTemplateRendered?: OnTemplateRenderedHook[]
|
|
186
186
|
template: string
|
|
187
187
|
manifest: Record<string, unknown>
|
|
188
188
|
render: any
|
|
189
189
|
}) => {
|
|
190
|
-
const
|
|
190
|
+
const ssrContextonAppRendered: (() => unknown)[] = []
|
|
191
191
|
const ssrContext: SSRContext = {
|
|
192
192
|
req: options.req,
|
|
193
193
|
res: options.res,
|
|
@@ -196,13 +196,13 @@ const renderHtml = async (options: {
|
|
|
196
196
|
_modules: new Set(),
|
|
197
197
|
_meta: {},
|
|
198
198
|
__qMetaList: [],
|
|
199
|
-
onRenderedList:
|
|
199
|
+
onRenderedList: ssrContextonAppRendered,
|
|
200
200
|
onRendered: (fn: () => unknown) => {
|
|
201
|
-
|
|
201
|
+
ssrContextonAppRendered.push(fn)
|
|
202
202
|
}
|
|
203
203
|
}
|
|
204
204
|
|
|
205
|
-
const
|
|
205
|
+
const onAppRendered = options.onAppRendered ?? []
|
|
206
206
|
const onTemplateRendered = options.onTemplateRendered ?? []
|
|
207
207
|
|
|
208
208
|
const {
|
|
@@ -211,14 +211,14 @@ const renderHtml = async (options: {
|
|
|
211
211
|
app
|
|
212
212
|
} = await options.render(options.url, options.manifest, ssrContext)
|
|
213
213
|
|
|
214
|
-
if (
|
|
215
|
-
for (const ssrFunction of
|
|
214
|
+
if (ssrContextonAppRendered?.length) {
|
|
215
|
+
for (const ssrFunction of ssrContextonAppRendered) {
|
|
216
216
|
await ssrFunction()
|
|
217
217
|
}
|
|
218
218
|
}
|
|
219
219
|
|
|
220
|
-
if (
|
|
221
|
-
for (const ssrFunction of
|
|
220
|
+
if (onAppRendered?.length) {
|
|
221
|
+
for (const ssrFunction of onAppRendered) {
|
|
222
222
|
await ssrFunction({ app, ssrContext })
|
|
223
223
|
}
|
|
224
224
|
}
|
|
@@ -307,14 +307,14 @@ const loadSSRAssets = async (
|
|
|
307
307
|
const manifest = JSON.parse(readFileSync(manifestPath).toString())
|
|
308
308
|
const entryServer = await import(entryServerPath)
|
|
309
309
|
const { render, getRoutes } = entryServer
|
|
310
|
-
const { onTemplateRendered,
|
|
310
|
+
const { onTemplateRendered, onAppRendered } = await import(vitrifyHooksPath)
|
|
311
311
|
|
|
312
312
|
return {
|
|
313
313
|
template,
|
|
314
314
|
manifest,
|
|
315
315
|
render,
|
|
316
316
|
getRoutes,
|
|
317
|
-
|
|
317
|
+
onAppRendered,
|
|
318
318
|
onTemplateRendered
|
|
319
319
|
}
|
|
320
320
|
} catch (e) {
|
|
@@ -2,7 +2,7 @@ import fastify from 'fastify'
|
|
|
2
2
|
import type {
|
|
3
3
|
OnTemplateRenderedHook,
|
|
4
4
|
OnSetupHook,
|
|
5
|
-
|
|
5
|
+
OnAppRenderedHook
|
|
6
6
|
} from '../../vitrify-config.js'
|
|
7
7
|
import type { FastifyCsrPlugin } from './fastify-csr-plugin.js'
|
|
8
8
|
import type { FastifySsrPlugin } from './fastify-ssr-plugin.js'
|
|
@@ -12,7 +12,7 @@ export const createApp = ({
|
|
|
12
12
|
appDir,
|
|
13
13
|
baseUrl,
|
|
14
14
|
fastifyPlugin,
|
|
15
|
-
|
|
15
|
+
onAppRendered,
|
|
16
16
|
onTemplateRendered,
|
|
17
17
|
vitrifyDir,
|
|
18
18
|
mode
|
|
@@ -21,7 +21,7 @@ export const createApp = ({
|
|
|
21
21
|
appDir: URL
|
|
22
22
|
baseUrl?: string
|
|
23
23
|
fastifyPlugin: FastifySsrPlugin | FastifyCsrPlugin
|
|
24
|
-
|
|
24
|
+
onAppRendered?: OnAppRenderedHook[]
|
|
25
25
|
onTemplateRendered?: OnTemplateRenderedHook[]
|
|
26
26
|
vitrifyDir?: URL
|
|
27
27
|
mode: string
|
|
@@ -39,7 +39,7 @@ export const createApp = ({
|
|
|
39
39
|
baseUrl,
|
|
40
40
|
appDir,
|
|
41
41
|
vitrifyDir,
|
|
42
|
-
|
|
42
|
+
onAppRendered,
|
|
43
43
|
onTemplateRendered,
|
|
44
44
|
mode
|
|
45
45
|
})
|
package/src/node/hooks/index.ts
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
OnAppCreatedHook,
|
|
3
|
+
OnAppCreatedHookFile,
|
|
4
4
|
OnAppMountedHook,
|
|
5
|
-
|
|
5
|
+
OnAppMountedHookFile,
|
|
6
|
+
OnAppRenderedHook,
|
|
7
|
+
OnAppRenderedHookFile,
|
|
6
8
|
OnTemplateRenderedHook,
|
|
7
|
-
|
|
9
|
+
OnTemplateRenderedHookFile,
|
|
10
|
+
OnSetupHookFile,
|
|
8
11
|
OnSetupHook
|
|
9
12
|
} from '../vitrify-config.js'
|
|
10
13
|
|
|
11
14
|
export {
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
OnAppCreatedHook,
|
|
16
|
+
OnAppCreatedHookFile,
|
|
14
17
|
OnAppMountedHook,
|
|
15
|
-
|
|
18
|
+
OnAppMountedHookFile,
|
|
19
|
+
OnAppRenderedHook,
|
|
20
|
+
OnAppRenderedHookFile,
|
|
16
21
|
OnTemplateRenderedHook,
|
|
17
|
-
|
|
22
|
+
OnTemplateRenderedHookFile,
|
|
23
|
+
OnSetupHookFile,
|
|
18
24
|
OnSetupHook
|
|
19
25
|
}
|
package/src/node/index.ts
CHANGED
|
@@ -24,11 +24,14 @@ import type {
|
|
|
24
24
|
VitrifyModes,
|
|
25
25
|
VitrifyUIFrameworks,
|
|
26
26
|
VitrifySSRModes,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
27
|
+
OnAppRenderedHook,
|
|
28
|
+
OnSetupHookFile,
|
|
29
|
+
OnAppCreatedHook,
|
|
30
|
+
OnTemplateRenderedHook,
|
|
31
|
+
OnAppCreatedHookFile,
|
|
32
|
+
OnAppRenderedHookFile,
|
|
33
|
+
OnTemplateRenderedHookFile,
|
|
34
|
+
OnAppMountedHookFile
|
|
32
35
|
} from './vitrify-config.js'
|
|
33
36
|
import type { VitrifyContext } from './bin/run.js'
|
|
34
37
|
import type { VitrifyPlugin } from './plugins/index.js'
|
|
@@ -278,12 +281,15 @@ export const baseConfig = async ({
|
|
|
278
281
|
}
|
|
279
282
|
}
|
|
280
283
|
|
|
281
|
-
let
|
|
282
|
-
let
|
|
284
|
+
let onAppRenderedHooks: OnAppRenderedHook[]
|
|
285
|
+
let onAppRenderedFiles: OnAppRenderedHookFile[]
|
|
283
286
|
let onTemplateRenderedHooks: OnTemplateRenderedHook[]
|
|
287
|
+
let onTemplateRenderedFiles: OnTemplateRenderedHookFile[]
|
|
284
288
|
let onAppMountedHooks: OnAppMountedHook[]
|
|
285
|
-
let
|
|
286
|
-
let
|
|
289
|
+
let onAppMountedFiles: OnAppMountedHookFile[]
|
|
290
|
+
let OnAppCreatedHooks: OnAppCreatedHook[]
|
|
291
|
+
let onAppCreatedFiles: OnAppCreatedHookFile[]
|
|
292
|
+
let onSetupFiles: OnSetupHookFile[]
|
|
287
293
|
let globalCss: string[] = []
|
|
288
294
|
let staticImports: StaticImports
|
|
289
295
|
let sassVariables: Record<string, string | undefined>
|
|
@@ -358,12 +364,16 @@ export const baseConfig = async ({
|
|
|
358
364
|
name: 'vitrify-setup',
|
|
359
365
|
enforce: 'post',
|
|
360
366
|
config: (config: VitrifyConfig, env) => {
|
|
361
|
-
|
|
362
|
-
|
|
367
|
+
onAppRenderedHooks = config.vitrify?.hooks?.onAppRendered || []
|
|
368
|
+
onAppRenderedFiles = config.vitrify?.hooks?.onAppRenderedFiles || []
|
|
363
369
|
onTemplateRenderedHooks =
|
|
364
370
|
config.vitrify?.hooks?.onTemplateRendered || []
|
|
371
|
+
onTemplateRenderedFiles =
|
|
372
|
+
config.vitrify?.hooks?.onTemplateRenderedFiles || []
|
|
365
373
|
onAppMountedHooks = config.vitrify?.hooks?.onAppMounted || []
|
|
366
|
-
|
|
374
|
+
onAppMountedFiles = config.vitrify?.hooks?.onAppMountedFiles || []
|
|
375
|
+
OnAppCreatedHooks = config.vitrify?.hooks?.onAppCreated || []
|
|
376
|
+
onAppCreatedFiles = config.vitrify?.hooks?.onAppCreatedFiles || []
|
|
367
377
|
onSetupFiles = config?.vitrify?.hooks?.onSetup || []
|
|
368
378
|
globalCss = config.vitrify?.globalCss || []
|
|
369
379
|
staticImports = config.vitrify?.staticImports || {}
|
|
@@ -392,21 +402,82 @@ export const baseConfig = async ({
|
|
|
392
402
|
},
|
|
393
403
|
load(id) {
|
|
394
404
|
if (id === 'virtual:vitrify-hooks') {
|
|
395
|
-
return `export const
|
|
405
|
+
return `export const onAppMounted = [${onAppMountedHooks
|
|
396
406
|
.map((fn) => `${String(fn)}`)
|
|
397
407
|
.join(', ')}]
|
|
398
|
-
|
|
399
|
-
.map((
|
|
400
|
-
|
|
401
|
-
|
|
408
|
+
${onAppMountedFiles
|
|
409
|
+
.map((url, index) => {
|
|
410
|
+
const varName = fileURLToPath(url)
|
|
411
|
+
.replaceAll('/', '')
|
|
412
|
+
.replaceAll(':', '')
|
|
413
|
+
.replaceAll('\\', '')
|
|
414
|
+
.replaceAll('.', '')
|
|
415
|
+
.replaceAll('-', '')
|
|
416
|
+
.replaceAll('_', '')
|
|
417
|
+
.replaceAll('+', '')
|
|
418
|
+
|
|
419
|
+
return `import ${varName} from '${
|
|
420
|
+
new URL(url, appDir).pathname
|
|
421
|
+
}'; onAppMounted.push(${varName});`
|
|
422
|
+
})
|
|
423
|
+
.join('\n')}
|
|
424
|
+
export const onAppRendered = [${onAppRenderedHooks
|
|
402
425
|
.map((fn) => `${String(fn)}`)
|
|
403
426
|
.join(', ')}]
|
|
427
|
+
${onAppRenderedFiles
|
|
428
|
+
.map((url, index) => {
|
|
429
|
+
const varName = fileURLToPath(url)
|
|
430
|
+
.replaceAll('/', '')
|
|
431
|
+
.replaceAll(':', '')
|
|
432
|
+
.replaceAll('\\', '')
|
|
433
|
+
.replaceAll('.', '')
|
|
434
|
+
.replaceAll('-', '')
|
|
435
|
+
.replaceAll('_', '')
|
|
436
|
+
.replaceAll('+', '')
|
|
437
|
+
|
|
438
|
+
return `import ${varName} from '${
|
|
439
|
+
new URL(url, appDir).pathname
|
|
440
|
+
}'; onAppRendered.push(${varName});`
|
|
441
|
+
})
|
|
442
|
+
.join('\n')}
|
|
404
443
|
export const onTemplateRendered = [${onTemplateRenderedHooks
|
|
405
444
|
.map((fn) => `${String(fn)}`)
|
|
406
445
|
.join(', ')}]
|
|
407
|
-
|
|
408
|
-
.map((
|
|
409
|
-
|
|
446
|
+
${onTemplateRenderedFiles
|
|
447
|
+
.map((url, index) => {
|
|
448
|
+
const varName = fileURLToPath(url)
|
|
449
|
+
.replaceAll('/', '')
|
|
450
|
+
.replaceAll(':', '')
|
|
451
|
+
.replaceAll('\\', '')
|
|
452
|
+
.replaceAll('.', '')
|
|
453
|
+
.replaceAll('-', '')
|
|
454
|
+
.replaceAll('_', '')
|
|
455
|
+
.replaceAll('+', '')
|
|
456
|
+
|
|
457
|
+
return `import ${varName} from '${
|
|
458
|
+
new URL(url, appDir).pathname
|
|
459
|
+
}'; onTemplateRendered.push(${varName});`
|
|
460
|
+
})
|
|
461
|
+
.join('\n')}
|
|
462
|
+
export const onAppCreated = [${OnAppCreatedHooks.map(
|
|
463
|
+
(fn) => `${String(fn)}`
|
|
464
|
+
).join(', ')}]
|
|
465
|
+
${onAppCreatedFiles
|
|
466
|
+
.map((url, index) => {
|
|
467
|
+
const varName = fileURLToPath(url)
|
|
468
|
+
.replaceAll('/', '')
|
|
469
|
+
.replaceAll(':', '')
|
|
470
|
+
.replaceAll('\\', '')
|
|
471
|
+
.replaceAll('.', '')
|
|
472
|
+
.replaceAll('-', '')
|
|
473
|
+
.replaceAll('_', '')
|
|
474
|
+
.replaceAll('+', '')
|
|
475
|
+
|
|
476
|
+
return `import ${varName} from '${
|
|
477
|
+
new URL(url, appDir).pathname
|
|
478
|
+
}'; onAppCreated.push(${varName});`
|
|
479
|
+
})
|
|
480
|
+
.join('\n')}
|
|
410
481
|
export const onSetup = []
|
|
411
482
|
${onSetupFiles
|
|
412
483
|
.map((url, index) => {
|
|
@@ -421,7 +492,7 @@ export const baseConfig = async ({
|
|
|
421
492
|
|
|
422
493
|
return `import ${varName} from '${
|
|
423
494
|
new URL(url, appDir).pathname
|
|
424
|
-
}'; onSetup.push(${varName})
|
|
495
|
+
}'; onSetup.push(${varName});`
|
|
425
496
|
})
|
|
426
497
|
.join('\n')}`
|
|
427
498
|
} else if (id === 'virtual:static-imports') {
|
|
@@ -733,10 +804,4 @@ export const baseConfig = async ({
|
|
|
733
804
|
export const vitrifyDir = new URL('..', import.meta.url)
|
|
734
805
|
export { prerender } from './frameworks/vue/prerender.js'
|
|
735
806
|
|
|
736
|
-
export type {
|
|
737
|
-
VitrifyConfig,
|
|
738
|
-
VitrifyConfigAsync,
|
|
739
|
-
VitrifyPlugin,
|
|
740
|
-
VitrifyContext,
|
|
741
|
-
OnBootHook
|
|
742
|
-
}
|
|
807
|
+
export type { VitrifyConfig, VitrifyConfigAsync, VitrifyPlugin, VitrifyContext }
|
|
@@ -1,4 +1,7 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type {
|
|
2
|
+
OnAppCreatedHook,
|
|
3
|
+
OnAppRenderedHook
|
|
4
|
+
} from '../../vitrify-config.js'
|
|
2
5
|
import type { VitrifyPlugin } from '../index.js'
|
|
3
6
|
|
|
4
7
|
export type PiniaPluginOptions = {
|
|
@@ -6,7 +9,7 @@ export type PiniaPluginOptions = {
|
|
|
6
9
|
colada?: boolean
|
|
7
10
|
}
|
|
8
11
|
|
|
9
|
-
const piniaOnAppCreated:
|
|
12
|
+
const piniaOnAppCreated: OnAppCreatedHook = async ({
|
|
10
13
|
app,
|
|
11
14
|
ctx,
|
|
12
15
|
initialState,
|
|
@@ -23,14 +26,17 @@ const piniaOnAppCreated: onAppCreatedHook = async ({
|
|
|
23
26
|
if (ssrContext) ssrContext.pinia = pinia
|
|
24
27
|
}
|
|
25
28
|
|
|
26
|
-
const
|
|
29
|
+
const piniaonAppRenderedHook: OnAppRenderedHook = async ({
|
|
30
|
+
app,
|
|
31
|
+
ssrContext
|
|
32
|
+
}) => {
|
|
27
33
|
// SSR Server
|
|
28
34
|
if (ssrContext?.initialState && ssrContext.pinia) {
|
|
29
35
|
ssrContext.initialState.pinia = ssrContext.pinia.state.value
|
|
30
36
|
}
|
|
31
37
|
}
|
|
32
38
|
|
|
33
|
-
const piniaColadaonAppCreated:
|
|
39
|
+
const piniaColadaonAppCreated: OnAppCreatedHook = async ({
|
|
34
40
|
app,
|
|
35
41
|
ctx,
|
|
36
42
|
initialState
|
|
@@ -52,7 +58,7 @@ const piniaColadaonAppCreated: onAppCreatedHook = async ({
|
|
|
52
58
|
}
|
|
53
59
|
}
|
|
54
60
|
|
|
55
|
-
const
|
|
61
|
+
const piniaColadaonAppRenderedHook: OnAppRenderedHook = async ({
|
|
56
62
|
app,
|
|
57
63
|
ssrContext
|
|
58
64
|
}) => {
|
|
@@ -76,10 +82,10 @@ export const PiniaPlugin: VitrifyPlugin<PiniaPluginOptions> = async ({
|
|
|
76
82
|
options = {}
|
|
77
83
|
}) => {
|
|
78
84
|
const onAppCreated = [piniaOnAppCreated]
|
|
79
|
-
const
|
|
85
|
+
const onAppRendered = [piniaonAppRenderedHook]
|
|
80
86
|
if (options.colada) {
|
|
81
87
|
onAppCreated.push(piniaColadaonAppCreated)
|
|
82
|
-
|
|
88
|
+
onAppRendered.push(piniaColadaonAppRenderedHook)
|
|
83
89
|
}
|
|
84
90
|
|
|
85
91
|
return {
|
|
@@ -88,7 +94,7 @@ export const PiniaPlugin: VitrifyPlugin<PiniaPluginOptions> = async ({
|
|
|
88
94
|
vitrify: {
|
|
89
95
|
hooks: {
|
|
90
96
|
onAppCreated,
|
|
91
|
-
|
|
97
|
+
onAppRendered
|
|
92
98
|
}
|
|
93
99
|
}
|
|
94
100
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { fileURLToPath } from 'url'
|
|
2
2
|
import type {
|
|
3
|
-
OnBootHook,
|
|
4
3
|
OnAppMountedHook,
|
|
5
4
|
OnTemplateRenderedHook,
|
|
6
|
-
VitrifyConfig
|
|
5
|
+
VitrifyConfig,
|
|
6
|
+
OnAppCreatedHook
|
|
7
7
|
} from '../../vitrify-config.js'
|
|
8
8
|
import type { VitrifyPlugin } from '../index.js'
|
|
9
9
|
import { findDepPkgJsonPath } from 'vitefu'
|
|
@@ -145,7 +145,7 @@ export const QuasarPlugin: VitrifyPlugin<QuasarPluginOptions> = async ({
|
|
|
145
145
|
}
|
|
146
146
|
]
|
|
147
147
|
|
|
148
|
-
const
|
|
148
|
+
const onAppCreatedHooks: OnAppCreatedHook[] = [
|
|
149
149
|
async ({ app, ssrContext, staticImports }) => {
|
|
150
150
|
// @ts-expect-error undefined
|
|
151
151
|
const quasarPlugins = await import('virtual:quasar-plugins')
|
|
@@ -202,7 +202,7 @@ export const QuasarPlugin: VitrifyPlugin<QuasarPluginOptions> = async ({
|
|
|
202
202
|
quasar: ['Quasar']
|
|
203
203
|
},
|
|
204
204
|
hooks: {
|
|
205
|
-
|
|
205
|
+
onAppCreated: onAppCreatedHooks,
|
|
206
206
|
onAppMounted: onAppMountedHooks,
|
|
207
207
|
onTemplateRendered: [injectSsrContext]
|
|
208
208
|
},
|
|
@@ -49,12 +49,14 @@ export type SSRContext = {
|
|
|
49
49
|
[key: string]: unknown
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
export type
|
|
52
|
+
export type OnAppCreatedHookFile = URL
|
|
53
|
+
export type OnAppCreatedHook = ({
|
|
53
54
|
app,
|
|
54
55
|
router,
|
|
55
56
|
ctx,
|
|
56
57
|
initialState,
|
|
57
|
-
ssrContext
|
|
58
|
+
ssrContext,
|
|
59
|
+
staticImports
|
|
58
60
|
}: {
|
|
59
61
|
app: App
|
|
60
62
|
router: Router
|
|
@@ -69,18 +71,10 @@ export type onAppCreatedHook = ({
|
|
|
69
71
|
[key: string]: unknown
|
|
70
72
|
}
|
|
71
73
|
ssrContext?: SSRContext
|
|
72
|
-
}) => Promise<void> | void
|
|
73
|
-
|
|
74
|
-
export type OnBootHook = ({
|
|
75
|
-
app,
|
|
76
|
-
ssrContext,
|
|
77
|
-
staticImports
|
|
78
|
-
}: {
|
|
79
|
-
app: App
|
|
80
|
-
ssrContext: SSRContext
|
|
81
74
|
staticImports?: Record<string, any>
|
|
82
75
|
}) => Promise<void> | void
|
|
83
76
|
|
|
77
|
+
export type OnAppMountedHookFile = URL
|
|
84
78
|
export type OnAppMountedHook = ({
|
|
85
79
|
instance
|
|
86
80
|
}: {
|
|
@@ -88,7 +82,7 @@ export type OnAppMountedHook = ({
|
|
|
88
82
|
}) => Promise<void> | void
|
|
89
83
|
export type StaticImports = Record<string, string[]>
|
|
90
84
|
|
|
91
|
-
export type
|
|
85
|
+
export type OnSetupHookFile = URL
|
|
92
86
|
export type OnSetupHook = (
|
|
93
87
|
fastify: FastifyInstance,
|
|
94
88
|
options?: {
|
|
@@ -107,7 +101,8 @@ export type Render = (
|
|
|
107
101
|
app: App
|
|
108
102
|
}>
|
|
109
103
|
|
|
110
|
-
export type
|
|
104
|
+
export type OnAppRenderedHookFile = URL
|
|
105
|
+
export type OnAppRenderedHook = ({
|
|
111
106
|
app,
|
|
112
107
|
ssrContext
|
|
113
108
|
}: {
|
|
@@ -115,6 +110,7 @@ export type OnRenderedHook = ({
|
|
|
115
110
|
ssrContext?: SSRContext
|
|
116
111
|
}) => Promise<void> | void
|
|
117
112
|
|
|
113
|
+
export type OnTemplateRenderedHookFile = URL
|
|
118
114
|
export type OnTemplateRenderedHook = ({
|
|
119
115
|
html,
|
|
120
116
|
ssrContext
|
|
@@ -142,27 +138,39 @@ export interface VitrifyConfig extends ViteUserConfig {
|
|
|
142
138
|
/**
|
|
143
139
|
* setup() is called directly after instantiating fastify. Use it to register your own plugins, routes etc.
|
|
144
140
|
*/
|
|
145
|
-
onSetup?:
|
|
141
|
+
onSetup?: OnSetupHookFile[]
|
|
142
|
+
/**
|
|
143
|
+
* Functions which run directly after initializing the application
|
|
144
|
+
*/
|
|
145
|
+
onAppCreated?: OnAppCreatedHook[]
|
|
146
|
+
/**
|
|
147
|
+
* Functions which run directly after initializing the application
|
|
148
|
+
*/
|
|
149
|
+
onAppCreatedFiles?: OnAppCreatedHookFile[]
|
|
146
150
|
/**
|
|
147
151
|
* Functions which run in the onMounted hook of the app
|
|
148
152
|
*/
|
|
149
153
|
onAppMounted?: OnAppMountedHook[]
|
|
150
154
|
/**
|
|
151
|
-
*
|
|
155
|
+
* Files with functions which run in the onMounted hook of the app
|
|
152
156
|
*/
|
|
153
|
-
|
|
157
|
+
onAppMountedFiles?: OnAppMountedHookFile[]
|
|
154
158
|
/**
|
|
155
159
|
* Functions which run after rendering the app (SSR)
|
|
156
160
|
*/
|
|
157
|
-
|
|
161
|
+
onAppRendered?: OnAppRenderedHook[]
|
|
162
|
+
/**
|
|
163
|
+
* Files with functions which run after rendering the app (SSR)
|
|
164
|
+
*/
|
|
165
|
+
onAppRenderedFiles?: OnAppRenderedHookFile[]
|
|
158
166
|
/**
|
|
159
167
|
* Functions which run after rendering the template (SSR)
|
|
160
168
|
*/
|
|
161
169
|
onTemplateRendered?: OnTemplateRenderedHook[]
|
|
162
170
|
/**
|
|
163
|
-
*
|
|
171
|
+
* Files with functions which run after rendering the template (SSR)
|
|
164
172
|
*/
|
|
165
|
-
|
|
173
|
+
onTemplateRenderedFiles?: OnTemplateRenderedHookFile[]
|
|
166
174
|
}
|
|
167
175
|
/**
|
|
168
176
|
* Global SASS variables
|
|
@@ -189,6 +197,9 @@ export interface VitrifyConfig extends ViteUserConfig {
|
|
|
189
197
|
* SSR specific configuration
|
|
190
198
|
*/
|
|
191
199
|
ssr?: {
|
|
200
|
+
/**
|
|
201
|
+
* Packages which should not be bundled but installed on the server instead.
|
|
202
|
+
*/
|
|
192
203
|
serverModules?: string[]
|
|
193
204
|
fastify?: FastifyServerOptions
|
|
194
205
|
}
|
|
@@ -215,7 +226,6 @@ export interface VitrifyConfig extends ViteUserConfig {
|
|
|
215
226
|
*/
|
|
216
227
|
unpluginVueComponents?: unpluginVueComponentsOptions
|
|
217
228
|
}
|
|
218
|
-
// quasar?: QuasarConf
|
|
219
229
|
}
|
|
220
230
|
|
|
221
231
|
export type VitrifyCommands = 'build' | 'dev' | 'test'
|
package/src/vite/vue/main.ts
CHANGED
|
@@ -70,7 +70,7 @@ export async function createApp(
|
|
|
70
70
|
app.use(router)
|
|
71
71
|
|
|
72
72
|
for (const fn of onAppCreated) {
|
|
73
|
-
await fn({ app, router, ctx, initialState, ssrContext })
|
|
73
|
+
await fn({ app, router, ctx, initialState, ssrContext, staticImports })
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
// Workaround to fix hydration errors when serving html files directly
|
|
@@ -95,9 +95,9 @@ export async function createApp(
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
for (const fn of onBoot) {
|
|
99
|
-
|
|
100
|
-
}
|
|
98
|
+
// for (const fn of onBoot) {
|
|
99
|
+
// await fn({ app, ssrContext, staticImports })
|
|
100
|
+
// }
|
|
101
101
|
|
|
102
102
|
// @vitrify-pwa-only
|
|
103
103
|
// @ts-expect-error undefined
|
package/src/vite/vue/ssr/app.ts
CHANGED
|
@@ -1,6 +1,10 @@
|
|
|
1
1
|
import { createApp } from '../../../node/frameworks/vue/server.js'
|
|
2
2
|
import { getAppDir } from '../../../node/app-urls.js'
|
|
3
|
-
import {
|
|
3
|
+
import {
|
|
4
|
+
onSetup,
|
|
5
|
+
onAppRendered,
|
|
6
|
+
onTemplateRendered
|
|
7
|
+
} from 'virtual:vitrify-hooks'
|
|
4
8
|
import { fastifySsrPlugin } from './fastify-ssr-plugin.js'
|
|
5
9
|
|
|
6
10
|
const getString = (str?: string) => str
|
|
@@ -13,11 +17,11 @@ export const setupApp = async () => {
|
|
|
13
17
|
appDir,
|
|
14
18
|
baseUrl,
|
|
15
19
|
fastifyPlugin: fastifySsrPlugin,
|
|
16
|
-
|
|
20
|
+
onAppRendered,
|
|
17
21
|
onTemplateRendered,
|
|
18
22
|
mode: import.meta.env.MODE
|
|
19
23
|
})
|
|
20
24
|
}
|
|
21
25
|
|
|
22
26
|
export { default as vitrifyConfig } from 'virtual:vitrify-config'
|
|
23
|
-
export {
|
|
27
|
+
export { onAppRendered, onTemplateRendered }
|