vitrify 0.6.13 → 0.6.16
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 +6 -4
- package/dist/frameworks/vue/fastify-ssr-plugin.js +15 -4
- package/dist/frameworks/vue/server.js +2 -1
- package/dist/index.js +17 -17
- package/dist/plugins/quasar.js +4 -3
- package/dist/types/bin/dev.d.ts +1 -1
- package/dist/types/frameworks/vue/fastify-ssr-plugin.d.ts +2 -0
- package/dist/types/frameworks/vue/server.d.ts +3 -2
- package/package.json +2 -2
- package/src/node/bin/dev.ts +7 -5
- package/src/node/frameworks/vue/fastify-ssr-plugin.ts +20 -4
- package/src/node/frameworks/vue/server.ts +4 -1
- package/src/node/index.ts +23 -16
- package/src/node/plugins/quasar.ts +4 -3
- package/src/vite/vue/ssr/app.ts +4 -1
- package/src/vite/vue/ssr/entry-server.ts +1 -7
package/dist/bin/dev.js
CHANGED
|
@@ -76,14 +76,15 @@ ssr, framework = 'vue', host, appDir, publicDir }) {
|
|
|
76
76
|
});
|
|
77
77
|
let setup;
|
|
78
78
|
let server;
|
|
79
|
+
let onRendered;
|
|
79
80
|
console.log(`Development mode: ${ssr ? ssr : 'csr'}`);
|
|
80
81
|
if (ssr) {
|
|
81
82
|
const entryUrl = ssr === 'fastify'
|
|
82
83
|
? new URL('src/vite/fastify/entry.ts', cliDir).pathname
|
|
83
|
-
: new URL(`src/vite/${framework}/ssr/
|
|
84
|
-
({ setup } = await vite.ssrLoadModule(entryUrl));
|
|
84
|
+
: new URL(`src/vite/${framework}/ssr/app.ts`, cliDir).pathname;
|
|
85
|
+
({ setup, onRendered } = await vite.ssrLoadModule(entryUrl));
|
|
85
86
|
const app = fastify({
|
|
86
|
-
logger:
|
|
87
|
+
logger: false,
|
|
87
88
|
https: vite.config.server.https
|
|
88
89
|
});
|
|
89
90
|
if (process.env)
|
|
@@ -96,7 +97,8 @@ ssr, framework = 'vue', host, appDir, publicDir }) {
|
|
|
96
97
|
if (ssr === 'ssr') {
|
|
97
98
|
await app.register(fastifySsrPlugin, {
|
|
98
99
|
appDir,
|
|
99
|
-
mode: 'development'
|
|
100
|
+
mode: 'development',
|
|
101
|
+
onRendered
|
|
100
102
|
});
|
|
101
103
|
}
|
|
102
104
|
await app.listen({
|
|
@@ -56,7 +56,6 @@ const fastifySsrPlugin = async (fastify, options, done) => {
|
|
|
56
56
|
// configFile: false,
|
|
57
57
|
// ...config
|
|
58
58
|
// })
|
|
59
|
-
console.log('Dev mode');
|
|
60
59
|
if (!('use' in fastify)) {
|
|
61
60
|
const middie = (await import('@fastify/middie')).default;
|
|
62
61
|
await fastify.register(middie);
|
|
@@ -65,9 +64,11 @@ const fastifySsrPlugin = async (fastify, options, done) => {
|
|
|
65
64
|
fastify.get(`${options.baseUrl}*`, async (req, res) => {
|
|
66
65
|
try {
|
|
67
66
|
const url = req.raw.url?.replace(options.baseUrl, '/');
|
|
67
|
+
const provide = options.provide ? await options.provide(req, res) : {};
|
|
68
68
|
const ssrContext = {
|
|
69
69
|
req,
|
|
70
|
-
res
|
|
70
|
+
res,
|
|
71
|
+
provide
|
|
71
72
|
};
|
|
72
73
|
let template = readFileSync(new URL('index.html', frameworkDir)).toString();
|
|
73
74
|
template = await vite.transformIndexHtml(url, template);
|
|
@@ -90,11 +91,16 @@ const fastifySsrPlugin = async (fastify, options, done) => {
|
|
|
90
91
|
mods: matchedModules
|
|
91
92
|
});
|
|
92
93
|
const [appHtml, preloadLinks] = await render(url, manifest, ssrContext);
|
|
93
|
-
|
|
94
|
+
let html = template
|
|
94
95
|
.replace(`<!--preload-links-->`, preloadLinks)
|
|
95
96
|
.replace(`<!--app-html-->`, appHtml)
|
|
96
97
|
.replace('<!--product-name-->', options.productName || 'Product name')
|
|
97
98
|
.replace('<!--dev-ssr-css-->', css);
|
|
99
|
+
if (options.onRendered?.length) {
|
|
100
|
+
for (const ssrFunction of options.onRendered) {
|
|
101
|
+
html = ssrFunction(html, ssrContext);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
98
104
|
res.code(200);
|
|
99
105
|
res.type('text/html');
|
|
100
106
|
res.send(html);
|
|
@@ -131,9 +137,14 @@ const fastifySsrPlugin = async (fastify, options, done) => {
|
|
|
131
137
|
if (!ssrContext.initialState)
|
|
132
138
|
ssrContext.initialState = {};
|
|
133
139
|
ssrContext.initialState.provide = provide;
|
|
134
|
-
|
|
140
|
+
let html = template
|
|
135
141
|
.replace(`<!--preload-links-->`, preloadLinks)
|
|
136
142
|
.replace(`<!--app-html-->`, appHtml);
|
|
143
|
+
if (options.onRendered?.length) {
|
|
144
|
+
for (const ssrFunction of options.onRendered) {
|
|
145
|
+
html = ssrFunction(html, ssrContext);
|
|
146
|
+
}
|
|
147
|
+
}
|
|
137
148
|
res.code(200);
|
|
138
149
|
res.type('text/html');
|
|
139
150
|
res.send(html);
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import fastify from 'fastify';
|
|
2
|
-
export const createApp = ({ onSetup, appDir, baseUrl, fastifyPlugin, vitrifyDir, mode }) => {
|
|
2
|
+
export const createApp = ({ onSetup, appDir, baseUrl, fastifyPlugin, onRendered, vitrifyDir, mode }) => {
|
|
3
3
|
const app = fastify({
|
|
4
4
|
logger: true
|
|
5
5
|
});
|
|
@@ -7,6 +7,7 @@ export const createApp = ({ onSetup, appDir, baseUrl, fastifyPlugin, vitrifyDir,
|
|
|
7
7
|
baseUrl,
|
|
8
8
|
appDir,
|
|
9
9
|
vitrifyDir,
|
|
10
|
+
onRendered,
|
|
10
11
|
mode
|
|
11
12
|
});
|
|
12
13
|
// if (onSetup?.length) {
|
package/dist/index.js
CHANGED
|
@@ -32,23 +32,23 @@ const manualChunkNames = [
|
|
|
32
32
|
'server'
|
|
33
33
|
];
|
|
34
34
|
const moduleChunks = {
|
|
35
|
-
vue: ['vue', 'vue-router'],
|
|
35
|
+
vue: ['vue', '@vue', 'vue-router'],
|
|
36
36
|
quasar: ['quasar', '@quasar']
|
|
37
37
|
};
|
|
38
38
|
const manualChunks = (id) => {
|
|
39
39
|
const matchedModule = Object.entries(moduleChunks).find(([chunkName, moduleNames]) => moduleNames.some((moduleName) => id.includes(moduleName + '/')));
|
|
40
|
-
if (id.includes('vitrify/src/
|
|
40
|
+
if (id.includes('vitrify/src/')) {
|
|
41
41
|
const name = id.split('/').at(-1)?.split('.').at(0);
|
|
42
42
|
if (name && manualChunkNames.includes(name))
|
|
43
43
|
return name;
|
|
44
44
|
}
|
|
45
|
-
else if (matchedModule) {
|
|
46
|
-
return matchedModule[0];
|
|
47
|
-
}
|
|
48
45
|
else if (VIRTUAL_MODULES.some((virtualModule) => id.includes(virtualModule))) {
|
|
49
46
|
return VIRTUAL_MODULES.find((name) => id.includes(name));
|
|
50
47
|
}
|
|
51
48
|
else if (id.includes('node_modules')) {
|
|
49
|
+
if (matchedModule) {
|
|
50
|
+
return matchedModule[0];
|
|
51
|
+
}
|
|
52
52
|
return 'vendor';
|
|
53
53
|
}
|
|
54
54
|
};
|
|
@@ -378,22 +378,22 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
378
378
|
{ find: 'cwd', replacement: cwd.pathname },
|
|
379
379
|
{ find: 'boot', replacement: new URL('boot/', srcDir).pathname },
|
|
380
380
|
{ find: 'assets', replacement: new URL('assets/', srcDir).pathname },
|
|
381
|
-
...Object.entries(packageUrls).map(([key, value]) => ({
|
|
382
|
-
|
|
383
|
-
|
|
384
|
-
}))
|
|
385
|
-
|
|
386
|
-
|
|
387
|
-
|
|
388
|
-
|
|
381
|
+
// ...Object.entries(packageUrls).map(([key, value]) => ({
|
|
382
|
+
// find: key,
|
|
383
|
+
// replacement: value.pathname
|
|
384
|
+
// }))
|
|
385
|
+
{
|
|
386
|
+
find: new RegExp('^vue$'),
|
|
387
|
+
replacement: new URL('./dist/vue.runtime.esm-bundler.js', packageUrls['vue']).pathname
|
|
388
|
+
},
|
|
389
389
|
// {
|
|
390
390
|
// find: new RegExp('^vue/server-renderer$'),
|
|
391
391
|
// replacement: 'vue/server-renderer/index.mjs'
|
|
392
392
|
// },
|
|
393
|
-
|
|
394
|
-
|
|
395
|
-
|
|
396
|
-
|
|
393
|
+
{
|
|
394
|
+
find: new RegExp('^vue-router$'),
|
|
395
|
+
replacement: new URL('./dist/vue-router.esm-bundler.js', packageUrls['vue-router']).pathname
|
|
396
|
+
}
|
|
397
397
|
// { find: 'vue', replacement: packageUrls['vue'].pathname },
|
|
398
398
|
// { find: 'vue-router', replacement: packageUrls['vue-router'].pathname },
|
|
399
399
|
// { find: 'vitrify', replacement: cliDir.pathname }
|
package/dist/plugins/quasar.js
CHANGED
|
@@ -181,8 +181,8 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
|
|
|
181
181
|
// ).pathname
|
|
182
182
|
// },
|
|
183
183
|
{
|
|
184
|
-
find: 'quasar/src',
|
|
185
|
-
replacement: new URL('./src', config.vitrify.urls.packages.quasar).pathname
|
|
184
|
+
find: 'quasar/src/',
|
|
185
|
+
replacement: new URL('./src/', config.vitrify.urls.packages.quasar).pathname
|
|
186
186
|
}
|
|
187
187
|
// {
|
|
188
188
|
// find: 'quasar',
|
|
@@ -195,7 +195,7 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
|
|
|
195
195
|
// find: new RegExp('^quasar$'),
|
|
196
196
|
// replacement: new URL('src/index.all.js', urls?.packages?.quasar)
|
|
197
197
|
// .pathname
|
|
198
|
-
// }
|
|
198
|
+
// }
|
|
199
199
|
// {
|
|
200
200
|
// find: `@quasar/extras`,
|
|
201
201
|
// replacement: new URL('.', urls?.packages?.['@quasar/extras'])
|
|
@@ -263,6 +263,7 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
|
|
|
263
263
|
export * from 'quasar/src/composables.js';
|
|
264
264
|
export * from 'quasar/src/directives.js';
|
|
265
265
|
export * from 'quasar/src/utils.js';
|
|
266
|
+
export * from 'quasar/src/composables.js';
|
|
266
267
|
export { default as Quasar } from 'quasar/src/install-quasar.js'`;
|
|
267
268
|
}
|
|
268
269
|
return null;
|
package/dist/types/bin/dev.d.ts
CHANGED
|
@@ -42,7 +42,7 @@ export declare function createServer({ port, logLevel, ssr, framework, host, app
|
|
|
42
42
|
server: import("vite").ResolvedServerOptions;
|
|
43
43
|
build: Required<import("vite").BuildOptions>;
|
|
44
44
|
preview: import("vite").ResolvedPreviewOptions;
|
|
45
|
-
ssr: import("vite").ResolvedSSROptions;
|
|
45
|
+
ssr: import("vite").ResolvedSSROptions | undefined;
|
|
46
46
|
assetsInclude: (file: string) => boolean;
|
|
47
47
|
logger: import("vite").Logger;
|
|
48
48
|
createResolver: (options?: Partial<import("vite").InternalResolveOptions> | undefined) => import("vite").ResolveFn;
|
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import type { FastifyPluginCallback, FastifyRequest, FastifyReply } from 'fastify';
|
|
2
2
|
import type { ViteDevServer } from 'vite';
|
|
3
|
+
import type { OnRenderedHook } from 'src/node/vitrify-config.js';
|
|
3
4
|
export interface FastifySsrOptions {
|
|
4
5
|
baseUrl?: string;
|
|
5
6
|
provide?: (req: FastifyRequest, res: FastifyReply) => Promise<Record<string, unknown>>;
|
|
6
7
|
vitrifyDir?: URL;
|
|
7
8
|
vite?: ViteDevServer;
|
|
9
|
+
onRendered?: OnRenderedHook[];
|
|
8
10
|
appDir?: URL;
|
|
9
11
|
publicDir?: URL;
|
|
10
12
|
productName?: string;
|
|
@@ -1,13 +1,14 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { FastifyInstance } from 'fastify';
|
|
3
|
-
import type { OnSetupFile } from '../../vitrify-config.js';
|
|
3
|
+
import type { OnRenderedHook, OnSetupFile } from '../../vitrify-config.js';
|
|
4
4
|
import type { FastifyCsrPlugin } from './fastify-csr-plugin.js';
|
|
5
5
|
import type { FastifySsrPlugin } from './fastify-ssr-plugin.js';
|
|
6
|
-
export declare const createApp: ({ onSetup, appDir, baseUrl, fastifyPlugin, vitrifyDir, mode }: {
|
|
6
|
+
export declare const createApp: ({ onSetup, appDir, baseUrl, fastifyPlugin, onRendered, vitrifyDir, mode }: {
|
|
7
7
|
onSetup: OnSetupFile[];
|
|
8
8
|
appDir: URL;
|
|
9
9
|
baseUrl?: string | undefined;
|
|
10
10
|
fastifyPlugin: FastifySsrPlugin | FastifyCsrPlugin;
|
|
11
|
+
onRendered: OnRenderedHook[];
|
|
11
12
|
vitrifyDir?: URL | undefined;
|
|
12
13
|
mode: string;
|
|
13
14
|
}) => FastifyInstance<import("http").Server, import("http").IncomingMessage, import("http").ServerResponse, pino.Logger, import("fastify").FastifyTypeProviderDefault> & PromiseLike<FastifyInstance<import("http").Server, import("http").IncomingMessage, import("http").ServerResponse, pino.Logger, import("fastify").FastifyTypeProviderDefault>>;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitrify",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.16",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Stefan van Herwijnen",
|
|
6
6
|
"description": "Pre-configured Vite CLI for your framework",
|
|
@@ -76,7 +76,7 @@
|
|
|
76
76
|
"sass": "1.53.0",
|
|
77
77
|
"ts-node": "^10.8.2",
|
|
78
78
|
"unplugin-vue-components": "^0.21.0",
|
|
79
|
-
"vite": "
|
|
79
|
+
"vite": "3.0.0-beta.6",
|
|
80
80
|
"vitest": "^0.17.0"
|
|
81
81
|
},
|
|
82
82
|
"devDependencies": {
|
package/src/node/bin/dev.ts
CHANGED
|
@@ -7,6 +7,7 @@ import type { FastifyInstance } from 'fastify/types/instance'
|
|
|
7
7
|
import fastify from 'fastify'
|
|
8
8
|
import { fastifySsrPlugin } from '../frameworks/vue/fastify-ssr-plugin.js'
|
|
9
9
|
import type { ServerOptions } from 'https'
|
|
10
|
+
import type { OnRenderedHook } from '../vitrify-config.js'
|
|
10
11
|
|
|
11
12
|
export async function createVitrifyDevServer({
|
|
12
13
|
port = 3000,
|
|
@@ -128,18 +129,18 @@ export async function createServer({
|
|
|
128
129
|
|
|
129
130
|
let setup
|
|
130
131
|
let server: Server
|
|
132
|
+
let onRendered: OnRenderedHook[]
|
|
131
133
|
|
|
132
134
|
console.log(`Development mode: ${ssr ? ssr : 'csr'}`)
|
|
133
135
|
if (ssr) {
|
|
134
136
|
const entryUrl =
|
|
135
137
|
ssr === 'fastify'
|
|
136
138
|
? new URL('src/vite/fastify/entry.ts', cliDir).pathname
|
|
137
|
-
: new URL(`src/vite/${framework}/ssr/
|
|
138
|
-
|
|
139
|
-
;({ setup } = await vite.ssrLoadModule(entryUrl))
|
|
139
|
+
: new URL(`src/vite/${framework}/ssr/app.ts`, cliDir).pathname
|
|
140
140
|
|
|
141
|
+
;({ setup, onRendered } = await vite.ssrLoadModule(entryUrl))
|
|
141
142
|
const app = fastify({
|
|
142
|
-
logger:
|
|
143
|
+
logger: false,
|
|
143
144
|
https: vite.config.server.https as ServerOptions
|
|
144
145
|
})
|
|
145
146
|
if (process.env) process.env.MODE = 'development'
|
|
@@ -151,7 +152,8 @@ export async function createServer({
|
|
|
151
152
|
if (ssr === 'ssr') {
|
|
152
153
|
await app.register(fastifySsrPlugin, {
|
|
153
154
|
appDir,
|
|
154
|
-
mode: 'development'
|
|
155
|
+
mode: 'development',
|
|
156
|
+
onRendered
|
|
155
157
|
})
|
|
156
158
|
}
|
|
157
159
|
await app.listen({
|
|
@@ -7,6 +7,7 @@ import fastifyStatic from '@fastify/static'
|
|
|
7
7
|
import { readFileSync } from 'fs'
|
|
8
8
|
import { componentsModules, collectCss } from '../../helpers/collect-css-ssr.js'
|
|
9
9
|
import type { ViteDevServer } from 'vite'
|
|
10
|
+
import type { OnRenderedHook } from 'src/node/vitrify-config.js'
|
|
10
11
|
|
|
11
12
|
export interface FastifySsrOptions {
|
|
12
13
|
baseUrl?: string
|
|
@@ -17,6 +18,7 @@ export interface FastifySsrOptions {
|
|
|
17
18
|
vitrifyDir?: URL
|
|
18
19
|
vite?: ViteDevServer
|
|
19
20
|
// frameworkDir?: URL
|
|
21
|
+
onRendered?: OnRenderedHook[]
|
|
20
22
|
appDir?: URL
|
|
21
23
|
publicDir?: URL
|
|
22
24
|
productName?: string
|
|
@@ -88,7 +90,6 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
|
|
|
88
90
|
// ...config
|
|
89
91
|
// })
|
|
90
92
|
|
|
91
|
-
console.log('Dev mode')
|
|
92
93
|
if (!('use' in fastify)) {
|
|
93
94
|
const middie = (await import('@fastify/middie')).default
|
|
94
95
|
await fastify.register(middie)
|
|
@@ -98,9 +99,12 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
|
|
|
98
99
|
fastify.get(`${options.baseUrl}*`, async (req, res) => {
|
|
99
100
|
try {
|
|
100
101
|
const url = req.raw.url?.replace(options.baseUrl!, '/')
|
|
102
|
+
const provide = options.provide ? await options.provide(req, res) : {}
|
|
103
|
+
|
|
101
104
|
const ssrContext = {
|
|
102
105
|
req,
|
|
103
|
-
res
|
|
106
|
+
res,
|
|
107
|
+
provide
|
|
104
108
|
}
|
|
105
109
|
|
|
106
110
|
let template = readFileSync(
|
|
@@ -129,12 +133,18 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
|
|
|
129
133
|
})
|
|
130
134
|
|
|
131
135
|
const [appHtml, preloadLinks] = await render(url, manifest, ssrContext)
|
|
132
|
-
|
|
136
|
+
let html = template
|
|
133
137
|
.replace(`<!--preload-links-->`, preloadLinks)
|
|
134
138
|
.replace(`<!--app-html-->`, appHtml)
|
|
135
139
|
.replace('<!--product-name-->', options.productName || 'Product name')
|
|
136
140
|
.replace('<!--dev-ssr-css-->', css)
|
|
137
141
|
|
|
142
|
+
if (options.onRendered?.length) {
|
|
143
|
+
for (const ssrFunction of options.onRendered) {
|
|
144
|
+
html = ssrFunction(html, ssrContext)
|
|
145
|
+
}
|
|
146
|
+
}
|
|
147
|
+
|
|
138
148
|
res.code(200)
|
|
139
149
|
res.type('text/html')
|
|
140
150
|
res.send(html)
|
|
@@ -183,10 +193,16 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
|
|
|
183
193
|
if (!ssrContext.initialState) ssrContext.initialState = {}
|
|
184
194
|
ssrContext.initialState.provide = provide
|
|
185
195
|
|
|
186
|
-
|
|
196
|
+
let html = template
|
|
187
197
|
.replace(`<!--preload-links-->`, preloadLinks)
|
|
188
198
|
.replace(`<!--app-html-->`, appHtml)
|
|
189
199
|
|
|
200
|
+
if (options.onRendered?.length) {
|
|
201
|
+
for (const ssrFunction of options.onRendered) {
|
|
202
|
+
html = ssrFunction(html, ssrContext)
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
|
|
190
206
|
res.code(200)
|
|
191
207
|
res.type('text/html')
|
|
192
208
|
res.send(html)
|
|
@@ -2,7 +2,7 @@ import type { FastifyInstance } from 'fastify'
|
|
|
2
2
|
import fastify from 'fastify'
|
|
3
3
|
import type { ViteDevServer } from 'vite'
|
|
4
4
|
import { getCliDir, getCliViteDir } from '../../app-urls.js'
|
|
5
|
-
import type { OnSetupFile } from '../../vitrify-config.js'
|
|
5
|
+
import type { OnRenderedHook, OnSetupFile } from '../../vitrify-config.js'
|
|
6
6
|
import type { FastifyCsrPlugin } from './fastify-csr-plugin.js'
|
|
7
7
|
import type { FastifySsrPlugin } from './fastify-ssr-plugin.js'
|
|
8
8
|
|
|
@@ -11,6 +11,7 @@ export const createApp = ({
|
|
|
11
11
|
appDir,
|
|
12
12
|
baseUrl,
|
|
13
13
|
fastifyPlugin,
|
|
14
|
+
onRendered,
|
|
14
15
|
vitrifyDir,
|
|
15
16
|
mode
|
|
16
17
|
}: {
|
|
@@ -18,6 +19,7 @@ export const createApp = ({
|
|
|
18
19
|
appDir: URL
|
|
19
20
|
baseUrl?: string
|
|
20
21
|
fastifyPlugin: FastifySsrPlugin | FastifyCsrPlugin
|
|
22
|
+
onRendered: OnRenderedHook[]
|
|
21
23
|
vitrifyDir?: URL
|
|
22
24
|
mode: string
|
|
23
25
|
}) => {
|
|
@@ -29,6 +31,7 @@ export const createApp = ({
|
|
|
29
31
|
baseUrl,
|
|
30
32
|
appDir,
|
|
31
33
|
vitrifyDir,
|
|
34
|
+
onRendered,
|
|
32
35
|
mode
|
|
33
36
|
})
|
|
34
37
|
|
package/src/node/index.ts
CHANGED
|
@@ -50,7 +50,7 @@ const manualChunkNames = [
|
|
|
50
50
|
]
|
|
51
51
|
|
|
52
52
|
const moduleChunks = {
|
|
53
|
-
vue: ['vue', 'vue-router'],
|
|
53
|
+
vue: ['vue', '@vue', 'vue-router'],
|
|
54
54
|
quasar: ['quasar', '@quasar']
|
|
55
55
|
}
|
|
56
56
|
const manualChunks: ManualChunksOption = (id: string) => {
|
|
@@ -58,16 +58,17 @@ const manualChunks: ManualChunksOption = (id: string) => {
|
|
|
58
58
|
([chunkName, moduleNames]) =>
|
|
59
59
|
moduleNames.some((moduleName) => id.includes(moduleName + '/'))
|
|
60
60
|
)
|
|
61
|
-
if (id.includes('vitrify/src/
|
|
61
|
+
if (id.includes('vitrify/src/')) {
|
|
62
62
|
const name = id.split('/').at(-1)?.split('.').at(0)
|
|
63
63
|
if (name && manualChunkNames.includes(name)) return name
|
|
64
|
-
} else if (matchedModule) {
|
|
65
|
-
return matchedModule[0]
|
|
66
64
|
} else if (
|
|
67
65
|
VIRTUAL_MODULES.some((virtualModule) => id.includes(virtualModule))
|
|
68
66
|
) {
|
|
69
67
|
return VIRTUAL_MODULES.find((name) => id.includes(name))
|
|
70
68
|
} else if (id.includes('node_modules')) {
|
|
69
|
+
if (matchedModule) {
|
|
70
|
+
return matchedModule[0]
|
|
71
|
+
}
|
|
71
72
|
return 'vendor'
|
|
72
73
|
}
|
|
73
74
|
}
|
|
@@ -459,22 +460,28 @@ export const baseConfig = async ({
|
|
|
459
460
|
{ find: 'cwd', replacement: cwd.pathname },
|
|
460
461
|
{ find: 'boot', replacement: new URL('boot/', srcDir).pathname },
|
|
461
462
|
{ find: 'assets', replacement: new URL('assets/', srcDir).pathname },
|
|
462
|
-
...Object.entries(packageUrls).map(([key, value]) => ({
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
}))
|
|
466
|
-
|
|
467
|
-
|
|
468
|
-
|
|
469
|
-
|
|
463
|
+
// ...Object.entries(packageUrls).map(([key, value]) => ({
|
|
464
|
+
// find: key,
|
|
465
|
+
// replacement: value.pathname
|
|
466
|
+
// }))
|
|
467
|
+
{
|
|
468
|
+
find: new RegExp('^vue$'),
|
|
469
|
+
replacement: new URL(
|
|
470
|
+
'./dist/vue.runtime.esm-bundler.js',
|
|
471
|
+
packageUrls['vue']
|
|
472
|
+
).pathname
|
|
473
|
+
},
|
|
470
474
|
// {
|
|
471
475
|
// find: new RegExp('^vue/server-renderer$'),
|
|
472
476
|
// replacement: 'vue/server-renderer/index.mjs'
|
|
473
477
|
// },
|
|
474
|
-
|
|
475
|
-
|
|
476
|
-
|
|
477
|
-
|
|
478
|
+
{
|
|
479
|
+
find: new RegExp('^vue-router$'),
|
|
480
|
+
replacement: new URL(
|
|
481
|
+
'./dist/vue-router.esm-bundler.js',
|
|
482
|
+
packageUrls['vue-router']
|
|
483
|
+
).pathname
|
|
484
|
+
}
|
|
478
485
|
// { find: 'vue', replacement: packageUrls['vue'].pathname },
|
|
479
486
|
// { find: 'vue-router', replacement: packageUrls['vue-router'].pathname },
|
|
480
487
|
// { find: 'vitrify', replacement: cliDir.pathname }
|
|
@@ -261,9 +261,9 @@ export const QuasarPlugin: VitrifyPlugin = async ({
|
|
|
261
261
|
// ).pathname
|
|
262
262
|
// },
|
|
263
263
|
{
|
|
264
|
-
find: 'quasar/src',
|
|
264
|
+
find: 'quasar/src/',
|
|
265
265
|
replacement: new URL(
|
|
266
|
-
'./src',
|
|
266
|
+
'./src/',
|
|
267
267
|
config.vitrify!.urls!.packages!.quasar
|
|
268
268
|
).pathname
|
|
269
269
|
}
|
|
@@ -278,7 +278,7 @@ export const QuasarPlugin: VitrifyPlugin = async ({
|
|
|
278
278
|
// find: new RegExp('^quasar$'),
|
|
279
279
|
// replacement: new URL('src/index.all.js', urls?.packages?.quasar)
|
|
280
280
|
// .pathname
|
|
281
|
-
// }
|
|
281
|
+
// }
|
|
282
282
|
// {
|
|
283
283
|
// find: `@quasar/extras`,
|
|
284
284
|
// replacement: new URL('.', urls?.packages?.['@quasar/extras'])
|
|
@@ -344,6 +344,7 @@ export const QuasarPlugin: VitrifyPlugin = async ({
|
|
|
344
344
|
export * from 'quasar/src/composables.js';
|
|
345
345
|
export * from 'quasar/src/directives.js';
|
|
346
346
|
export * from 'quasar/src/utils.js';
|
|
347
|
+
export * from 'quasar/src/composables.js';
|
|
347
348
|
export { default as Quasar } from 'quasar/src/install-quasar.js'`
|
|
348
349
|
}
|
|
349
350
|
return null
|
package/src/vite/vue/ssr/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 { onSetup } from 'virtual:vitrify-hooks'
|
|
4
|
+
import { onSetup, onRendered } from 'virtual:vitrify-hooks'
|
|
5
5
|
import { fastifySsrPlugin } from './fastify-ssr-plugin.js'
|
|
6
6
|
import type { ViteDevServer } from 'vite'
|
|
7
7
|
|
|
@@ -17,7 +17,10 @@ export const setupApp = async () => {
|
|
|
17
17
|
appDir,
|
|
18
18
|
baseUrl,
|
|
19
19
|
fastifyPlugin: fastifySsrPlugin,
|
|
20
|
+
onRendered,
|
|
20
21
|
// vitrifyDir,
|
|
21
22
|
mode: import.meta.env.MODE
|
|
22
23
|
})
|
|
23
24
|
}
|
|
25
|
+
|
|
26
|
+
export { onRendered }
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { createApp } from '../main.js'
|
|
2
2
|
// import { renderToString } from 'vue/server-renderer'
|
|
3
3
|
|
|
4
|
-
import { onRendered } from 'virtual:vitrify-hooks'
|
|
4
|
+
// import { onRendered } from 'virtual:vitrify-hooks'
|
|
5
5
|
|
|
6
6
|
const initializeApp = async (url, ssrContext) => {
|
|
7
7
|
const onRenderedList = []
|
|
@@ -49,12 +49,6 @@ export async function render(url, manifest, ssrContext, renderToString) {
|
|
|
49
49
|
|
|
50
50
|
const preloadLinks = renderPreloadLinks(ctx.modules, manifest)
|
|
51
51
|
|
|
52
|
-
if (onRendered?.length) {
|
|
53
|
-
for (const ssrFunction of onRendered) {
|
|
54
|
-
html = ssrFunction(html, ssrContext)
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
|
|
58
52
|
return [html, preloadLinks]
|
|
59
53
|
}
|
|
60
54
|
|