vitrify 0.20.0 → 0.21.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/app-urls.js +1 -1
- package/dist/bin/cli.js +11 -4
- package/dist/frameworks/vue/fastify-ssr-plugin.js +41 -5
- package/dist/frameworks/vue/prerender.js +1 -5
- package/dist/index.js +3 -2
- package/dist/types/app-urls.d.ts +1 -1
- package/dist/types/frameworks/vue/fastify-ssr-plugin.d.ts +11 -1
- package/dist/types/frameworks/vue/prerender.d.ts +6 -4
- package/package.json +16 -16
- package/src/node/app-urls.ts +2 -2
- package/src/node/bin/cli.ts +13 -6
- package/src/node/frameworks/vue/fastify-ssr-plugin.ts +60 -26
- package/src/node/frameworks/vue/prerender.ts +9 -10
- package/src/node/index.ts +5 -2
- package/src/vite/vue/ssr/fastify-ssr-plugin.ts +3 -2
package/dist/app-urls.js
CHANGED
|
@@ -17,7 +17,7 @@ export const getPkgJsonDir = (dir) => {
|
|
|
17
17
|
}
|
|
18
18
|
return getPkgJsonDir(new URL('..', dir));
|
|
19
19
|
};
|
|
20
|
-
export const getAppDir = () => getPkgJsonDir(new URL(`file://${process.cwd()}/`));
|
|
20
|
+
export const getAppDir = (dir) => getPkgJsonDir(dir ?? new URL(`file://${process.cwd()}/`));
|
|
21
21
|
export const getCliDir = () => getPkgJsonDir(new URL('./', import.meta.url));
|
|
22
22
|
export const getCliViteDir = (cliDir) => new URL('src/vite/', cliDir);
|
|
23
23
|
export const getSrcDir = (appDir) => new URL('src/', appDir);
|
package/dist/bin/cli.js
CHANGED
|
@@ -5,6 +5,7 @@ import { getAppDir, parsePath } from '../app-urls.js';
|
|
|
5
5
|
import { printHttpServerUrls, exitLogs } from '../helpers/logger.js';
|
|
6
6
|
import { build as esbuild } from 'esbuild';
|
|
7
7
|
import { readdir } from 'fs/promises';
|
|
8
|
+
import { loadSSRAssets } from '../frameworks/vue/fastify-ssr-plugin.js';
|
|
8
9
|
const cli = cac('vitrify');
|
|
9
10
|
cli
|
|
10
11
|
.command('build')
|
|
@@ -73,12 +74,18 @@ cli
|
|
|
73
74
|
...args,
|
|
74
75
|
outDir: fileURLToPath(new URL('ssr/server/', baseOutDir))
|
|
75
76
|
});
|
|
76
|
-
({ prerender
|
|
77
|
+
({ prerender } = await import(new URL('ssr/server/prerender.mjs', baseOutDir).pathname));
|
|
78
|
+
const { template, manifest, render, getRoutes, onRendered } = await loadSSRAssets({
|
|
79
|
+
mode: 'ssg',
|
|
80
|
+
distDir: baseOutDir
|
|
81
|
+
});
|
|
82
|
+
const routes = await getRoutes();
|
|
77
83
|
prerender({
|
|
78
84
|
outDir: fileURLToPath(new URL('static/', baseOutDir)),
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
85
|
+
template,
|
|
86
|
+
manifest,
|
|
87
|
+
render,
|
|
88
|
+
routes,
|
|
82
89
|
onRendered
|
|
83
90
|
});
|
|
84
91
|
break;
|
|
@@ -2,6 +2,7 @@ import fastifyStatic from '@fastify/static';
|
|
|
2
2
|
import { readFileSync } from 'fs';
|
|
3
3
|
import { fileURLToPath } from 'url';
|
|
4
4
|
import { addOrReplaceAppDiv, appendToBody, appendToHead } from '../../helpers/utils.js';
|
|
5
|
+
import { getAppDir } from '../../app-urls.js';
|
|
5
6
|
const fastifySsrPlugin = async (fastify, options) => {
|
|
6
7
|
options.baseUrl = options.baseUrl || '/';
|
|
7
8
|
options.mode = options.mode || process.env.MODE || import.meta.env.MODE;
|
|
@@ -80,10 +81,9 @@ const fastifySsrPlugin = async (fastify, options) => {
|
|
|
80
81
|
fastify.get(`${options.baseUrl}*`, async (req, res) => {
|
|
81
82
|
const url = req.raw.url?.replace(options.baseUrl, '/');
|
|
82
83
|
const provide = options.provide ? await options.provide(req, res) : {};
|
|
83
|
-
const template =
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
const onRendered = (await import(fileURLToPath(new URL('./dist/ssr/server/virtual_vitrify-hooks.mjs', options.appDir)))).onRendered;
|
|
84
|
+
const { template, manifest, render, onRendered } = await loadSSRAssets({
|
|
85
|
+
distDir: new URL('./dist/', options.appDir)
|
|
86
|
+
});
|
|
87
87
|
const html = await renderHtml({
|
|
88
88
|
request: req,
|
|
89
89
|
reply: res,
|
|
@@ -131,4 +131,40 @@ const renderHtml = async (options) => {
|
|
|
131
131
|
}
|
|
132
132
|
return html;
|
|
133
133
|
};
|
|
134
|
-
|
|
134
|
+
const loadSSRAssets = async ({ mode, distDir } = {
|
|
135
|
+
mode: 'ssr'
|
|
136
|
+
}) => {
|
|
137
|
+
const appDir = getAppDir(new URL(import.meta.url));
|
|
138
|
+
const baseOutDir = distDir || new URL('dist/', appDir);
|
|
139
|
+
let templatePath, manifestPath, entryServerPath;
|
|
140
|
+
const onRenderedPath = fileURLToPath(new URL('ssr/server/virtual_vitrify-hooks.mjs', baseOutDir));
|
|
141
|
+
if (mode === 'ssg') {
|
|
142
|
+
templatePath = fileURLToPath(new URL('static/index.html', baseOutDir));
|
|
143
|
+
manifestPath = fileURLToPath(new URL('static/.vite/ssr-manifest.json', baseOutDir));
|
|
144
|
+
entryServerPath = fileURLToPath(new URL('ssr/server/entry-server.mjs', baseOutDir));
|
|
145
|
+
}
|
|
146
|
+
else {
|
|
147
|
+
templatePath = fileURLToPath(new URL('ssr/client/index.html', baseOutDir));
|
|
148
|
+
manifestPath = fileURLToPath(new URL('ssr/client/.vite/ssr-manifest.json', baseOutDir));
|
|
149
|
+
entryServerPath = fileURLToPath(new URL('ssr/server/entry-server.mjs', baseOutDir));
|
|
150
|
+
}
|
|
151
|
+
try {
|
|
152
|
+
const template = readFileSync(templatePath).toString();
|
|
153
|
+
const manifest = JSON.parse(readFileSync(manifestPath).toString());
|
|
154
|
+
const entryServer = await import(entryServerPath);
|
|
155
|
+
const { render, getRoutes } = entryServer;
|
|
156
|
+
const onRendered = (await import(onRenderedPath)).onRendered;
|
|
157
|
+
return {
|
|
158
|
+
template,
|
|
159
|
+
manifest,
|
|
160
|
+
render,
|
|
161
|
+
getRoutes,
|
|
162
|
+
onRendered
|
|
163
|
+
};
|
|
164
|
+
}
|
|
165
|
+
catch (e) {
|
|
166
|
+
console.error(e);
|
|
167
|
+
throw new Error('Unable to load SSR asset files');
|
|
168
|
+
}
|
|
169
|
+
};
|
|
170
|
+
export { fastifySsrPlugin, renderHtml, loadSSRAssets };
|
|
@@ -1,12 +1,8 @@
|
|
|
1
1
|
import { existsSync, promises as fs, mkdirSync } from 'fs';
|
|
2
2
|
import { routesToPaths } from '../../helpers/routes.js';
|
|
3
3
|
import { renderHtml } from './fastify-ssr-plugin.js';
|
|
4
|
-
export const prerender = async ({ outDir,
|
|
4
|
+
export const prerender = async ({ outDir, template, manifest, render, routes, onRendered }) => {
|
|
5
5
|
const promises = [];
|
|
6
|
-
const template = (await fs.readFile(templatePath)).toString();
|
|
7
|
-
const manifest = JSON.parse((await fs.readFile(manifestPath)).toString());
|
|
8
|
-
const { render, getRoutes } = await import(entryServerPath);
|
|
9
|
-
const routes = await getRoutes();
|
|
10
6
|
const paths = routesToPaths(routes).filter((i) => !i.includes(':') && !i.includes('*'));
|
|
11
7
|
const beasties = new (await import('beasties')).default({
|
|
12
8
|
path: outDir,
|
package/dist/index.js
CHANGED
|
@@ -43,11 +43,12 @@ const manualChunkNames = [
|
|
|
43
43
|
];
|
|
44
44
|
const moduleChunks = {
|
|
45
45
|
vue: ['vue', '@vue', 'vue-router'],
|
|
46
|
-
quasar: ['quasar',
|
|
46
|
+
quasar: ['quasar'],
|
|
47
|
+
atQuasar: ['@quasar']
|
|
47
48
|
};
|
|
48
49
|
const manualChunksFn = (manualChunkList) => {
|
|
49
50
|
return (id) => {
|
|
50
|
-
const matchedModule = Object.entries(moduleChunks).find(([chunkName, moduleNames]) => moduleNames.some((moduleName) =>
|
|
51
|
+
const matchedModule = Object.entries(moduleChunks).find(([chunkName, moduleNames]) => moduleNames.some((moduleName) => new RegExp(`\/${moduleName}\/`).test(id)));
|
|
51
52
|
if (id.includes('vitrify/src/')) {
|
|
52
53
|
const name = id.split('/').at(-1)?.split('.').at(0);
|
|
53
54
|
if (name && manualChunkNames.includes(name))
|
package/dist/types/app-urls.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export declare const resolve: (packageName: string, base: URL, counter?: number) => URL;
|
|
2
2
|
export declare const getPkgJsonDir: (dir: URL) => URL;
|
|
3
|
-
export declare const getAppDir: () => URL;
|
|
3
|
+
export declare const getAppDir: (dir?: URL) => URL;
|
|
4
4
|
export declare const getCliDir: () => URL;
|
|
5
5
|
export declare const getCliViteDir: (cliDir: URL) => URL;
|
|
6
6
|
export declare const getSrcDir: (appDir: URL) => URL;
|
|
@@ -29,5 +29,15 @@ declare const renderHtml: (options: {
|
|
|
29
29
|
manifest: Record<string, unknown>;
|
|
30
30
|
render: any;
|
|
31
31
|
}) => Promise<string>;
|
|
32
|
-
|
|
32
|
+
declare const loadSSRAssets: ({ mode, distDir }?: {
|
|
33
|
+
mode?: "ssr" | "ssg";
|
|
34
|
+
distDir?: URL;
|
|
35
|
+
}) => Promise<{
|
|
36
|
+
template: string;
|
|
37
|
+
manifest: any;
|
|
38
|
+
render: any;
|
|
39
|
+
getRoutes: any;
|
|
40
|
+
onRendered: any;
|
|
41
|
+
}>;
|
|
42
|
+
export { fastifySsrPlugin, renderHtml, loadSSRAssets };
|
|
33
43
|
export type FastifySsrPlugin = typeof fastifySsrPlugin;
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import type { OnRenderedHook } from 'src/node/vitrify-config.js';
|
|
2
|
-
|
|
2
|
+
import { type RouteRecordRaw } from 'vue-router';
|
|
3
|
+
export declare const prerender: ({ outDir, template, manifest, render, routes, onRendered }: {
|
|
3
4
|
outDir: string;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
5
|
+
template: string;
|
|
6
|
+
manifest: Record<string, unknown>;
|
|
7
|
+
render: unknown;
|
|
8
|
+
routes: RouteRecordRaw[];
|
|
7
9
|
onRendered: OnRenderedHook[];
|
|
8
10
|
}) => Promise<void[]>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitrify",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.21.0",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Stefan van Herwijnen",
|
|
6
6
|
"description": "Vite as your Full Stack development tool",
|
|
@@ -52,7 +52,7 @@
|
|
|
52
52
|
"@fastify/static": "^8.1.1",
|
|
53
53
|
"@unocss/core": "^66.0.0",
|
|
54
54
|
"@unocss/preset-uno": "^66.0.0",
|
|
55
|
-
"@unocss/preset-web-fonts": "66.1.0-beta.
|
|
55
|
+
"@unocss/preset-web-fonts": "66.1.0-beta.13",
|
|
56
56
|
"@unocss/preset-wind": "^66.0.0",
|
|
57
57
|
"@vitejs/plugin-vue": "^5.2.3",
|
|
58
58
|
"ajv": "^8.17.1",
|
|
@@ -60,23 +60,23 @@
|
|
|
60
60
|
"cac": "^6.7.14",
|
|
61
61
|
"chalk": "^5.4.1",
|
|
62
62
|
"cross-env": "^7.0.3",
|
|
63
|
-
"esbuild": "^0.25.
|
|
64
|
-
"fastify": "^5.
|
|
65
|
-
"glob": "^11.0.
|
|
66
|
-
"happy-dom": "^17.4.
|
|
63
|
+
"esbuild": "^0.25.3",
|
|
64
|
+
"fastify": "^5.3.2",
|
|
65
|
+
"glob": "^11.0.2",
|
|
66
|
+
"happy-dom": "^17.4.6",
|
|
67
67
|
"is-port-reachable": "^4.0.0",
|
|
68
68
|
"magic-string": "^0.30.17",
|
|
69
69
|
"merge-deep": "^3.0.3",
|
|
70
70
|
"readline": "^1.3.0",
|
|
71
71
|
"rollup-plugin-visualizer": "^5.14.0",
|
|
72
|
-
"sass": "1.
|
|
72
|
+
"sass": "1.87.0",
|
|
73
73
|
"ts-node": "^10.9.2",
|
|
74
74
|
"unocss": "^66.0.0",
|
|
75
|
-
"unplugin-vue-components": "^28.
|
|
76
|
-
"vite": "^6.
|
|
75
|
+
"unplugin-vue-components": "^28.5.0",
|
|
76
|
+
"vite": "^6.3.4",
|
|
77
77
|
"vite-plugin-pwa": "^1.0.0",
|
|
78
78
|
"vitefu": "^1.0.6",
|
|
79
|
-
"vitest": "^3.1.
|
|
79
|
+
"vitest": "^3.1.2",
|
|
80
80
|
"workbox-window": "^7.3.0"
|
|
81
81
|
},
|
|
82
82
|
"devDependencies": {
|
|
@@ -87,25 +87,25 @@
|
|
|
87
87
|
"@types/connect": "^3.4.38",
|
|
88
88
|
"@types/glob": "^8.1.0",
|
|
89
89
|
"@types/merge-deep": "^3.0.3",
|
|
90
|
-
"@types/node": "^22.
|
|
90
|
+
"@types/node": "^22.15.3",
|
|
91
91
|
"@types/ws": "^8.18.1",
|
|
92
92
|
"@unocss/preset-icons": "^66.0.0",
|
|
93
93
|
"@vue/runtime-core": "^3.5.13",
|
|
94
|
-
"beasties": "^0.3.
|
|
94
|
+
"beasties": "^0.3.3",
|
|
95
95
|
"css": "^3.0.0",
|
|
96
96
|
"css-to-tailwind-translator": "^1.2.8",
|
|
97
97
|
"quasar": "^2.18.1",
|
|
98
|
-
"rollup": "^4.
|
|
98
|
+
"rollup": "^4.40.1",
|
|
99
99
|
"typescript": "^5.8.3",
|
|
100
100
|
"vue": "^3.5.13",
|
|
101
|
-
"vue-router": "^4.5.
|
|
101
|
+
"vue-router": "^4.5.1"
|
|
102
102
|
},
|
|
103
103
|
"peerDependencies": {
|
|
104
104
|
"@fastify/static": "^8.1.1",
|
|
105
|
-
"fastify": "^5.
|
|
105
|
+
"fastify": "^5.3.2",
|
|
106
106
|
"quasar": "^2.18.1",
|
|
107
107
|
"vue": "^3.5.13",
|
|
108
|
-
"vue-router": "^4.5.
|
|
108
|
+
"vue-router": "^4.5.1"
|
|
109
109
|
},
|
|
110
110
|
"publishConfig": {
|
|
111
111
|
"access": "public",
|
package/src/node/app-urls.ts
CHANGED
|
@@ -19,8 +19,8 @@ export const getPkgJsonDir = (dir: URL): URL => {
|
|
|
19
19
|
}
|
|
20
20
|
return getPkgJsonDir(new URL('..', dir))
|
|
21
21
|
}
|
|
22
|
-
export const getAppDir = () =>
|
|
23
|
-
getPkgJsonDir(new URL(`file://${process.cwd()}/`))
|
|
22
|
+
export const getAppDir = (dir?: URL) =>
|
|
23
|
+
getPkgJsonDir(dir ?? new URL(`file://${process.cwd()}/`))
|
|
24
24
|
export const getCliDir = () => getPkgJsonDir(new URL('./', import.meta.url))
|
|
25
25
|
export const getCliViteDir = (cliDir: URL) => new URL('src/vite/', cliDir)
|
|
26
26
|
export const getSrcDir = (appDir: URL) => new URL('src/', appDir)
|
package/src/node/bin/cli.ts
CHANGED
|
@@ -8,6 +8,7 @@ import type { ResolvedConfig, ViteDevServer } from 'vite'
|
|
|
8
8
|
import type { Server } from 'net'
|
|
9
9
|
import type { FastifyInstance } from 'fastify'
|
|
10
10
|
import { readdir } from 'fs/promises'
|
|
11
|
+
import { loadSSRAssets } from '../frameworks/vue/fastify-ssr-plugin.js'
|
|
11
12
|
|
|
12
13
|
const cli = cac('vitrify')
|
|
13
14
|
cli
|
|
@@ -85,17 +86,23 @@ cli
|
|
|
85
86
|
...args,
|
|
86
87
|
outDir: fileURLToPath(new URL('ssr/server/', baseOutDir))
|
|
87
88
|
})
|
|
88
|
-
;({ prerender
|
|
89
|
+
;({ prerender } = await import(
|
|
89
90
|
new URL('ssr/server/prerender.mjs', baseOutDir).pathname
|
|
90
91
|
))
|
|
91
92
|
|
|
93
|
+
const { template, manifest, render, getRoutes, onRendered } =
|
|
94
|
+
await loadSSRAssets({
|
|
95
|
+
mode: 'ssg',
|
|
96
|
+
distDir: baseOutDir
|
|
97
|
+
})
|
|
98
|
+
const routes = await getRoutes()
|
|
99
|
+
|
|
92
100
|
prerender({
|
|
93
101
|
outDir: fileURLToPath(new URL('static/', baseOutDir)),
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
entryServerPath: new URL('ssr/server/entry-server.mjs', baseOutDir),
|
|
102
|
+
template,
|
|
103
|
+
manifest,
|
|
104
|
+
render,
|
|
105
|
+
routes,
|
|
99
106
|
onRendered
|
|
100
107
|
})
|
|
101
108
|
break
|
|
@@ -9,6 +9,7 @@ import {
|
|
|
9
9
|
} from '../../helpers/utils.js'
|
|
10
10
|
import type { ViteDevServer } from 'vite'
|
|
11
11
|
import type { OnRenderedHook } from '../../vitrify-config.js'
|
|
12
|
+
import { getAppDir } from '../../app-urls.js'
|
|
12
13
|
|
|
13
14
|
type ProvideFn = (
|
|
14
15
|
req: FastifyRequest,
|
|
@@ -123,31 +124,9 @@ const fastifySsrPlugin: FastifyPluginAsync<FastifySsrOptions> = async (
|
|
|
123
124
|
const url = req.raw.url?.replace(options.baseUrl!, '/')
|
|
124
125
|
const provide = options.provide ? await options.provide(req, res) : {}
|
|
125
126
|
|
|
126
|
-
const template =
|
|
127
|
-
|
|
128
|
-
)
|
|
129
|
-
const manifest = JSON.parse(
|
|
130
|
-
readFileSync(
|
|
131
|
-
new URL('./dist/ssr/client/.vite/ssr-manifest.json', options.appDir)
|
|
132
|
-
).toString()
|
|
133
|
-
)
|
|
134
|
-
const render = (
|
|
135
|
-
await import(
|
|
136
|
-
fileURLToPath(
|
|
137
|
-
new URL('./dist/ssr/server/entry-server.mjs', options.appDir)
|
|
138
|
-
)
|
|
139
|
-
)
|
|
140
|
-
).render
|
|
141
|
-
const onRendered = (
|
|
142
|
-
await import(
|
|
143
|
-
fileURLToPath(
|
|
144
|
-
new URL(
|
|
145
|
-
'./dist/ssr/server/virtual_vitrify-hooks.mjs',
|
|
146
|
-
options.appDir
|
|
147
|
-
)
|
|
148
|
-
)
|
|
149
|
-
)
|
|
150
|
-
).onRendered
|
|
127
|
+
const { template, manifest, render, onRendered } = await loadSSRAssets({
|
|
128
|
+
distDir: new URL('./dist/', options.appDir)
|
|
129
|
+
})
|
|
151
130
|
|
|
152
131
|
const html = await renderHtml({
|
|
153
132
|
request: req,
|
|
@@ -232,5 +211,60 @@ const renderHtml = async (options: {
|
|
|
232
211
|
return html
|
|
233
212
|
}
|
|
234
213
|
|
|
235
|
-
|
|
214
|
+
const loadSSRAssets = async (
|
|
215
|
+
{
|
|
216
|
+
mode,
|
|
217
|
+
distDir
|
|
218
|
+
}: {
|
|
219
|
+
mode?: 'ssr' | 'ssg'
|
|
220
|
+
distDir?: URL
|
|
221
|
+
} = {
|
|
222
|
+
mode: 'ssr'
|
|
223
|
+
}
|
|
224
|
+
) => {
|
|
225
|
+
const appDir = getAppDir(new URL(import.meta.url))
|
|
226
|
+
const baseOutDir = distDir || new URL('dist/', appDir)
|
|
227
|
+
|
|
228
|
+
let templatePath, manifestPath, entryServerPath
|
|
229
|
+
const onRenderedPath = fileURLToPath(
|
|
230
|
+
new URL('ssr/server/virtual_vitrify-hooks.mjs', baseOutDir)
|
|
231
|
+
)
|
|
232
|
+
if (mode === 'ssg') {
|
|
233
|
+
templatePath = fileURLToPath(new URL('static/index.html', baseOutDir))
|
|
234
|
+
manifestPath = fileURLToPath(
|
|
235
|
+
new URL('static/.vite/ssr-manifest.json', baseOutDir)
|
|
236
|
+
)
|
|
237
|
+
entryServerPath = fileURLToPath(
|
|
238
|
+
new URL('ssr/server/entry-server.mjs', baseOutDir)
|
|
239
|
+
)
|
|
240
|
+
} else {
|
|
241
|
+
templatePath = fileURLToPath(new URL('ssr/client/index.html', baseOutDir))
|
|
242
|
+
manifestPath = fileURLToPath(
|
|
243
|
+
new URL('ssr/client/.vite/ssr-manifest.json', baseOutDir)
|
|
244
|
+
)
|
|
245
|
+
entryServerPath = fileURLToPath(
|
|
246
|
+
new URL('ssr/server/entry-server.mjs', baseOutDir)
|
|
247
|
+
)
|
|
248
|
+
}
|
|
249
|
+
try {
|
|
250
|
+
const template = readFileSync(templatePath).toString()
|
|
251
|
+
const manifest = JSON.parse(readFileSync(manifestPath).toString())
|
|
252
|
+
const entryServer = await import(entryServerPath)
|
|
253
|
+
const { render, getRoutes } = entryServer
|
|
254
|
+
const onRendered = (await import(onRenderedPath)).onRendered
|
|
255
|
+
|
|
256
|
+
return {
|
|
257
|
+
template,
|
|
258
|
+
manifest,
|
|
259
|
+
render,
|
|
260
|
+
getRoutes,
|
|
261
|
+
onRendered
|
|
262
|
+
}
|
|
263
|
+
} catch (e) {
|
|
264
|
+
console.error(e)
|
|
265
|
+
throw new Error('Unable to load SSR asset files')
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
export { fastifySsrPlugin, renderHtml, loadSSRAssets }
|
|
236
270
|
export type FastifySsrPlugin = typeof fastifySsrPlugin
|
|
@@ -2,25 +2,24 @@ import { existsSync, promises as fs, mkdirSync } from 'fs'
|
|
|
2
2
|
import type { OnRenderedHook } from 'src/node/vitrify-config.js'
|
|
3
3
|
import { routesToPaths } from '../../helpers/routes.js'
|
|
4
4
|
import { renderHtml } from './fastify-ssr-plugin.js'
|
|
5
|
+
import { type RouteRecordRaw } from 'vue-router'
|
|
5
6
|
|
|
6
7
|
export const prerender = async ({
|
|
7
8
|
outDir,
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
9
|
+
template,
|
|
10
|
+
manifest,
|
|
11
|
+
render,
|
|
12
|
+
routes,
|
|
11
13
|
onRendered
|
|
12
14
|
}: {
|
|
13
15
|
outDir: string
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
16
|
+
template: string
|
|
17
|
+
manifest: Record<string, unknown>
|
|
18
|
+
render: unknown
|
|
19
|
+
routes: RouteRecordRaw[]
|
|
17
20
|
onRendered: OnRenderedHook[]
|
|
18
21
|
}) => {
|
|
19
22
|
const promises = []
|
|
20
|
-
const template = (await fs.readFile(templatePath)).toString()
|
|
21
|
-
const manifest = JSON.parse((await fs.readFile(manifestPath)).toString())
|
|
22
|
-
const { render, getRoutes } = await import(entryServerPath)
|
|
23
|
-
const routes = await getRoutes()
|
|
24
23
|
const paths = routesToPaths(routes).filter(
|
|
25
24
|
(i) => !i.includes(':') && !i.includes('*')
|
|
26
25
|
)
|
package/src/node/index.ts
CHANGED
|
@@ -74,13 +74,16 @@ const manualChunkNames = [
|
|
|
74
74
|
|
|
75
75
|
const moduleChunks = {
|
|
76
76
|
vue: ['vue', '@vue', 'vue-router'],
|
|
77
|
-
quasar: ['quasar',
|
|
77
|
+
quasar: ['quasar'],
|
|
78
|
+
atQuasar: ['@quasar']
|
|
78
79
|
}
|
|
79
80
|
const manualChunksFn = (manualChunkList?: string[]): ManualChunksOption => {
|
|
80
81
|
return (id: string) => {
|
|
81
82
|
const matchedModule = Object.entries(moduleChunks).find(
|
|
82
83
|
([chunkName, moduleNames]) =>
|
|
83
|
-
moduleNames.some((moduleName) =>
|
|
84
|
+
moduleNames.some((moduleName) =>
|
|
85
|
+
new RegExp(`\/${moduleName}\/`).test(id)
|
|
86
|
+
)
|
|
84
87
|
)
|
|
85
88
|
if (id.includes('vitrify/src/')) {
|
|
86
89
|
const name = id.split('/').at(-1)?.split('.').at(0)
|