vitrify 0.25.0 → 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/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 +7 -7
- package/dist/plugins/pinia/index.js +5 -5
- 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/vitrify-config.d.ts +7 -4
- 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 +4 -4
- package/src/node/index.ts +9 -9
- package/src/node/plugins/pinia/index.ts +12 -6
- package/src/node/vitrify-config.ts +7 -4
- package/src/vite/vue/ssr/app.ts +7 -3
package/dist/bin/cli.js
CHANGED
|
@@ -74,7 +74,7 @@ cli
|
|
|
74
74
|
outDir: fileURLToPath(new URL('ssr/server/', baseOutDir))
|
|
75
75
|
});
|
|
76
76
|
({ prerender } = await import(new URL('ssr/server/prerender.mjs', baseOutDir).pathname));
|
|
77
|
-
const { template, manifest, render, getRoutes,
|
|
77
|
+
const { template, manifest, render, getRoutes, onAppRendered, onTemplateRendered } = await loadSSRAssets({
|
|
78
78
|
mode: 'ssg',
|
|
79
79
|
distDir: baseOutDir
|
|
80
80
|
});
|
|
@@ -85,7 +85,7 @@ cli
|
|
|
85
85
|
manifest,
|
|
86
86
|
render,
|
|
87
87
|
routes,
|
|
88
|
-
|
|
88
|
+
onAppRendered,
|
|
89
89
|
onTemplateRendered
|
|
90
90
|
});
|
|
91
91
|
break;
|
package/dist/bin/dev.js
CHANGED
|
@@ -76,6 +76,7 @@ ssr, framework = 'vue', host, appDir, publicDir, vite }) {
|
|
|
76
76
|
let app;
|
|
77
77
|
let server;
|
|
78
78
|
let onTemplateRendered;
|
|
79
|
+
let onAppRendered;
|
|
79
80
|
let vitrifyConfig;
|
|
80
81
|
console.log(`Development mode: ${ssr ? ssr : 'csr'}`);
|
|
81
82
|
if (ssr) {
|
|
@@ -83,11 +84,9 @@ ssr, framework = 'vue', host, appDir, publicDir, vite }) {
|
|
|
83
84
|
? fileURLToPath(new URL('src/vite/fastify/entry.ts', cliDir))
|
|
84
85
|
: fileURLToPath(new URL(`src/vite/${framework}/ssr/app.ts`, cliDir));
|
|
85
86
|
const environment = vite.environments.ssr;
|
|
86
|
-
({ setup, onTemplateRendered, vitrifyConfig } =
|
|
87
|
+
({ setup, onTemplateRendered, onAppRendered, vitrifyConfig } =
|
|
87
88
|
// @ts-expect-error missing types
|
|
88
89
|
await environment.runner.import(entryUrl));
|
|
89
|
-
// console.log(module)
|
|
90
|
-
// ;({ setup, onRendered, vitrifyConfig } = await vite.ssrLoadModule(entryUrl))
|
|
91
90
|
app = fastify({
|
|
92
91
|
logger: {
|
|
93
92
|
transport: {
|
|
@@ -113,6 +112,7 @@ ssr, framework = 'vue', host, appDir, publicDir, vite }) {
|
|
|
113
112
|
appDir,
|
|
114
113
|
mode: 'development',
|
|
115
114
|
onTemplateRendered,
|
|
115
|
+
onAppRendered,
|
|
116
116
|
host
|
|
117
117
|
});
|
|
118
118
|
}
|
|
@@ -55,7 +55,7 @@ const fastifySsrPlugin = async (fastify, options) => {
|
|
|
55
55
|
res,
|
|
56
56
|
url: url ?? '/',
|
|
57
57
|
provide,
|
|
58
|
-
|
|
58
|
+
onAppRendered: options.onAppRendered,
|
|
59
59
|
onTemplateRendered: options.onTemplateRendered,
|
|
60
60
|
template,
|
|
61
61
|
manifest,
|
|
@@ -87,7 +87,7 @@ const fastifySsrPlugin = async (fastify, options) => {
|
|
|
87
87
|
fastify.get(`${options.baseUrl}*`, async (req, res) => {
|
|
88
88
|
const url = req.raw.url?.replace(options.baseUrl, '/');
|
|
89
89
|
const provide = options.provide ? await options.provide(req, res) : {};
|
|
90
|
-
const { template, manifest, render,
|
|
90
|
+
const { template, manifest, render, onAppRendered, onTemplateRendered } = await loadSSRAssets({
|
|
91
91
|
distDir: new URL('./dist/', options.appDir)
|
|
92
92
|
});
|
|
93
93
|
const html = await renderHtml({
|
|
@@ -95,7 +95,7 @@ const fastifySsrPlugin = async (fastify, options) => {
|
|
|
95
95
|
res,
|
|
96
96
|
url: url ?? '/',
|
|
97
97
|
provide,
|
|
98
|
-
|
|
98
|
+
onAppRendered,
|
|
99
99
|
onTemplateRendered,
|
|
100
100
|
template,
|
|
101
101
|
manifest,
|
|
@@ -111,7 +111,7 @@ const renderTemplate = ({ template, initialStateScript, appHtml, preloadLinks })
|
|
|
111
111
|
return appendToHead(preloadLinks, appendToBody(initialStateScript, addOrReplaceAppDiv(appHtml, template)));
|
|
112
112
|
};
|
|
113
113
|
const renderHtml = async (options) => {
|
|
114
|
-
const
|
|
114
|
+
const ssrContextonAppRendered = [];
|
|
115
115
|
const ssrContext = {
|
|
116
116
|
req: options.req,
|
|
117
117
|
res: options.res,
|
|
@@ -120,21 +120,21 @@ const renderHtml = async (options) => {
|
|
|
120
120
|
_modules: new Set(),
|
|
121
121
|
_meta: {},
|
|
122
122
|
__qMetaList: [],
|
|
123
|
-
onRenderedList:
|
|
123
|
+
onRenderedList: ssrContextonAppRendered,
|
|
124
124
|
onRendered: (fn) => {
|
|
125
|
-
|
|
125
|
+
ssrContextonAppRendered.push(fn);
|
|
126
126
|
}
|
|
127
127
|
};
|
|
128
|
-
const
|
|
128
|
+
const onAppRendered = options.onAppRendered ?? [];
|
|
129
129
|
const onTemplateRendered = options.onTemplateRendered ?? [];
|
|
130
130
|
const { html: appHtml, preloadLinks, app } = await options.render(options.url, options.manifest, ssrContext);
|
|
131
|
-
if (
|
|
132
|
-
for (const ssrFunction of
|
|
131
|
+
if (ssrContextonAppRendered?.length) {
|
|
132
|
+
for (const ssrFunction of ssrContextonAppRendered) {
|
|
133
133
|
await ssrFunction();
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
|
-
if (
|
|
137
|
-
for (const ssrFunction of
|
|
136
|
+
if (onAppRendered?.length) {
|
|
137
|
+
for (const ssrFunction of onAppRendered) {
|
|
138
138
|
await ssrFunction({ app, ssrContext });
|
|
139
139
|
}
|
|
140
140
|
}
|
|
@@ -191,13 +191,13 @@ 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,
|
|
194
|
+
const { onTemplateRendered, onAppRendered } = await import(vitrifyHooksPath);
|
|
195
195
|
return {
|
|
196
196
|
template,
|
|
197
197
|
manifest,
|
|
198
198
|
render,
|
|
199
199
|
getRoutes,
|
|
200
|
-
|
|
200
|
+
onAppRendered,
|
|
201
201
|
onTemplateRendered
|
|
202
202
|
};
|
|
203
203
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fastify from 'fastify';
|
|
2
|
-
export const createApp = ({ onSetup, appDir, baseUrl, fastifyPlugin,
|
|
2
|
+
export const createApp = ({ onSetup, appDir, baseUrl, fastifyPlugin, onAppRendered, onTemplateRendered, vitrifyDir, mode }) => {
|
|
3
3
|
const app = fastify({
|
|
4
4
|
logger: {
|
|
5
5
|
transport: {
|
|
@@ -12,7 +12,7 @@ export const createApp = ({ onSetup, appDir, baseUrl, fastifyPlugin, onRendered,
|
|
|
12
12
|
baseUrl,
|
|
13
13
|
appDir,
|
|
14
14
|
vitrifyDir,
|
|
15
|
-
|
|
15
|
+
onAppRendered,
|
|
16
16
|
onTemplateRendered,
|
|
17
17
|
mode
|
|
18
18
|
});
|
package/dist/index.js
CHANGED
|
@@ -207,8 +207,8 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
|
-
let
|
|
211
|
-
let
|
|
210
|
+
let onAppRenderedHooks;
|
|
211
|
+
let onAppRenderedFiles;
|
|
212
212
|
let onTemplateRenderedHooks;
|
|
213
213
|
let onTemplateRenderedFiles;
|
|
214
214
|
let onAppMountedHooks;
|
|
@@ -273,8 +273,8 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
273
273
|
name: 'vitrify-setup',
|
|
274
274
|
enforce: 'post',
|
|
275
275
|
config: (config, env) => {
|
|
276
|
-
|
|
277
|
-
|
|
276
|
+
onAppRenderedHooks = config.vitrify?.hooks?.onAppRendered || [];
|
|
277
|
+
onAppRenderedFiles = config.vitrify?.hooks?.onAppRenderedFiles || [];
|
|
278
278
|
onTemplateRenderedHooks =
|
|
279
279
|
config.vitrify?.hooks?.onTemplateRendered || [];
|
|
280
280
|
onTemplateRenderedFiles =
|
|
@@ -329,10 +329,10 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
329
329
|
return `import ${varName} from '${new URL(url, appDir).pathname}'; onAppMounted.push(${varName});`;
|
|
330
330
|
})
|
|
331
331
|
.join('\n')}
|
|
332
|
-
export const
|
|
332
|
+
export const onAppRendered = [${onAppRenderedHooks
|
|
333
333
|
.map((fn) => `${String(fn)}`)
|
|
334
334
|
.join(', ')}]
|
|
335
|
-
${
|
|
335
|
+
${onAppRenderedFiles
|
|
336
336
|
.map((url, index) => {
|
|
337
337
|
const varName = fileURLToPath(url)
|
|
338
338
|
.replaceAll('/', '')
|
|
@@ -342,7 +342,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
342
342
|
.replaceAll('-', '')
|
|
343
343
|
.replaceAll('_', '')
|
|
344
344
|
.replaceAll('+', '');
|
|
345
|
-
return `import ${varName} from '${new URL(url, appDir).pathname}';
|
|
345
|
+
return `import ${varName} from '${new URL(url, appDir).pathname}'; onAppRendered.push(${varName});`;
|
|
346
346
|
})
|
|
347
347
|
.join('\n')}
|
|
348
348
|
export const onTemplateRendered = [${onTemplateRenderedHooks
|
|
@@ -10,7 +10,7 @@ const piniaOnAppCreated = async ({ app, ctx, initialState, ssrContext }) => {
|
|
|
10
10
|
if (ssrContext)
|
|
11
11
|
ssrContext.pinia = pinia;
|
|
12
12
|
};
|
|
13
|
-
const
|
|
13
|
+
const piniaonAppRenderedHook = async ({ app, ssrContext }) => {
|
|
14
14
|
// SSR Server
|
|
15
15
|
if (ssrContext?.initialState && ssrContext.pinia) {
|
|
16
16
|
ssrContext.initialState.pinia = ssrContext.pinia.state.value;
|
|
@@ -25,7 +25,7 @@ const piniaColadaonAppCreated = async ({ app, ctx, initialState }) => {
|
|
|
25
25
|
}
|
|
26
26
|
}
|
|
27
27
|
};
|
|
28
|
-
const
|
|
28
|
+
const piniaColadaonAppRenderedHook = async ({ app, ssrContext }) => {
|
|
29
29
|
// SSR Server
|
|
30
30
|
if (ssrContext?.initialState && ssrContext.pinia) {
|
|
31
31
|
const { useQueryCache, serializeQueryCache } = await import('@pinia/colada');
|
|
@@ -38,10 +38,10 @@ const piniaColadaOnRenderedHook = async ({ app, ssrContext }) => {
|
|
|
38
38
|
};
|
|
39
39
|
export const PiniaPlugin = async ({ ssr = false, pwa = false, options = {} }) => {
|
|
40
40
|
const onAppCreated = [piniaOnAppCreated];
|
|
41
|
-
const
|
|
41
|
+
const onAppRendered = [piniaonAppRenderedHook];
|
|
42
42
|
if (options.colada) {
|
|
43
43
|
onAppCreated.push(piniaColadaonAppCreated);
|
|
44
|
-
|
|
44
|
+
onAppRendered.push(piniaColadaonAppRenderedHook);
|
|
45
45
|
}
|
|
46
46
|
return {
|
|
47
47
|
plugins: [],
|
|
@@ -49,7 +49,7 @@ export const PiniaPlugin = async ({ ssr = false, pwa = false, options = {} }) =>
|
|
|
49
49
|
vitrify: {
|
|
50
50
|
hooks: {
|
|
51
51
|
onAppCreated,
|
|
52
|
-
|
|
52
|
+
onAppRendered
|
|
53
53
|
}
|
|
54
54
|
}
|
|
55
55
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { FastifyPluginAsync, FastifyRequest, FastifyReply } from 'fastify';
|
|
2
2
|
import type { ViteDevServer } from 'vite';
|
|
3
|
-
import type {
|
|
3
|
+
import type { OnAppRenderedHook, OnTemplateRenderedHook } from '../../vitrify-config.js';
|
|
4
4
|
type ProvideFn = (req: FastifyRequest, res: FastifyReply) => Promise<Record<string, unknown | {
|
|
5
5
|
value: unknown;
|
|
6
6
|
}>>;
|
|
@@ -9,7 +9,7 @@ export interface FastifySsrOptions {
|
|
|
9
9
|
provide?: ProvideFn;
|
|
10
10
|
vitrifyDir?: URL;
|
|
11
11
|
vite?: ViteDevServer;
|
|
12
|
-
|
|
12
|
+
onAppRendered?: OnAppRenderedHook[];
|
|
13
13
|
onTemplateRendered?: OnTemplateRenderedHook[];
|
|
14
14
|
appDir?: URL;
|
|
15
15
|
publicDir?: URL;
|
|
@@ -25,7 +25,7 @@ declare const renderHtml: (options: {
|
|
|
25
25
|
};
|
|
26
26
|
res: FastifyReply | Record<string, unknown>;
|
|
27
27
|
provide: Record<string, unknown>;
|
|
28
|
-
|
|
28
|
+
onAppRendered?: OnAppRenderedHook[];
|
|
29
29
|
onTemplateRendered?: OnTemplateRenderedHook[];
|
|
30
30
|
template: string;
|
|
31
31
|
manifest: Record<string, unknown>;
|
|
@@ -39,7 +39,7 @@ declare const loadSSRAssets: ({ mode, distDir }?: {
|
|
|
39
39
|
manifest: any;
|
|
40
40
|
render: any;
|
|
41
41
|
getRoutes: any;
|
|
42
|
-
|
|
42
|
+
onAppRendered: any;
|
|
43
43
|
onTemplateRendered: any;
|
|
44
44
|
}>;
|
|
45
45
|
export { fastifySsrPlugin, renderHtml, loadSSRAssets };
|
|
@@ -1,12 +1,12 @@
|
|
|
1
|
-
import type { OnTemplateRenderedHook, OnSetupHook,
|
|
1
|
+
import type { OnTemplateRenderedHook, OnSetupHook, OnAppRenderedHook } from '../../vitrify-config.js';
|
|
2
2
|
import type { FastifyCsrPlugin } from './fastify-csr-plugin.js';
|
|
3
3
|
import type { FastifySsrPlugin } from './fastify-ssr-plugin.js';
|
|
4
|
-
export declare const createApp: ({ onSetup, appDir, baseUrl, fastifyPlugin,
|
|
4
|
+
export declare const createApp: ({ onSetup, appDir, baseUrl, fastifyPlugin, onAppRendered, onTemplateRendered, vitrifyDir, mode }: {
|
|
5
5
|
onSetup: OnSetupHook[];
|
|
6
6
|
appDir: URL;
|
|
7
7
|
baseUrl?: string;
|
|
8
8
|
fastifyPlugin: FastifySsrPlugin | FastifyCsrPlugin;
|
|
9
|
-
|
|
9
|
+
onAppRendered?: OnAppRenderedHook[];
|
|
10
10
|
onTemplateRendered?: OnTemplateRenderedHook[];
|
|
11
11
|
vitrifyDir?: URL;
|
|
12
12
|
mode: string;
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type { OnAppCreatedHook, OnAppCreatedHookFile, OnAppMountedHook, OnAppMountedHookFile,
|
|
2
|
-
export { OnAppCreatedHook, OnAppCreatedHookFile, OnAppMountedHook, OnAppMountedHookFile,
|
|
1
|
+
import type { OnAppCreatedHook, OnAppCreatedHookFile, OnAppMountedHook, OnAppMountedHookFile, OnAppRenderedHook, OnAppRenderedHookFile, OnTemplateRenderedHook, OnTemplateRenderedHookFile, OnSetupHookFile, OnSetupHook } from '../vitrify-config.js';
|
|
2
|
+
export { OnAppCreatedHook, OnAppCreatedHookFile, OnAppMountedHook, OnAppMountedHookFile, OnAppRenderedHook, OnAppRenderedHookFile, OnTemplateRenderedHook, OnTemplateRenderedHookFile, OnSetupHookFile, OnSetupHook };
|
|
@@ -69,8 +69,8 @@ export type Render = (url: string, manifest: Record<string, unknown>, ssrContext
|
|
|
69
69
|
preloadLinks: string;
|
|
70
70
|
app: App;
|
|
71
71
|
}>;
|
|
72
|
-
export type
|
|
73
|
-
export type
|
|
72
|
+
export type OnAppRenderedHookFile = URL;
|
|
73
|
+
export type OnAppRenderedHook = ({ app, ssrContext }: {
|
|
74
74
|
app: App;
|
|
75
75
|
ssrContext?: SSRContext;
|
|
76
76
|
}) => Promise<void> | void;
|
|
@@ -118,11 +118,11 @@ export interface VitrifyConfig extends ViteUserConfig {
|
|
|
118
118
|
/**
|
|
119
119
|
* Functions which run after rendering the app (SSR)
|
|
120
120
|
*/
|
|
121
|
-
|
|
121
|
+
onAppRendered?: OnAppRenderedHook[];
|
|
122
122
|
/**
|
|
123
123
|
* Files with functions which run after rendering the app (SSR)
|
|
124
124
|
*/
|
|
125
|
-
|
|
125
|
+
onAppRenderedFiles?: OnAppRenderedHookFile[];
|
|
126
126
|
/**
|
|
127
127
|
* Functions which run after rendering the template (SSR)
|
|
128
128
|
*/
|
|
@@ -157,6 +157,9 @@ export interface VitrifyConfig extends ViteUserConfig {
|
|
|
157
157
|
* SSR specific configuration
|
|
158
158
|
*/
|
|
159
159
|
ssr?: {
|
|
160
|
+
/**
|
|
161
|
+
* Packages which should not be bundled but installed on the server instead.
|
|
162
|
+
*/
|
|
160
163
|
serverModules?: string[];
|
|
161
164
|
fastify?: FastifyServerOptions;
|
|
162
165
|
};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitrify",
|
|
3
|
-
"version": "0.25.
|
|
3
|
+
"version": "0.25.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Stefan van Herwijnen",
|
|
6
6
|
"description": "Vite as your Full Stack development tool",
|
|
@@ -55,10 +55,10 @@
|
|
|
55
55
|
"@fastify/middie": "^9.0.3",
|
|
56
56
|
"@fastify/one-line-logger": "^2.0.2",
|
|
57
57
|
"@fastify/static": "^8.2.0",
|
|
58
|
-
"@unocss/core": "^66.
|
|
59
|
-
"@unocss/preset-uno": "^66.
|
|
60
|
-
"@unocss/preset-web-fonts": "66.
|
|
61
|
-
"@unocss/preset-wind": "^66.
|
|
58
|
+
"@unocss/core": "^66.2.3",
|
|
59
|
+
"@unocss/preset-uno": "^66.2.3",
|
|
60
|
+
"@unocss/preset-web-fonts": "66.2.3",
|
|
61
|
+
"@unocss/preset-wind": "^66.2.3",
|
|
62
62
|
"@vitejs/plugin-vue": "^5.2.4",
|
|
63
63
|
"ajv": "^8.17.1",
|
|
64
64
|
"animated-unocss": "^0.0.6",
|
|
@@ -67,54 +67,54 @@
|
|
|
67
67
|
"cross-env": "^7.0.3",
|
|
68
68
|
"devalue": "^5.1.1",
|
|
69
69
|
"esbuild": "^0.25.5",
|
|
70
|
-
"fastify": "^5.
|
|
71
|
-
"glob": "^11.0.
|
|
72
|
-
"happy-dom": "^
|
|
70
|
+
"fastify": "^5.4.0",
|
|
71
|
+
"glob": "^11.0.3",
|
|
72
|
+
"happy-dom": "^18.0.1",
|
|
73
73
|
"is-port-reachable": "^4.0.0",
|
|
74
74
|
"magic-string": "^0.30.17",
|
|
75
75
|
"merge-deep": "^3.0.3",
|
|
76
76
|
"readline": "^1.3.0",
|
|
77
|
-
"rollup-plugin-visualizer": "^6.0.
|
|
78
|
-
"sass": "1.89.
|
|
77
|
+
"rollup-plugin-visualizer": "^6.0.3",
|
|
78
|
+
"sass": "1.89.2",
|
|
79
79
|
"stringify-object": "^5.0.0",
|
|
80
80
|
"ts-node": "^10.9.2",
|
|
81
|
-
"unocss": "^66.
|
|
81
|
+
"unocss": "^66.2.3",
|
|
82
82
|
"unplugin-vue-components": "^28.7.0",
|
|
83
83
|
"vite": "^6.3.5",
|
|
84
84
|
"vite-plugin-pwa": "^1.0.0",
|
|
85
85
|
"vitefu": "^1.0.6",
|
|
86
|
-
"vitest": "^3.2.
|
|
86
|
+
"vitest": "^3.2.4",
|
|
87
87
|
"workbox-window": "^7.3.0"
|
|
88
88
|
},
|
|
89
89
|
"devDependencies": {
|
|
90
90
|
"@iconify-json/mdi": "^1.2.3",
|
|
91
|
-
"@pinia/colada": "^0.
|
|
91
|
+
"@pinia/colada": "^0.17.1",
|
|
92
92
|
"@quasar/extras": "^1.17.0",
|
|
93
93
|
"@quasar/quasar-ui-qmarkdown": "^2.0.5",
|
|
94
94
|
"@quasar/quasar-ui-qmediaplayer": "^2.0.0-beta.0",
|
|
95
95
|
"@types/connect": "^3.4.38",
|
|
96
96
|
"@types/glob": "^8.1.0",
|
|
97
97
|
"@types/merge-deep": "^3.0.3",
|
|
98
|
-
"@types/node": "^
|
|
98
|
+
"@types/node": "^24.0.3",
|
|
99
99
|
"@types/stringify-object": "^4.0.5",
|
|
100
100
|
"@types/ws": "^8.18.1",
|
|
101
|
-
"@unocss/preset-icons": "^66.
|
|
101
|
+
"@unocss/preset-icons": "^66.2.3",
|
|
102
102
|
"@vue/runtime-core": "^3.5.16",
|
|
103
103
|
"beasties": "^0.3.4",
|
|
104
104
|
"css": "^3.0.0",
|
|
105
105
|
"css-to-tailwind-translator": "^1.2.8",
|
|
106
|
-
"pinia": "^3.0.
|
|
106
|
+
"pinia": "^3.0.3",
|
|
107
107
|
"quasar": "^2.18.1",
|
|
108
|
-
"rollup": "^4.
|
|
108
|
+
"rollup": "^4.43.0",
|
|
109
109
|
"typescript": "^5.8.3",
|
|
110
110
|
"vue": "^3.5.16",
|
|
111
111
|
"vue-router": "^4.5.1"
|
|
112
112
|
},
|
|
113
113
|
"peerDependencies": {
|
|
114
114
|
"@fastify/static": "^8.2.0",
|
|
115
|
-
"@pinia/colada": "^0.
|
|
116
|
-
"fastify": "^5.
|
|
117
|
-
"pinia": "^3.0.
|
|
115
|
+
"@pinia/colada": "^0.17.1",
|
|
116
|
+
"fastify": "^5.4.0",
|
|
117
|
+
"pinia": "^3.0.3",
|
|
118
118
|
"quasar": "^2.18.1",
|
|
119
119
|
"vue": "^3.5.16",
|
|
120
120
|
"vue-router": "^4.5.1"
|
package/src/node/bin/cli.ts
CHANGED
|
@@ -94,7 +94,7 @@ cli
|
|
|
94
94
|
manifest,
|
|
95
95
|
render,
|
|
96
96
|
getRoutes,
|
|
97
|
-
|
|
97
|
+
onAppRendered,
|
|
98
98
|
onTemplateRendered
|
|
99
99
|
} = await loadSSRAssets({
|
|
100
100
|
mode: 'ssg',
|
|
@@ -108,7 +108,7 @@ cli
|
|
|
108
108
|
manifest,
|
|
109
109
|
render,
|
|
110
110
|
routes,
|
|
111
|
-
|
|
111
|
+
onAppRendered,
|
|
112
112
|
onTemplateRendered
|
|
113
113
|
})
|
|
114
114
|
break
|
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
|
@@ -3,8 +3,8 @@ import type {
|
|
|
3
3
|
OnAppCreatedHookFile,
|
|
4
4
|
OnAppMountedHook,
|
|
5
5
|
OnAppMountedHookFile,
|
|
6
|
-
|
|
7
|
-
|
|
6
|
+
OnAppRenderedHook,
|
|
7
|
+
OnAppRenderedHookFile,
|
|
8
8
|
OnTemplateRenderedHook,
|
|
9
9
|
OnTemplateRenderedHookFile,
|
|
10
10
|
OnSetupHookFile,
|
|
@@ -16,8 +16,8 @@ export {
|
|
|
16
16
|
OnAppCreatedHookFile,
|
|
17
17
|
OnAppMountedHook,
|
|
18
18
|
OnAppMountedHookFile,
|
|
19
|
-
|
|
20
|
-
|
|
19
|
+
OnAppRenderedHook,
|
|
20
|
+
OnAppRenderedHookFile,
|
|
21
21
|
OnTemplateRenderedHook,
|
|
22
22
|
OnTemplateRenderedHookFile,
|
|
23
23
|
OnSetupHookFile,
|
package/src/node/index.ts
CHANGED
|
@@ -24,12 +24,12 @@ import type {
|
|
|
24
24
|
VitrifyModes,
|
|
25
25
|
VitrifyUIFrameworks,
|
|
26
26
|
VitrifySSRModes,
|
|
27
|
-
|
|
27
|
+
OnAppRenderedHook,
|
|
28
28
|
OnSetupHookFile,
|
|
29
29
|
OnAppCreatedHook,
|
|
30
30
|
OnTemplateRenderedHook,
|
|
31
31
|
OnAppCreatedHookFile,
|
|
32
|
-
|
|
32
|
+
OnAppRenderedHookFile,
|
|
33
33
|
OnTemplateRenderedHookFile,
|
|
34
34
|
OnAppMountedHookFile
|
|
35
35
|
} from './vitrify-config.js'
|
|
@@ -281,8 +281,8 @@ export const baseConfig = async ({
|
|
|
281
281
|
}
|
|
282
282
|
}
|
|
283
283
|
|
|
284
|
-
let
|
|
285
|
-
let
|
|
284
|
+
let onAppRenderedHooks: OnAppRenderedHook[]
|
|
285
|
+
let onAppRenderedFiles: OnAppRenderedHookFile[]
|
|
286
286
|
let onTemplateRenderedHooks: OnTemplateRenderedHook[]
|
|
287
287
|
let onTemplateRenderedFiles: OnTemplateRenderedHookFile[]
|
|
288
288
|
let onAppMountedHooks: OnAppMountedHook[]
|
|
@@ -364,8 +364,8 @@ export const baseConfig = async ({
|
|
|
364
364
|
name: 'vitrify-setup',
|
|
365
365
|
enforce: 'post',
|
|
366
366
|
config: (config: VitrifyConfig, env) => {
|
|
367
|
-
|
|
368
|
-
|
|
367
|
+
onAppRenderedHooks = config.vitrify?.hooks?.onAppRendered || []
|
|
368
|
+
onAppRenderedFiles = config.vitrify?.hooks?.onAppRenderedFiles || []
|
|
369
369
|
onTemplateRenderedHooks =
|
|
370
370
|
config.vitrify?.hooks?.onTemplateRendered || []
|
|
371
371
|
onTemplateRenderedFiles =
|
|
@@ -421,10 +421,10 @@ export const baseConfig = async ({
|
|
|
421
421
|
}'; onAppMounted.push(${varName});`
|
|
422
422
|
})
|
|
423
423
|
.join('\n')}
|
|
424
|
-
export const
|
|
424
|
+
export const onAppRendered = [${onAppRenderedHooks
|
|
425
425
|
.map((fn) => `${String(fn)}`)
|
|
426
426
|
.join(', ')}]
|
|
427
|
-
${
|
|
427
|
+
${onAppRenderedFiles
|
|
428
428
|
.map((url, index) => {
|
|
429
429
|
const varName = fileURLToPath(url)
|
|
430
430
|
.replaceAll('/', '')
|
|
@@ -437,7 +437,7 @@ export const baseConfig = async ({
|
|
|
437
437
|
|
|
438
438
|
return `import ${varName} from '${
|
|
439
439
|
new URL(url, appDir).pathname
|
|
440
|
-
}';
|
|
440
|
+
}'; onAppRendered.push(${varName});`
|
|
441
441
|
})
|
|
442
442
|
.join('\n')}
|
|
443
443
|
export const onTemplateRendered = [${onTemplateRenderedHooks
|
|
@@ -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 = {
|
|
@@ -23,7 +26,10 @@ 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
|
|
@@ -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
|
}
|
|
@@ -101,8 +101,8 @@ export type Render = (
|
|
|
101
101
|
app: App
|
|
102
102
|
}>
|
|
103
103
|
|
|
104
|
-
export type
|
|
105
|
-
export type
|
|
104
|
+
export type OnAppRenderedHookFile = URL
|
|
105
|
+
export type OnAppRenderedHook = ({
|
|
106
106
|
app,
|
|
107
107
|
ssrContext
|
|
108
108
|
}: {
|
|
@@ -158,11 +158,11 @@ export interface VitrifyConfig extends ViteUserConfig {
|
|
|
158
158
|
/**
|
|
159
159
|
* Functions which run after rendering the app (SSR)
|
|
160
160
|
*/
|
|
161
|
-
|
|
161
|
+
onAppRendered?: OnAppRenderedHook[]
|
|
162
162
|
/**
|
|
163
163
|
* Files with functions which run after rendering the app (SSR)
|
|
164
164
|
*/
|
|
165
|
-
|
|
165
|
+
onAppRenderedFiles?: OnAppRenderedHookFile[]
|
|
166
166
|
/**
|
|
167
167
|
* Functions which run after rendering the template (SSR)
|
|
168
168
|
*/
|
|
@@ -197,6 +197,9 @@ export interface VitrifyConfig extends ViteUserConfig {
|
|
|
197
197
|
* SSR specific configuration
|
|
198
198
|
*/
|
|
199
199
|
ssr?: {
|
|
200
|
+
/**
|
|
201
|
+
* Packages which should not be bundled but installed on the server instead.
|
|
202
|
+
*/
|
|
200
203
|
serverModules?: string[]
|
|
201
204
|
fastify?: FastifyServerOptions
|
|
202
205
|
}
|
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 }
|