vitrify 0.6.0 → 0.6.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 +3 -4
- package/dist/frameworks/vue/fastify-ssr-plugin.js +0 -5
- package/dist/frameworks/vue/prerender.js +2 -8
- package/dist/frameworks/vue/server.js +1 -2
- package/dist/index.js +12 -4
- package/dist/plugins/quasar.js +3 -3
- package/dist/types/frameworks/vue/fastify-csr-plugin.d.ts +0 -2
- package/dist/types/frameworks/vue/fastify-ssr-plugin.d.ts +0 -2
- package/dist/types/frameworks/vue/prerender.d.ts +1 -3
- package/dist/types/frameworks/vue/server.d.ts +2 -3
- package/dist/types/index.d.ts +1 -0
- package/package.json +2 -1
- package/src/node/bin/cli.ts +3 -4
- package/src/node/frameworks/vue/fastify-csr-plugin.ts +0 -2
- package/src/node/frameworks/vue/fastify-ssr-plugin.ts +0 -8
- package/src/node/frameworks/vue/prerender.ts +2 -12
- package/src/node/frameworks/vue/server.ts +1 -4
- package/src/node/index.ts +14 -5
- package/src/node/plugins/quasar.ts +9 -3
- package/src/vite/vue/csr/app.ts +1 -2
- package/src/vite/vue/ssr/app.ts +1 -2
- package/src/vite/vue/ssr/entry-server.ts +7 -1
- package/src/vite/vue/ssr/fastify-ssr-plugin.ts +1 -2
- package/src/vite/vue/ssr/prerender.ts +1 -2
- package/src/vite/vue/ssr/server.ts +0 -19
package/dist/bin/cli.js
CHANGED
|
@@ -15,7 +15,7 @@ cli
|
|
|
15
15
|
.action(async (options) => {
|
|
16
16
|
const { build } = await import('./build.js');
|
|
17
17
|
let appDir;
|
|
18
|
-
let prerender
|
|
18
|
+
let prerender;
|
|
19
19
|
if (options.appDir) {
|
|
20
20
|
if (options.appDir.slice(-1) !== '/')
|
|
21
21
|
options.appDir += '/';
|
|
@@ -68,15 +68,14 @@ cli
|
|
|
68
68
|
...args,
|
|
69
69
|
outDir: new URL('ssr/server/', baseOutDir).pathname
|
|
70
70
|
});
|
|
71
|
-
({ prerender
|
|
71
|
+
({ prerender } = await import(new URL('ssr/server/prerender.mjs', baseOutDir).pathname));
|
|
72
72
|
prerender({
|
|
73
73
|
outDir: new URL('static/', baseOutDir).pathname,
|
|
74
74
|
templatePath: new URL('static/index.html', baseOutDir).pathname,
|
|
75
75
|
manifestPath: new URL('static/ssr-manifest.json', baseOutDir)
|
|
76
76
|
.pathname,
|
|
77
77
|
entryServerPath: new URL('ssr/server/entry-server.mjs', baseOutDir)
|
|
78
|
-
.pathname
|
|
79
|
-
onRenderedHooks
|
|
78
|
+
.pathname
|
|
80
79
|
});
|
|
81
80
|
break;
|
|
82
81
|
default:
|
|
@@ -134,11 +134,6 @@ const fastifySsrPlugin = async (fastify, options, done) => {
|
|
|
134
134
|
let html = template
|
|
135
135
|
.replace(`<!--preload-links-->`, preloadLinks)
|
|
136
136
|
.replace(`<!--app-html-->`, appHtml);
|
|
137
|
-
if (options.onRendered?.length) {
|
|
138
|
-
for (const ssrFunction of options.onRendered) {
|
|
139
|
-
html = ssrFunction(html, ssrContext);
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
137
|
res.code(200);
|
|
143
138
|
res.type('text/html');
|
|
144
139
|
res.send(html);
|
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
import { promises as fs } from 'fs';
|
|
2
2
|
import { routesToPaths } from '../../helpers/routes.js';
|
|
3
|
-
|
|
4
|
-
export const prerender = async ({ outDir, templatePath, manifestPath, entryServerPath, onRenderedHooks }) => {
|
|
3
|
+
export const prerender = async ({ outDir, templatePath, manifestPath, entryServerPath }) => {
|
|
5
4
|
const promises = [];
|
|
6
5
|
const template = (await fs.readFile(templatePath)).toString();
|
|
7
6
|
const manifest = await fs.readFile(manifestPath);
|
|
8
7
|
const { render, getRoutes } = await import(entryServerPath);
|
|
9
8
|
const routes = await getRoutes();
|
|
10
9
|
const paths = routesToPaths(routes).filter((i) => !i.includes(':') && !i.includes('*'));
|
|
11
|
-
const critters = new
|
|
10
|
+
const critters = new (await import('critters')).default({
|
|
12
11
|
path: outDir,
|
|
13
12
|
logLevel: 'warn',
|
|
14
13
|
external: true,
|
|
@@ -27,11 +26,6 @@ export const prerender = async ({ outDir, templatePath, manifestPath, entryServe
|
|
|
27
26
|
.replace(`<!--preload-links-->`, preloadLinks)
|
|
28
27
|
.replace(`<!--app-html-->`, appHtml);
|
|
29
28
|
html = await critters.process(html);
|
|
30
|
-
if (onRenderedHooks?.length) {
|
|
31
|
-
for (const ssrFunction of onRenderedHooks) {
|
|
32
|
-
html = ssrFunction(html, ssrContext);
|
|
33
|
-
}
|
|
34
|
-
}
|
|
35
29
|
promises.push(fs.writeFile(outDir + filename, html, 'utf-8'));
|
|
36
30
|
}
|
|
37
31
|
return Promise.all(promises);
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
import fastify from 'fastify';
|
|
2
|
-
export const createApp = ({ onSetup, appDir, baseUrl,
|
|
2
|
+
export const createApp = ({ onSetup, appDir, baseUrl, fastifyPlugin, vitrifyDir, mode }) => {
|
|
3
3
|
const app = fastify({
|
|
4
4
|
logger: true
|
|
5
5
|
});
|
|
6
6
|
app.register(fastifyPlugin, {
|
|
7
7
|
baseUrl,
|
|
8
8
|
appDir,
|
|
9
|
-
onRendered,
|
|
10
9
|
vitrifyDir,
|
|
11
10
|
mode
|
|
12
11
|
});
|
package/dist/index.js
CHANGED
|
@@ -30,7 +30,11 @@ const manualChunkNames = [
|
|
|
30
30
|
'fastify-csr-plugin',
|
|
31
31
|
'server'
|
|
32
32
|
];
|
|
33
|
-
const
|
|
33
|
+
const moduleChunks = {
|
|
34
|
+
vue: ['vue', '@vue'],
|
|
35
|
+
quasar: ['quasar']
|
|
36
|
+
};
|
|
37
|
+
const manualChunks = (id, api) => {
|
|
34
38
|
if (id.includes('vitrify/src/vite/')) {
|
|
35
39
|
const name = id.split('/').at(-1)?.split('.').at(0);
|
|
36
40
|
if (name && manualChunkNames.includes(name))
|
|
@@ -40,6 +44,9 @@ const manualChunks = (id) => {
|
|
|
40
44
|
return VIRTUAL_MODULES.find((name) => id.includes(name));
|
|
41
45
|
}
|
|
42
46
|
else if (id.includes('node_modules')) {
|
|
47
|
+
const name = Object.entries(moduleChunks).find(([chunkName, moduleNames]) => moduleNames.some((name) => id.includes(`${name}/`)));
|
|
48
|
+
if (name)
|
|
49
|
+
return name[0];
|
|
43
50
|
return 'vendor';
|
|
44
51
|
}
|
|
45
52
|
};
|
|
@@ -133,13 +140,13 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
133
140
|
console.log('No vitrify.config.(ts|js) file found, using defaults');
|
|
134
141
|
vitrifyConfig = {};
|
|
135
142
|
}
|
|
136
|
-
|
|
137
|
-
const localPackages = []
|
|
143
|
+
const localPackages = ['vue', 'vue-router', '@vue/server-renderer'];
|
|
144
|
+
// const localPackages: string[] = []
|
|
138
145
|
const cliPackages = [];
|
|
139
146
|
const packageUrls = vitrifyConfig.vitrify?.urls?.packages || {};
|
|
140
147
|
await (async () => {
|
|
141
148
|
for (const val of localPackages)
|
|
142
|
-
packageUrls[val] = getPkgJsonDir(new URL(
|
|
149
|
+
packageUrls[val] = getPkgJsonDir(new URL(resolve(val, appDir)));
|
|
143
150
|
})();
|
|
144
151
|
// await (async () => {
|
|
145
152
|
// for (const val of cliPackages)
|
|
@@ -529,3 +536,4 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
529
536
|
return mergeConfig(config, vitrifyConfig);
|
|
530
537
|
};
|
|
531
538
|
export const vitrifyDir = new URL('..', import.meta.url);
|
|
539
|
+
export { prerender } from './frameworks/vue/prerender.js';
|
package/dist/plugins/quasar.js
CHANGED
|
@@ -42,9 +42,9 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
|
|
|
42
42
|
const { ssr: transformSsr } = options || {};
|
|
43
43
|
code = code
|
|
44
44
|
.replaceAll('__QUASAR_SSR__', ssr ? 'true' : 'false')
|
|
45
|
-
.replaceAll('__QUASAR_SSR_SERVER__', 'import.meta.env.SSR')
|
|
46
|
-
.replaceAll('__QUASAR_SSR_CLIENT__', '!import.meta.env.SSR')
|
|
47
|
-
.replaceAll('__QUASAR_SSR_PWA__', pwa ? '!import.meta.env.SSR' : 'false');
|
|
45
|
+
.replaceAll('__QUASAR_SSR_SERVER__', ssr === 'server' ? 'import.meta.env.SSR' : 'false')
|
|
46
|
+
.replaceAll('__QUASAR_SSR_CLIENT__', ssr ? '!import.meta.env.SSR' : 'false')
|
|
47
|
+
.replaceAll('__QUASAR_SSR_PWA__', ssr && pwa ? '!import.meta.env.SSR' : 'false');
|
|
48
48
|
return code;
|
|
49
49
|
}
|
|
50
50
|
},
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { FastifyPluginCallback, FastifyRequest, FastifyReply } from 'fastify';
|
|
2
|
-
import type { OnRenderedHook } from '../../vitrify-config.js';
|
|
3
2
|
import type { ViteDevServer } from 'vite';
|
|
4
3
|
export interface FastifySsrOptions {
|
|
5
4
|
baseUrl?: string;
|
|
@@ -9,7 +8,6 @@ export interface FastifySsrOptions {
|
|
|
9
8
|
appDir?: URL;
|
|
10
9
|
publicDir?: URL;
|
|
11
10
|
productName?: string;
|
|
12
|
-
onRendered?: OnRenderedHook[];
|
|
13
11
|
mode?: string;
|
|
14
12
|
}
|
|
15
13
|
declare const fastifyCsrPlugin: FastifyPluginCallback<FastifySsrOptions>;
|
|
@@ -1,5 +1,4 @@
|
|
|
1
1
|
import type { FastifyPluginCallback, FastifyRequest, FastifyReply } from 'fastify';
|
|
2
|
-
import type { OnRenderedHook } from '../../vitrify-config.js';
|
|
3
2
|
import type { ViteDevServer } from 'vite';
|
|
4
3
|
export interface FastifySsrOptions {
|
|
5
4
|
baseUrl?: string;
|
|
@@ -9,7 +8,6 @@ export interface FastifySsrOptions {
|
|
|
9
8
|
appDir?: URL;
|
|
10
9
|
publicDir?: URL;
|
|
11
10
|
productName?: string;
|
|
12
|
-
onRendered?: OnRenderedHook[];
|
|
13
11
|
mode?: string;
|
|
14
12
|
}
|
|
15
13
|
declare const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions>;
|
|
@@ -1,8 +1,6 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const prerender: ({ outDir, templatePath, manifestPath, entryServerPath, onRenderedHooks }: {
|
|
1
|
+
export declare const prerender: ({ outDir, templatePath, manifestPath, entryServerPath }: {
|
|
3
2
|
outDir: string;
|
|
4
3
|
templatePath: string;
|
|
5
4
|
manifestPath: string;
|
|
6
5
|
entryServerPath: string;
|
|
7
|
-
onRenderedHooks: OnRenderedHook[];
|
|
8
6
|
}) => Promise<void[]>;
|
|
@@ -1,13 +1,12 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import type { FastifyInstance } from 'fastify';
|
|
3
|
-
import type {
|
|
3
|
+
import type { 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,
|
|
6
|
+
export declare const createApp: ({ onSetup, appDir, baseUrl, fastifyPlugin, vitrifyDir, mode }: {
|
|
7
7
|
onSetup: OnSetupFile[];
|
|
8
8
|
appDir: URL;
|
|
9
9
|
baseUrl?: string | undefined;
|
|
10
|
-
onRendered?: OnRenderedHook[] | undefined;
|
|
11
10
|
fastifyPlugin: FastifySsrPlugin | FastifyCsrPlugin;
|
|
12
11
|
vitrifyDir?: URL | undefined;
|
|
13
12
|
mode: string;
|
package/dist/types/index.d.ts
CHANGED
|
@@ -15,4 +15,5 @@ export declare const baseConfig: ({ ssr, appDir, publicDir, base, command, mode,
|
|
|
15
15
|
debug?: boolean | undefined;
|
|
16
16
|
}) => Promise<InlineConfig>;
|
|
17
17
|
export declare const vitrifyDir: URL;
|
|
18
|
+
export { prerender } from './frameworks/vue/prerender.js';
|
|
18
19
|
export type { VitrifyConfig, VitrifyPlugin, VitrifyContext, BootFunction };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitrify",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.1",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Stefan van Herwijnen",
|
|
6
6
|
"description": "Pre-configured Vite CLI for your framework",
|
|
@@ -56,6 +56,7 @@
|
|
|
56
56
|
"@fastify/static": "^6.4.0",
|
|
57
57
|
"@quasar/extras": "^1.14.1",
|
|
58
58
|
"@vitejs/plugin-vue": "^3.0.0-alpha.1",
|
|
59
|
+
"@vue/server-renderer": "^3.2.37",
|
|
59
60
|
"builtin-modules": "^3.3.0",
|
|
60
61
|
"cac": "^6.7.12",
|
|
61
62
|
"chalk": "^5.0.1",
|
package/src/node/bin/cli.ts
CHANGED
|
@@ -24,7 +24,7 @@ cli
|
|
|
24
24
|
.action(async (options) => {
|
|
25
25
|
const { build } = await import('./build.js')
|
|
26
26
|
let appDir: URL
|
|
27
|
-
let prerender
|
|
27
|
+
let prerender
|
|
28
28
|
if (options.appDir) {
|
|
29
29
|
if (options.appDir.slice(-1) !== '/') options.appDir += '/'
|
|
30
30
|
appDir = new URL(`file://${options.appDir}`)
|
|
@@ -84,7 +84,7 @@ cli
|
|
|
84
84
|
...args,
|
|
85
85
|
outDir: new URL('ssr/server/', baseOutDir).pathname
|
|
86
86
|
})
|
|
87
|
-
;({ prerender
|
|
87
|
+
;({ prerender } = await import(
|
|
88
88
|
new URL('ssr/server/prerender.mjs', baseOutDir).pathname
|
|
89
89
|
))
|
|
90
90
|
prerender({
|
|
@@ -93,8 +93,7 @@ cli
|
|
|
93
93
|
manifestPath: new URL('static/ssr-manifest.json', baseOutDir)
|
|
94
94
|
.pathname,
|
|
95
95
|
entryServerPath: new URL('ssr/server/entry-server.mjs', baseOutDir)
|
|
96
|
-
.pathname
|
|
97
|
-
onRenderedHooks
|
|
96
|
+
.pathname
|
|
98
97
|
})
|
|
99
98
|
break
|
|
100
99
|
default:
|
|
@@ -4,7 +4,6 @@ import type {
|
|
|
4
4
|
FastifyReply
|
|
5
5
|
} from 'fastify'
|
|
6
6
|
import fastifyStatic from '@fastify/static'
|
|
7
|
-
import type { OnRenderedHook } from '../../vitrify-config.js'
|
|
8
7
|
import type { ViteDevServer } from 'vite'
|
|
9
8
|
|
|
10
9
|
export interface FastifySsrOptions {
|
|
@@ -19,7 +18,6 @@ export interface FastifySsrOptions {
|
|
|
19
18
|
appDir?: URL
|
|
20
19
|
publicDir?: URL
|
|
21
20
|
productName?: string
|
|
22
|
-
onRendered?: OnRenderedHook[]
|
|
23
21
|
mode?: string
|
|
24
22
|
}
|
|
25
23
|
|
|
@@ -5,7 +5,6 @@ import type {
|
|
|
5
5
|
} from 'fastify'
|
|
6
6
|
import fastifyStatic from '@fastify/static'
|
|
7
7
|
import { readFileSync } from 'fs'
|
|
8
|
-
import type { OnRenderedHook } from '../../vitrify-config.js'
|
|
9
8
|
import { componentsModules, collectCss } from '../../helpers/collect-css-ssr.js'
|
|
10
9
|
import type { ViteDevServer } from 'vite'
|
|
11
10
|
|
|
@@ -21,7 +20,6 @@ export interface FastifySsrOptions {
|
|
|
21
20
|
appDir?: URL
|
|
22
21
|
publicDir?: URL
|
|
23
22
|
productName?: string
|
|
24
|
-
onRendered?: OnRenderedHook[]
|
|
25
23
|
mode?: string
|
|
26
24
|
}
|
|
27
25
|
|
|
@@ -189,12 +187,6 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
|
|
|
189
187
|
.replace(`<!--preload-links-->`, preloadLinks)
|
|
190
188
|
.replace(`<!--app-html-->`, appHtml)
|
|
191
189
|
|
|
192
|
-
if (options.onRendered?.length) {
|
|
193
|
-
for (const ssrFunction of options.onRendered) {
|
|
194
|
-
html = ssrFunction(html, ssrContext)
|
|
195
|
-
}
|
|
196
|
-
}
|
|
197
|
-
|
|
198
190
|
res.code(200)
|
|
199
191
|
res.type('text/html')
|
|
200
192
|
res.send(html)
|
|
@@ -1,20 +1,16 @@
|
|
|
1
1
|
import { promises as fs } from 'fs'
|
|
2
2
|
import { routesToPaths } from '../../helpers/routes.js'
|
|
3
|
-
import type { OnRenderedHook } from '../../vitrify-config.js'
|
|
4
|
-
import Critters from 'critters'
|
|
5
3
|
|
|
6
4
|
export const prerender = async ({
|
|
7
5
|
outDir,
|
|
8
6
|
templatePath,
|
|
9
7
|
manifestPath,
|
|
10
|
-
entryServerPath
|
|
11
|
-
onRenderedHooks
|
|
8
|
+
entryServerPath
|
|
12
9
|
}: {
|
|
13
10
|
outDir: string
|
|
14
11
|
templatePath: string
|
|
15
12
|
manifestPath: string
|
|
16
13
|
entryServerPath: string
|
|
17
|
-
onRenderedHooks: OnRenderedHook[]
|
|
18
14
|
}) => {
|
|
19
15
|
const promises = []
|
|
20
16
|
const template = (await fs.readFile(templatePath)).toString()
|
|
@@ -24,7 +20,7 @@ export const prerender = async ({
|
|
|
24
20
|
const paths = routesToPaths(routes).filter(
|
|
25
21
|
(i) => !i.includes(':') && !i.includes('*')
|
|
26
22
|
)
|
|
27
|
-
const critters = new
|
|
23
|
+
const critters = new (await import('critters')).default({
|
|
28
24
|
path: outDir,
|
|
29
25
|
logLevel: 'warn',
|
|
30
26
|
external: true,
|
|
@@ -47,12 +43,6 @@ export const prerender = async ({
|
|
|
47
43
|
|
|
48
44
|
html = await critters.process(html)
|
|
49
45
|
|
|
50
|
-
if (onRenderedHooks?.length) {
|
|
51
|
-
for (const ssrFunction of onRenderedHooks) {
|
|
52
|
-
html = ssrFunction(html, ssrContext)
|
|
53
|
-
}
|
|
54
|
-
}
|
|
55
|
-
|
|
56
46
|
promises.push(fs.writeFile(outDir + filename, html, 'utf-8'))
|
|
57
47
|
}
|
|
58
48
|
return Promise.all(promises)
|
|
@@ -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 {
|
|
5
|
+
import type { 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
|
|
|
@@ -10,7 +10,6 @@ export const createApp = ({
|
|
|
10
10
|
onSetup,
|
|
11
11
|
appDir,
|
|
12
12
|
baseUrl,
|
|
13
|
-
onRendered,
|
|
14
13
|
fastifyPlugin,
|
|
15
14
|
vitrifyDir,
|
|
16
15
|
mode
|
|
@@ -18,7 +17,6 @@ export const createApp = ({
|
|
|
18
17
|
onSetup: OnSetupFile[]
|
|
19
18
|
appDir: URL
|
|
20
19
|
baseUrl?: string
|
|
21
|
-
onRendered?: OnRenderedHook[]
|
|
22
20
|
fastifyPlugin: FastifySsrPlugin | FastifyCsrPlugin
|
|
23
21
|
vitrifyDir?: URL
|
|
24
22
|
mode: string
|
|
@@ -30,7 +28,6 @@ export const createApp = ({
|
|
|
30
28
|
app.register(fastifyPlugin, {
|
|
31
29
|
baseUrl,
|
|
32
30
|
appDir,
|
|
33
|
-
onRendered,
|
|
34
31
|
vitrifyDir,
|
|
35
32
|
mode
|
|
36
33
|
})
|
package/src/node/index.ts
CHANGED
|
@@ -48,7 +48,12 @@ const manualChunkNames = [
|
|
|
48
48
|
'fastify-csr-plugin',
|
|
49
49
|
'server'
|
|
50
50
|
]
|
|
51
|
-
|
|
51
|
+
|
|
52
|
+
const moduleChunks = {
|
|
53
|
+
vue: ['vue', '@vue'],
|
|
54
|
+
quasar: ['quasar']
|
|
55
|
+
}
|
|
56
|
+
const manualChunks: ManualChunksOption = (id, api) => {
|
|
52
57
|
if (id.includes('vitrify/src/vite/')) {
|
|
53
58
|
const name = id.split('/').at(-1)?.split('.').at(0)
|
|
54
59
|
if (name && manualChunkNames.includes(name)) return name
|
|
@@ -57,6 +62,10 @@ const manualChunks: ManualChunksOption = (id: string) => {
|
|
|
57
62
|
) {
|
|
58
63
|
return VIRTUAL_MODULES.find((name) => id.includes(name))
|
|
59
64
|
} else if (id.includes('node_modules')) {
|
|
65
|
+
const name = Object.entries(moduleChunks).find(([chunkName, moduleNames]) =>
|
|
66
|
+
moduleNames.some((name) => id.includes(`${name}/`))
|
|
67
|
+
)
|
|
68
|
+
if (name) return name[0]
|
|
60
69
|
return 'vendor'
|
|
61
70
|
}
|
|
62
71
|
}
|
|
@@ -195,14 +204,14 @@ export const baseConfig = async ({
|
|
|
195
204
|
vitrifyConfig = {}
|
|
196
205
|
}
|
|
197
206
|
|
|
198
|
-
|
|
199
|
-
const localPackages: string[] = []
|
|
207
|
+
const localPackages = ['vue', 'vue-router', '@vue/server-renderer']
|
|
208
|
+
// const localPackages: string[] = []
|
|
200
209
|
const cliPackages = []
|
|
201
210
|
const packageUrls: Record<string, URL> =
|
|
202
211
|
vitrifyConfig.vitrify?.urls?.packages || {}
|
|
203
212
|
await (async () => {
|
|
204
213
|
for (const val of localPackages)
|
|
205
|
-
packageUrls[val] = getPkgJsonDir(new URL(
|
|
214
|
+
packageUrls[val] = getPkgJsonDir(new URL(resolve(val, appDir)))
|
|
206
215
|
})()
|
|
207
216
|
|
|
208
217
|
// await (async () => {
|
|
@@ -613,5 +622,5 @@ export const baseConfig = async ({
|
|
|
613
622
|
}
|
|
614
623
|
|
|
615
624
|
export const vitrifyDir = new URL('..', import.meta.url)
|
|
616
|
-
|
|
625
|
+
export { prerender } from './frameworks/vue/prerender.js'
|
|
617
626
|
export type { VitrifyConfig, VitrifyPlugin, VitrifyContext, BootFunction }
|
|
@@ -93,11 +93,17 @@ export const QuasarPlugin: VitrifyPlugin = async ({
|
|
|
93
93
|
const { ssr: transformSsr } = options || {}
|
|
94
94
|
code = code
|
|
95
95
|
.replaceAll('__QUASAR_SSR__', ssr ? 'true' : 'false')
|
|
96
|
-
.replaceAll(
|
|
97
|
-
|
|
96
|
+
.replaceAll(
|
|
97
|
+
'__QUASAR_SSR_SERVER__',
|
|
98
|
+
ssr === 'server' ? 'import.meta.env.SSR' : 'false'
|
|
99
|
+
)
|
|
100
|
+
.replaceAll(
|
|
101
|
+
'__QUASAR_SSR_CLIENT__',
|
|
102
|
+
ssr ? '!import.meta.env.SSR' : 'false'
|
|
103
|
+
)
|
|
98
104
|
.replaceAll(
|
|
99
105
|
'__QUASAR_SSR_PWA__',
|
|
100
|
-
pwa ? '!import.meta.env.SSR' : 'false'
|
|
106
|
+
ssr && pwa ? '!import.meta.env.SSR' : 'false'
|
|
101
107
|
)
|
|
102
108
|
|
|
103
109
|
return code
|
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 { onSetup } from 'virtual:vitrify-hooks'
|
|
5
5
|
import { fastifyCsrPlugin } from './fastify-csr-plugin.js'
|
|
6
6
|
import type { ViteDevServer } from 'vite'
|
|
7
7
|
|
|
@@ -16,7 +16,6 @@ export const setupApp = async () => {
|
|
|
16
16
|
onSetup,
|
|
17
17
|
appDir,
|
|
18
18
|
baseUrl,
|
|
19
|
-
onRendered,
|
|
20
19
|
fastifyPlugin: fastifyCsrPlugin,
|
|
21
20
|
// vitrifyDir,
|
|
22
21
|
mode: import.meta.env.MODE
|
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 {
|
|
4
|
+
import { onSetup } from 'virtual:vitrify-hooks'
|
|
5
5
|
import { fastifySsrPlugin } from './fastify-ssr-plugin.js'
|
|
6
6
|
import type { ViteDevServer } from 'vite'
|
|
7
7
|
|
|
@@ -16,7 +16,6 @@ export const setupApp = async () => {
|
|
|
16
16
|
onSetup,
|
|
17
17
|
appDir,
|
|
18
18
|
baseUrl,
|
|
19
|
-
onRendered,
|
|
20
19
|
fastifyPlugin: fastifySsrPlugin,
|
|
21
20
|
// vitrifyDir,
|
|
22
21
|
mode: import.meta.env.MODE
|
|
@@ -5,7 +5,7 @@ import type { FastifyInstance } from 'fastify'
|
|
|
5
5
|
// import { ApolloClients } from '@vue/apollo-composable'
|
|
6
6
|
// import serialize from 'serialize-javascript'
|
|
7
7
|
|
|
8
|
-
import { onSetup } from 'virtual:vitrify-hooks'
|
|
8
|
+
import { onSetup, onRendered } from 'virtual:vitrify-hooks'
|
|
9
9
|
|
|
10
10
|
export const setup = async ({ fastify }: { fastify: FastifyInstance }) => {
|
|
11
11
|
if (onSetup?.length) {
|
|
@@ -67,6 +67,12 @@ export async function render(url, manifest, ssrContext) {
|
|
|
67
67
|
// request.
|
|
68
68
|
const preloadLinks = renderPreloadLinks(ctx.modules, manifest)
|
|
69
69
|
|
|
70
|
+
if (onRendered?.length) {
|
|
71
|
+
for (const ssrFunction of onRendered) {
|
|
72
|
+
html = ssrFunction(html, ssrContext)
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
|
|
70
76
|
return [html, preloadLinks]
|
|
71
77
|
}
|
|
72
78
|
|
|
@@ -1,23 +1,4 @@
|
|
|
1
|
-
// import { createApp } from '../../../node/frameworks/vue/server.js'
|
|
2
|
-
// import { getAppDir } from '../../../node/app-urls.js'
|
|
3
|
-
// import { setup } from 'virtual:fastify-setup'
|
|
4
|
-
// import { onRendered, onSetup } from 'virtual:vitrify-hooks'
|
|
5
|
-
// import { fastifySsrPlugin } from './fastify-ssr-plugin.js'
|
|
6
1
|
import { setupApp } from './app.js'
|
|
7
|
-
// import * as staticImports from 'virtual:static-imports'
|
|
8
|
-
// const appDir = getPkgJsonDir(import.meta.url)
|
|
9
|
-
// const getString = (str?: string) => str
|
|
10
|
-
// let baseUrl = getString(__BASE_URL__)
|
|
11
|
-
// const appDir = getAppDir()
|
|
12
|
-
|
|
13
|
-
// const app = createApp({
|
|
14
|
-
// onSetup,
|
|
15
|
-
// appDir,
|
|
16
|
-
// baseUrl,
|
|
17
|
-
// onRendered,
|
|
18
|
-
// fastifySsrPlugin,
|
|
19
|
-
// mode: import.meta.env.MODE
|
|
20
|
-
// })
|
|
21
2
|
|
|
22
3
|
const app = await setupApp()
|
|
23
4
|
|