vitrify 0.26.0 → 0.26.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/dist/bin/dev.js +5 -1
- package/dist/frameworks/vue/fastify-ssr-plugin.js +1 -1
- package/dist/index.js +59 -33
- package/package.json +1 -1
- package/src/node/bin/dev.ts +5 -1
- package/src/node/frameworks/vue/fastify-ssr-plugin.ts +3 -1
- package/src/node/index.ts +64 -38
- package/src/vite/fastify/entry.ts +5 -3
- package/src/vite/vue/RootComponent.vue +5 -3
- package/src/vite/vue/csr/app.ts +2 -2
- package/src/vite/vue/main.ts +5 -3
- package/src/vite/vue/ssr/app.ts +5 -9
- package/src/vite/vue/ssr/prerender.ts +2 -2
- package/src/vite/vue/ssr/server.ts +3 -0
package/dist/bin/dev.js
CHANGED
|
@@ -98,7 +98,11 @@ ssr, framework = 'vue', host, appDir, publicDir, vite }) {
|
|
|
98
98
|
? fileURLToPath(new URL('src/vite/fastify/entry.ts', cliDir))
|
|
99
99
|
: fileURLToPath(new URL(`src/vite/${framework}/ssr/app.ts`, cliDir));
|
|
100
100
|
const environment = vite.environments.ssr;
|
|
101
|
-
({
|
|
101
|
+
({
|
|
102
|
+
setup,
|
|
103
|
+
hooks: { onTemplateRendered, onAppRendered },
|
|
104
|
+
vitrifyConfig
|
|
105
|
+
} =
|
|
102
106
|
// @ts-expect-error missing types
|
|
103
107
|
await environment.runner.import(entryUrl));
|
|
104
108
|
app = fastify({
|
|
@@ -191,7 +191,7 @@ const loadSSRAssets = async ({ mode, distDir } = {
|
|
|
191
191
|
const manifest = JSON.parse(readFileSync(manifestPath).toString());
|
|
192
192
|
const entryServer = await import(entryServerPath);
|
|
193
193
|
const { render, getRoutes } = entryServer;
|
|
194
|
-
const { onTemplateRendered, onAppRendered } = await import(vitrifyHooksPath);
|
|
194
|
+
const { hooks: { onTemplateRendered, onAppRendered } } = await import(vitrifyHooksPath);
|
|
195
195
|
return {
|
|
196
196
|
template,
|
|
197
197
|
manifest,
|
package/dist/index.js
CHANGED
|
@@ -31,8 +31,8 @@ const internalServerModules = [
|
|
|
31
31
|
const manualChunkNames = [
|
|
32
32
|
'prerender',
|
|
33
33
|
'fastify-ssr-plugin',
|
|
34
|
-
'fastify-csr-plugin'
|
|
35
|
-
'server'
|
|
34
|
+
'fastify-csr-plugin'
|
|
35
|
+
// 'server'
|
|
36
36
|
];
|
|
37
37
|
const moduleChunks = {
|
|
38
38
|
vue: [
|
|
@@ -53,28 +53,6 @@ const moduleChunks = {
|
|
|
53
53
|
quasar: ['quasar'],
|
|
54
54
|
atQuasar: ['@quasar']
|
|
55
55
|
};
|
|
56
|
-
const manualChunksFn = (manualChunkList) => {
|
|
57
|
-
return (id) => {
|
|
58
|
-
const matchedModule = Object.entries(moduleChunks).find(([chunkName, moduleNames]) => moduleNames.some((moduleName) => new RegExp(`\/${moduleName}\/`).test(id)));
|
|
59
|
-
if (id.includes('vitrify/src/')) {
|
|
60
|
-
const name = id.split('/').at(-1)?.split('.').at(0);
|
|
61
|
-
if (name && manualChunkNames.includes(name))
|
|
62
|
-
return name;
|
|
63
|
-
}
|
|
64
|
-
else if (VIRTUAL_MODULES.some((virtualModule) => id.includes(virtualModule))) {
|
|
65
|
-
return VIRTUAL_MODULES.find((name) => id.includes(name));
|
|
66
|
-
}
|
|
67
|
-
else if (manualChunkList?.some((file) => id.includes(file))) {
|
|
68
|
-
return manualChunkList.find((file) => id.includes(file));
|
|
69
|
-
}
|
|
70
|
-
else if (id.includes('node_modules')) {
|
|
71
|
-
if (matchedModule) {
|
|
72
|
-
return matchedModule[0];
|
|
73
|
-
}
|
|
74
|
-
return 'vendor';
|
|
75
|
-
}
|
|
76
|
-
};
|
|
77
|
-
};
|
|
78
56
|
export const VIRTUAL_MODULES = [
|
|
79
57
|
'virtual:vitrify-hooks',
|
|
80
58
|
'virtual:static-imports',
|
|
@@ -82,6 +60,41 @@ export const VIRTUAL_MODULES = [
|
|
|
82
60
|
'vitrify.sass',
|
|
83
61
|
'vitrify.css'
|
|
84
62
|
];
|
|
63
|
+
/**
|
|
64
|
+
* Advanced chunking may no longer be necessary.
|
|
65
|
+
* @param ssr
|
|
66
|
+
* @returns
|
|
67
|
+
*/
|
|
68
|
+
const createCodeSplittingGroups = (ssr) => {
|
|
69
|
+
return [
|
|
70
|
+
...VIRTUAL_MODULES.map((m) => ({
|
|
71
|
+
name: m,
|
|
72
|
+
test: new RegExp(m),
|
|
73
|
+
priority: 30
|
|
74
|
+
}))
|
|
75
|
+
// ...manualChunkNames.map((m) => ({
|
|
76
|
+
// name: m,
|
|
77
|
+
// test: new RegExp(m),
|
|
78
|
+
// priority: 20
|
|
79
|
+
// })),
|
|
80
|
+
// ...Object.entries(moduleChunks).map(([key, value]) => ({
|
|
81
|
+
// name: key,
|
|
82
|
+
// test: new RegExp(value.join('|')),
|
|
83
|
+
// priority: 20,
|
|
84
|
+
// maxSize: ssr === 'client' || ssr === 'ssg' ? 1000000 : Infinity
|
|
85
|
+
// })),
|
|
86
|
+
// {
|
|
87
|
+
// name: 'vendor',
|
|
88
|
+
// test: /node_modules/,
|
|
89
|
+
// priority: 1
|
|
90
|
+
// },
|
|
91
|
+
// {
|
|
92
|
+
// name: 'typst',
|
|
93
|
+
// test: /\.typ/,
|
|
94
|
+
// priority: 40
|
|
95
|
+
// }
|
|
96
|
+
];
|
|
97
|
+
};
|
|
85
98
|
export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command = 'build', mode = 'production', framework = 'vue', debug = false, productName }) => {
|
|
86
99
|
const { getAppDir, getCliDir, getCliViteDir, getSrcDir, getCwd } = await import('./app-urls.js');
|
|
87
100
|
if (!appDir) {
|
|
@@ -280,7 +293,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
280
293
|
},
|
|
281
294
|
load(id) {
|
|
282
295
|
if (id === 'virtual:vitrify-hooks') {
|
|
283
|
-
return `
|
|
296
|
+
return `const onAppMounted = [${onAppMountedHooks
|
|
284
297
|
.map((fn) => `${String(fn)}`)
|
|
285
298
|
.join(', ')}]
|
|
286
299
|
${onAppMountedFiles
|
|
@@ -296,7 +309,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
296
309
|
return `import ${varName} from '${new URL(url, appDir).href}'; onAppMounted.push(${varName});`;
|
|
297
310
|
})
|
|
298
311
|
.join('\n')}
|
|
299
|
-
|
|
312
|
+
const onAppRendered = [${onAppRenderedHooks
|
|
300
313
|
.map((fn) => `${String(fn)}`)
|
|
301
314
|
.join(', ')}]
|
|
302
315
|
${onAppRenderedFiles
|
|
@@ -312,7 +325,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
312
325
|
return `import ${varName} from '${new URL(url, appDir).href}'; onAppRendered.push(${varName});`;
|
|
313
326
|
})
|
|
314
327
|
.join('\n')}
|
|
315
|
-
|
|
328
|
+
const onTemplateRendered = [${onTemplateRenderedHooks
|
|
316
329
|
.map((fn) => `${String(fn)}`)
|
|
317
330
|
.join(', ')}]
|
|
318
331
|
${onTemplateRenderedFiles
|
|
@@ -328,7 +341,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
328
341
|
return `import ${varName} from '${new URL(url, appDir).href}'; onTemplateRendered.push(${varName});`;
|
|
329
342
|
})
|
|
330
343
|
.join('\n')}
|
|
331
|
-
|
|
344
|
+
const onAppCreated = [${OnAppCreatedHooks.map((fn) => `${String(fn)}`).join(', ')}]
|
|
332
345
|
${onAppCreatedFiles
|
|
333
346
|
.map((url, index) => {
|
|
334
347
|
const varName = fileURLToPath(url)
|
|
@@ -342,7 +355,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
342
355
|
return `import ${varName} from '${new URL(url, appDir).href}'; onAppCreated.push(${varName});`;
|
|
343
356
|
})
|
|
344
357
|
.join('\n')}
|
|
345
|
-
|
|
358
|
+
const onSetup = []
|
|
346
359
|
${onSetupFiles
|
|
347
360
|
.map((url, index) => {
|
|
348
361
|
const varName = fileURLToPath(url)
|
|
@@ -355,7 +368,14 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
355
368
|
.replaceAll('+', '');
|
|
356
369
|
return `import ${varName} from '${new URL(url, appDir).href}'; onSetup.push(${varName});`;
|
|
357
370
|
})
|
|
358
|
-
.join('\n')}
|
|
371
|
+
.join('\n')}
|
|
372
|
+
export const hooks = {
|
|
373
|
+
onAppMounted,
|
|
374
|
+
onAppRendered,
|
|
375
|
+
onAppCreated,
|
|
376
|
+
onTemplateRendered,
|
|
377
|
+
onSetup
|
|
378
|
+
}`;
|
|
359
379
|
}
|
|
360
380
|
else if (id === 'virtual:static-imports') {
|
|
361
381
|
return `${Object.entries(staticImports)
|
|
@@ -522,7 +542,9 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
522
542
|
entryFileNames: '[name].mjs',
|
|
523
543
|
chunkFileNames: '[name].mjs',
|
|
524
544
|
format: 'es',
|
|
525
|
-
|
|
545
|
+
codeSplitting: {
|
|
546
|
+
groups: createCodeSplittingGroups(ssr)
|
|
547
|
+
}
|
|
526
548
|
}
|
|
527
549
|
};
|
|
528
550
|
// Create a SSR bundle
|
|
@@ -540,7 +562,9 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
540
562
|
entryFileNames: '[name].mjs',
|
|
541
563
|
chunkFileNames: '[name].mjs',
|
|
542
564
|
format: 'es',
|
|
543
|
-
|
|
565
|
+
codeSplitting: {
|
|
566
|
+
groups: createCodeSplittingGroups(ssr)
|
|
567
|
+
}
|
|
544
568
|
}
|
|
545
569
|
};
|
|
546
570
|
// Create a SSR bundle
|
|
@@ -557,7 +581,9 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
557
581
|
entryFileNames: '[name].mjs',
|
|
558
582
|
chunkFileNames: '[name].mjs',
|
|
559
583
|
format: 'es',
|
|
560
|
-
|
|
584
|
+
codeSplitting: {
|
|
585
|
+
groups: createCodeSplittingGroups(ssr)
|
|
586
|
+
}
|
|
561
587
|
}
|
|
562
588
|
};
|
|
563
589
|
}
|
package/package.json
CHANGED
package/src/node/bin/dev.ts
CHANGED
|
@@ -177,7 +177,11 @@ export async function createServer({
|
|
|
177
177
|
: fileURLToPath(new URL(`src/vite/${framework}/ssr/app.ts`, cliDir))
|
|
178
178
|
|
|
179
179
|
const environment = vite.environments.ssr
|
|
180
|
-
;({
|
|
180
|
+
;({
|
|
181
|
+
setup,
|
|
182
|
+
hooks: { onTemplateRendered, onAppRendered },
|
|
183
|
+
vitrifyConfig
|
|
184
|
+
} =
|
|
181
185
|
// @ts-expect-error missing types
|
|
182
186
|
await environment.runner.import(entryUrl))
|
|
183
187
|
|
|
@@ -307,7 +307,9 @@ 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 {
|
|
310
|
+
const {
|
|
311
|
+
hooks: { onTemplateRendered, onAppRendered }
|
|
312
|
+
} = await import(vitrifyHooksPath)
|
|
311
313
|
|
|
312
314
|
return {
|
|
313
315
|
template,
|
package/src/node/index.ts
CHANGED
|
@@ -34,12 +34,12 @@ import type {
|
|
|
34
34
|
import type { VitrifyContext } from './bin/run.js'
|
|
35
35
|
import type { VitrifyPlugin } from './plugins/index.js'
|
|
36
36
|
import { resolve } from './app-urls.js'
|
|
37
|
-
import type { ManualChunksOption, RollupOptions } from 'rollup'
|
|
38
37
|
import { addOrReplaceTitle, appendToBody } from './helpers/utils.js'
|
|
39
38
|
import Components from 'unplugin-vue-components/vite'
|
|
40
39
|
import { VitePWA } from 'vite-plugin-pwa'
|
|
41
40
|
import UnoCSS from 'unocss/vite'
|
|
42
41
|
import { searchForWorkspaceRoot } from 'vite'
|
|
42
|
+
import { CodeSplittingGroup, RolldownOptions } from 'rolldown'
|
|
43
43
|
|
|
44
44
|
const internalServerModules = [
|
|
45
45
|
'util',
|
|
@@ -60,8 +60,8 @@ const internalServerModules = [
|
|
|
60
60
|
const manualChunkNames = [
|
|
61
61
|
'prerender',
|
|
62
62
|
'fastify-ssr-plugin',
|
|
63
|
-
'fastify-csr-plugin'
|
|
64
|
-
'server'
|
|
63
|
+
'fastify-csr-plugin'
|
|
64
|
+
// 'server'
|
|
65
65
|
]
|
|
66
66
|
|
|
67
67
|
const moduleChunks = {
|
|
@@ -83,31 +83,6 @@ const moduleChunks = {
|
|
|
83
83
|
quasar: ['quasar'],
|
|
84
84
|
atQuasar: ['@quasar']
|
|
85
85
|
}
|
|
86
|
-
const manualChunksFn = (manualChunkList?: string[]): ManualChunksOption => {
|
|
87
|
-
return (id: string) => {
|
|
88
|
-
const matchedModule = Object.entries(moduleChunks).find(
|
|
89
|
-
([chunkName, moduleNames]) =>
|
|
90
|
-
moduleNames.some((moduleName) =>
|
|
91
|
-
new RegExp(`\/${moduleName}\/`).test(id)
|
|
92
|
-
)
|
|
93
|
-
)
|
|
94
|
-
if (id.includes('vitrify/src/')) {
|
|
95
|
-
const name = id.split('/').at(-1)?.split('.').at(0)
|
|
96
|
-
if (name && manualChunkNames.includes(name)) return name
|
|
97
|
-
} else if (
|
|
98
|
-
VIRTUAL_MODULES.some((virtualModule) => id.includes(virtualModule))
|
|
99
|
-
) {
|
|
100
|
-
return VIRTUAL_MODULES.find((name) => id.includes(name))
|
|
101
|
-
} else if (manualChunkList?.some((file) => id.includes(file))) {
|
|
102
|
-
return manualChunkList.find((file) => id.includes(file))
|
|
103
|
-
} else if (id.includes('node_modules')) {
|
|
104
|
-
if (matchedModule) {
|
|
105
|
-
return matchedModule[0]
|
|
106
|
-
}
|
|
107
|
-
return 'vendor'
|
|
108
|
-
}
|
|
109
|
-
}
|
|
110
|
-
}
|
|
111
86
|
|
|
112
87
|
export const VIRTUAL_MODULES = [
|
|
113
88
|
'virtual:vitrify-hooks',
|
|
@@ -117,6 +92,44 @@ export const VIRTUAL_MODULES = [
|
|
|
117
92
|
'vitrify.css'
|
|
118
93
|
]
|
|
119
94
|
|
|
95
|
+
/**
|
|
96
|
+
* Advanced chunking may no longer be necessary.
|
|
97
|
+
* @param ssr
|
|
98
|
+
* @returns
|
|
99
|
+
*/
|
|
100
|
+
const createCodeSplittingGroups = (
|
|
101
|
+
ssr?: VitrifySSRModes
|
|
102
|
+
): CodeSplittingGroup[] => {
|
|
103
|
+
return [
|
|
104
|
+
...VIRTUAL_MODULES.map((m) => ({
|
|
105
|
+
name: m,
|
|
106
|
+
test: new RegExp(m),
|
|
107
|
+
priority: 30
|
|
108
|
+
}))
|
|
109
|
+
// ...manualChunkNames.map((m) => ({
|
|
110
|
+
// name: m,
|
|
111
|
+
// test: new RegExp(m),
|
|
112
|
+
// priority: 20
|
|
113
|
+
// })),
|
|
114
|
+
// ...Object.entries(moduleChunks).map(([key, value]) => ({
|
|
115
|
+
// name: key,
|
|
116
|
+
// test: new RegExp(value.join('|')),
|
|
117
|
+
// priority: 20,
|
|
118
|
+
// maxSize: ssr === 'client' || ssr === 'ssg' ? 1000000 : Infinity
|
|
119
|
+
// })),
|
|
120
|
+
// {
|
|
121
|
+
// name: 'vendor',
|
|
122
|
+
// test: /node_modules/,
|
|
123
|
+
// priority: 1
|
|
124
|
+
// },
|
|
125
|
+
// {
|
|
126
|
+
// name: 'typst',
|
|
127
|
+
// test: /\.typ/,
|
|
128
|
+
// priority: 40
|
|
129
|
+
// }
|
|
130
|
+
]
|
|
131
|
+
}
|
|
132
|
+
|
|
120
133
|
export const baseConfig = async ({
|
|
121
134
|
ssr,
|
|
122
135
|
appDir,
|
|
@@ -358,7 +371,7 @@ export const baseConfig = async ({
|
|
|
358
371
|
},
|
|
359
372
|
load(id) {
|
|
360
373
|
if (id === 'virtual:vitrify-hooks') {
|
|
361
|
-
return `
|
|
374
|
+
return `const onAppMounted = [${onAppMountedHooks
|
|
362
375
|
.map((fn) => `${String(fn)}`)
|
|
363
376
|
.join(', ')}]
|
|
364
377
|
${onAppMountedFiles
|
|
@@ -377,7 +390,7 @@ export const baseConfig = async ({
|
|
|
377
390
|
}'; onAppMounted.push(${varName});`
|
|
378
391
|
})
|
|
379
392
|
.join('\n')}
|
|
380
|
-
|
|
393
|
+
const onAppRendered = [${onAppRenderedHooks
|
|
381
394
|
.map((fn) => `${String(fn)}`)
|
|
382
395
|
.join(', ')}]
|
|
383
396
|
${onAppRenderedFiles
|
|
@@ -396,7 +409,7 @@ export const baseConfig = async ({
|
|
|
396
409
|
}'; onAppRendered.push(${varName});`
|
|
397
410
|
})
|
|
398
411
|
.join('\n')}
|
|
399
|
-
|
|
412
|
+
const onTemplateRendered = [${onTemplateRenderedHooks
|
|
400
413
|
.map((fn) => `${String(fn)}`)
|
|
401
414
|
.join(', ')}]
|
|
402
415
|
${onTemplateRenderedFiles
|
|
@@ -415,7 +428,7 @@ export const baseConfig = async ({
|
|
|
415
428
|
}'; onTemplateRendered.push(${varName});`
|
|
416
429
|
})
|
|
417
430
|
.join('\n')}
|
|
418
|
-
|
|
431
|
+
const onAppCreated = [${OnAppCreatedHooks.map(
|
|
419
432
|
(fn) => `${String(fn)}`
|
|
420
433
|
).join(', ')}]
|
|
421
434
|
${onAppCreatedFiles
|
|
@@ -434,7 +447,7 @@ export const baseConfig = async ({
|
|
|
434
447
|
}'; onAppCreated.push(${varName});`
|
|
435
448
|
})
|
|
436
449
|
.join('\n')}
|
|
437
|
-
|
|
450
|
+
const onSetup = []
|
|
438
451
|
${onSetupFiles
|
|
439
452
|
.map((url, index) => {
|
|
440
453
|
const varName = fileURLToPath(url)
|
|
@@ -450,7 +463,14 @@ export const baseConfig = async ({
|
|
|
450
463
|
new URL(url, appDir).href
|
|
451
464
|
}'; onSetup.push(${varName});`
|
|
452
465
|
})
|
|
453
|
-
.join('\n')}
|
|
466
|
+
.join('\n')}
|
|
467
|
+
export const hooks = {
|
|
468
|
+
onAppMounted,
|
|
469
|
+
onAppRendered,
|
|
470
|
+
onAppCreated,
|
|
471
|
+
onTemplateRendered,
|
|
472
|
+
onSetup
|
|
473
|
+
}`
|
|
454
474
|
} else if (id === 'virtual:static-imports') {
|
|
455
475
|
return `${Object.entries(staticImports)
|
|
456
476
|
.map(([key, value]) => {
|
|
@@ -623,7 +643,7 @@ export const baseConfig = async ({
|
|
|
623
643
|
replacement: fileURLToPath(new URL(await resolve('vitest', cliDir)))
|
|
624
644
|
})
|
|
625
645
|
|
|
626
|
-
let rollupOptions:
|
|
646
|
+
let rollupOptions: RolldownOptions = {}
|
|
627
647
|
let noExternal: RegExp[] | string[] = [
|
|
628
648
|
new RegExp(`^(?!(${[...builtinModules, ...serverModules].join('|')}))`)
|
|
629
649
|
]
|
|
@@ -644,7 +664,9 @@ export const baseConfig = async ({
|
|
|
644
664
|
entryFileNames: '[name].mjs',
|
|
645
665
|
chunkFileNames: '[name].mjs',
|
|
646
666
|
format: 'es',
|
|
647
|
-
|
|
667
|
+
codeSplitting: {
|
|
668
|
+
groups: createCodeSplittingGroups(ssr)
|
|
669
|
+
}
|
|
648
670
|
}
|
|
649
671
|
}
|
|
650
672
|
// Create a SSR bundle
|
|
@@ -661,7 +683,9 @@ export const baseConfig = async ({
|
|
|
661
683
|
entryFileNames: '[name].mjs',
|
|
662
684
|
chunkFileNames: '[name].mjs',
|
|
663
685
|
format: 'es',
|
|
664
|
-
|
|
686
|
+
codeSplitting: {
|
|
687
|
+
groups: createCodeSplittingGroups(ssr)
|
|
688
|
+
}
|
|
665
689
|
}
|
|
666
690
|
}
|
|
667
691
|
// Create a SSR bundle
|
|
@@ -677,7 +701,9 @@ export const baseConfig = async ({
|
|
|
677
701
|
entryFileNames: '[name].mjs',
|
|
678
702
|
chunkFileNames: '[name].mjs',
|
|
679
703
|
format: 'es',
|
|
680
|
-
|
|
704
|
+
codeSplitting: {
|
|
705
|
+
groups: createCodeSplittingGroups(ssr)
|
|
706
|
+
}
|
|
681
707
|
}
|
|
682
708
|
}
|
|
683
709
|
}
|
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import type { FastifyInstance } from 'fastify'
|
|
2
|
-
import {
|
|
2
|
+
import { hooks } from 'virtual:vitrify-hooks'
|
|
3
3
|
export { default as vitrifyConfig } from 'virtual:vitrify-config'
|
|
4
4
|
|
|
5
5
|
export const setup = async ({ fastify }: { fastify: FastifyInstance }) => {
|
|
6
|
-
if (onSetup?.length) {
|
|
7
|
-
for (const setup of onSetup) {
|
|
6
|
+
if (hooks.onSetup?.length) {
|
|
7
|
+
for (const setup of hooks.onSetup) {
|
|
8
8
|
await setup(fastify)
|
|
9
9
|
}
|
|
10
10
|
}
|
|
11
11
|
return fastify
|
|
12
12
|
}
|
|
13
|
+
|
|
14
|
+
export { hooks }
|
|
@@ -8,15 +8,17 @@ import {
|
|
|
8
8
|
onMounted as onMountedVue,
|
|
9
9
|
getCurrentInstance
|
|
10
10
|
} from 'vue'
|
|
11
|
-
import {
|
|
11
|
+
import { hooks } from 'virtual:vitrify-hooks'
|
|
12
12
|
import App from 'src/App.vue'
|
|
13
13
|
// import 'vitrify.sass'
|
|
14
14
|
const instance = getCurrentInstance()
|
|
15
15
|
const props = defineProps()
|
|
16
16
|
|
|
17
17
|
onMountedVue(async () => {
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
if (hooks.onAppMounted) {
|
|
19
|
+
for (let fn of hooks.onAppMounted) {
|
|
20
|
+
await fn({ instance })
|
|
21
|
+
}
|
|
20
22
|
}
|
|
21
23
|
})
|
|
22
24
|
|
package/src/vite/vue/csr/app.ts
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createApp } from '../../../node/frameworks/vue/server.js'
|
|
2
2
|
import { getAppDir } from '../../../node/app-urls.js'
|
|
3
3
|
// import { setup } from 'virtual:fastify-setup'
|
|
4
|
-
import {
|
|
4
|
+
import { hooks } from 'virtual:vitrify-hooks'
|
|
5
5
|
import { fastifyCsrPlugin } from './fastify-csr-plugin'
|
|
6
6
|
|
|
7
7
|
// const appDir = getPkgJsonDir(import.meta.url)
|
|
@@ -12,7 +12,7 @@ const appDir = getAppDir()
|
|
|
12
12
|
export const setupApp = async () => {
|
|
13
13
|
// const vitrifyDir = new URL('../', await resolve('vitrify', new URL(import.meta.url)))
|
|
14
14
|
return createApp({
|
|
15
|
-
onSetup,
|
|
15
|
+
onSetup: hooks.onSetup,
|
|
16
16
|
appDir,
|
|
17
17
|
baseUrl,
|
|
18
18
|
fastifyPlugin: fastifyCsrPlugin,
|
package/src/vite/vue/main.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import createRouter from 'src/router'
|
|
2
2
|
import { App, createSSRApp, createApp as createVueApp, ref } from 'vue'
|
|
3
|
-
import {
|
|
3
|
+
import { hooks } from 'virtual:vitrify-hooks'
|
|
4
4
|
import routes from 'src/router/routes'
|
|
5
5
|
import * as staticImports from 'virtual:static-imports'
|
|
6
6
|
import 'virtual:uno.css'
|
|
@@ -69,8 +69,10 @@ export async function createApp(
|
|
|
69
69
|
const router = createRouter()
|
|
70
70
|
app.use(router)
|
|
71
71
|
|
|
72
|
-
|
|
73
|
-
|
|
72
|
+
if (hooks.onAppCreated) {
|
|
73
|
+
for (const fn of hooks.onAppCreated) {
|
|
74
|
+
await fn({ app, router, ctx, initialState, ssrContext, staticImports })
|
|
75
|
+
}
|
|
74
76
|
}
|
|
75
77
|
|
|
76
78
|
// Workaround to fix hydration errors when serving html files directly
|
package/src/vite/vue/ssr/app.ts
CHANGED
|
@@ -1,10 +1,6 @@
|
|
|
1
1
|
import { createApp } from '../../../node/frameworks/vue/server.js'
|
|
2
2
|
import { getAppDir } from '../../../node/app-urls.js'
|
|
3
|
-
import {
|
|
4
|
-
onSetup,
|
|
5
|
-
onAppRendered,
|
|
6
|
-
onTemplateRendered
|
|
7
|
-
} from 'virtual:vitrify-hooks'
|
|
3
|
+
import { hooks } from 'virtual:vitrify-hooks'
|
|
8
4
|
import { fastifySsrPlugin } from './fastify-ssr-plugin.js'
|
|
9
5
|
|
|
10
6
|
const getString = (str?: string) => str
|
|
@@ -13,15 +9,15 @@ const appDir = getAppDir()
|
|
|
13
9
|
|
|
14
10
|
export const setupApp = async () => {
|
|
15
11
|
return createApp({
|
|
16
|
-
onSetup,
|
|
12
|
+
onSetup: hooks.onSetup,
|
|
17
13
|
appDir,
|
|
18
14
|
baseUrl,
|
|
19
15
|
fastifyPlugin: fastifySsrPlugin,
|
|
20
|
-
onAppRendered,
|
|
21
|
-
onTemplateRendered,
|
|
16
|
+
onAppRendered: hooks.onAppRendered,
|
|
17
|
+
onTemplateRendered: hooks.onTemplateRendered,
|
|
22
18
|
mode: import.meta.env.MODE
|
|
23
19
|
})
|
|
24
20
|
}
|
|
25
21
|
|
|
26
22
|
export { default as vitrifyConfig } from 'virtual:vitrify-config'
|
|
27
|
-
export {
|
|
23
|
+
export { hooks }
|