vitrify 0.24.2 → 0.25.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/README.md +7 -22
- package/dist/index.js +66 -12
- package/dist/plugins/quasar/index.js +2 -2
- package/dist/types/hooks/index.d.ts +2 -2
- package/dist/types/index.d.ts +2 -2
- package/dist/types/vitrify-config.d.ts +23 -11
- package/package.json +1 -1
- package/src/node/hooks/index.ts +12 -6
- package/src/node/index.ts +89 -24
- package/src/node/plugins/pinia/index.ts +3 -3
- package/src/node/plugins/quasar/index.ts +4 -4
- package/src/node/vitrify-config.ts +25 -18
- package/src/vite/vue/main.ts +4 -4
package/README.md
CHANGED
|
@@ -1,19 +1,5 @@
|
|
|
1
1
|
# Vitrify
|
|
2
2
|
|
|
3
|
-
> Vite as your Full Stack development tool
|
|
4
|
-
|
|
5
|
-
- Use a simple configuration file to configure and integrate required Vite plugins into your project.
|
|
6
|
-
- Client-Side Rendering (CSR), Server-Side Rendering (SSR), Static Site Generation (SSG) and Fastify server build and development modes.
|
|
7
|
-
- Run both your frontend- and backend code through Vite at development and build time.
|
|
8
|
-
|
|
9
|
-
## Features
|
|
10
|
-
|
|
11
|
-
- Uses [Fastify](https://github.com/fastify/fastify-vite) for the development server and SSR production server.
|
|
12
|
-
- Generates a Fastify plugin to serve your server-side rendered application.
|
|
13
|
-
- A [`run`](./src/node/bin/run.ts) command which injects context such as application paths into the script which you want to run.
|
|
14
|
-
- A [`test`](./src/node/bin/test.ts) command which runs a pre-configured [Vitest](https://github.com/vitest-dev/vitest) instance.
|
|
15
|
-
- An [extra plugin layer](./src/node/plugins/index.ts) which provides some extra context such as the SSR mode (client or server) and PWA mode. Used for UI frameworks which render differently based on these settings.
|
|
16
|
-
|
|
17
3
|
## Commands
|
|
18
4
|
|
|
19
5
|
### build
|
|
@@ -83,15 +69,14 @@ Options:
|
|
|
83
69
|
end
|
|
84
70
|
merge-- mode: fastify -->frameworkFastify{Load framework entrypoints from fastify/...};
|
|
85
71
|
merge-- mode: csr/ssr/ssg -->framework{Load framework entrypoints from vite/...};
|
|
86
|
-
frameworkFastify-->
|
|
87
|
-
|
|
88
|
-
fastifySetup{onSetup / onRendered}-->fastifyDev
|
|
89
|
-
fastifySetup{onSetup / onRendered}-->fastifyBuild
|
|
90
|
-
framework-->build{Build the application};
|
|
72
|
+
frameworkFastify-->fastifySetup{onSetup / onRendered};
|
|
73
|
+
fastifySetup-->frameworkSetup;
|
|
91
74
|
build-- mode: ssg -->prerender{Run prerender.js}
|
|
92
|
-
framework-->
|
|
93
|
-
frameworkSetup{
|
|
94
|
-
|
|
75
|
+
framework-->frameworkSetup{onAppCreated / onMounted}
|
|
76
|
+
frameworkSetup-->frameworkOnRendered{onRendered};
|
|
77
|
+
frameworkOnRendered-->frameworkOnTemplateRendered{onTemplateRendered};
|
|
78
|
+
frameworkOnTemplateRendered-->build{Build the application};
|
|
79
|
+
frameworkOnTemplateRendered-->dev{Start dev server};
|
|
95
80
|
node/bin/test.ts-->test{Run a pre-configured Vitest instance};
|
|
96
81
|
node/bin/run.ts-->run{Inject context into script and run script};
|
|
97
82
|
```
|
package/dist/index.js
CHANGED
|
@@ -207,11 +207,14 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
207
207
|
}
|
|
208
208
|
}
|
|
209
209
|
}
|
|
210
|
-
let onBootHooks;
|
|
211
210
|
let onRenderedHooks;
|
|
211
|
+
let onRenderedFiles;
|
|
212
212
|
let onTemplateRenderedHooks;
|
|
213
|
+
let onTemplateRenderedFiles;
|
|
213
214
|
let onAppMountedHooks;
|
|
214
|
-
let
|
|
215
|
+
let onAppMountedFiles;
|
|
216
|
+
let OnAppCreatedHooks;
|
|
217
|
+
let onAppCreatedFiles;
|
|
215
218
|
let onSetupFiles;
|
|
216
219
|
let globalCss = [];
|
|
217
220
|
let staticImports;
|
|
@@ -270,12 +273,16 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
270
273
|
name: 'vitrify-setup',
|
|
271
274
|
enforce: 'post',
|
|
272
275
|
config: (config, env) => {
|
|
273
|
-
onBootHooks = config.vitrify?.hooks?.onBoot || [];
|
|
274
276
|
onRenderedHooks = config.vitrify?.hooks?.onRendered || [];
|
|
277
|
+
onRenderedFiles = config.vitrify?.hooks?.onRenderedFiles || [];
|
|
275
278
|
onTemplateRenderedHooks =
|
|
276
279
|
config.vitrify?.hooks?.onTemplateRendered || [];
|
|
280
|
+
onTemplateRenderedFiles =
|
|
281
|
+
config.vitrify?.hooks?.onTemplateRenderedFiles || [];
|
|
277
282
|
onAppMountedHooks = config.vitrify?.hooks?.onAppMounted || [];
|
|
278
|
-
|
|
283
|
+
onAppMountedFiles = config.vitrify?.hooks?.onAppMountedFiles || [];
|
|
284
|
+
OnAppCreatedHooks = config.vitrify?.hooks?.onAppCreated || [];
|
|
285
|
+
onAppCreatedFiles = config.vitrify?.hooks?.onAppCreatedFiles || [];
|
|
279
286
|
onSetupFiles = config?.vitrify?.hooks?.onSetup || [];
|
|
280
287
|
globalCss = config.vitrify?.globalCss || [];
|
|
281
288
|
staticImports = config.vitrify?.staticImports || {};
|
|
@@ -306,21 +313,68 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
306
313
|
},
|
|
307
314
|
load(id) {
|
|
308
315
|
if (id === 'virtual:vitrify-hooks') {
|
|
309
|
-
return `export const
|
|
310
|
-
.map((fn) => `${String(fn)}`)
|
|
311
|
-
.join(', ')}]
|
|
312
|
-
export const onAppMounted = [${onAppMountedHooks
|
|
316
|
+
return `export const onAppMounted = [${onAppMountedHooks
|
|
313
317
|
.map((fn) => `${String(fn)}`)
|
|
314
318
|
.join(', ')}]
|
|
319
|
+
${onAppMountedFiles
|
|
320
|
+
.map((url, index) => {
|
|
321
|
+
const varName = fileURLToPath(url)
|
|
322
|
+
.replaceAll('/', '')
|
|
323
|
+
.replaceAll(':', '')
|
|
324
|
+
.replaceAll('\\', '')
|
|
325
|
+
.replaceAll('.', '')
|
|
326
|
+
.replaceAll('-', '')
|
|
327
|
+
.replaceAll('_', '')
|
|
328
|
+
.replaceAll('+', '');
|
|
329
|
+
return `import ${varName} from '${new URL(url, appDir).pathname}'; onAppMounted.push(${varName});`;
|
|
330
|
+
})
|
|
331
|
+
.join('\n')}
|
|
315
332
|
export const onRendered = [${onRenderedHooks
|
|
316
333
|
.map((fn) => `${String(fn)}`)
|
|
317
334
|
.join(', ')}]
|
|
335
|
+
${onRenderedFiles
|
|
336
|
+
.map((url, index) => {
|
|
337
|
+
const varName = fileURLToPath(url)
|
|
338
|
+
.replaceAll('/', '')
|
|
339
|
+
.replaceAll(':', '')
|
|
340
|
+
.replaceAll('\\', '')
|
|
341
|
+
.replaceAll('.', '')
|
|
342
|
+
.replaceAll('-', '')
|
|
343
|
+
.replaceAll('_', '')
|
|
344
|
+
.replaceAll('+', '');
|
|
345
|
+
return `import ${varName} from '${new URL(url, appDir).pathname}'; onRendered.push(${varName});`;
|
|
346
|
+
})
|
|
347
|
+
.join('\n')}
|
|
318
348
|
export const onTemplateRendered = [${onTemplateRenderedHooks
|
|
319
349
|
.map((fn) => `${String(fn)}`)
|
|
320
350
|
.join(', ')}]
|
|
321
|
-
|
|
322
|
-
.map((
|
|
323
|
-
|
|
351
|
+
${onTemplateRenderedFiles
|
|
352
|
+
.map((url, index) => {
|
|
353
|
+
const varName = fileURLToPath(url)
|
|
354
|
+
.replaceAll('/', '')
|
|
355
|
+
.replaceAll(':', '')
|
|
356
|
+
.replaceAll('\\', '')
|
|
357
|
+
.replaceAll('.', '')
|
|
358
|
+
.replaceAll('-', '')
|
|
359
|
+
.replaceAll('_', '')
|
|
360
|
+
.replaceAll('+', '');
|
|
361
|
+
return `import ${varName} from '${new URL(url, appDir).pathname}'; onTemplateRendered.push(${varName});`;
|
|
362
|
+
})
|
|
363
|
+
.join('\n')}
|
|
364
|
+
export const onAppCreated = [${OnAppCreatedHooks.map((fn) => `${String(fn)}`).join(', ')}]
|
|
365
|
+
${onAppCreatedFiles
|
|
366
|
+
.map((url, index) => {
|
|
367
|
+
const varName = fileURLToPath(url)
|
|
368
|
+
.replaceAll('/', '')
|
|
369
|
+
.replaceAll(':', '')
|
|
370
|
+
.replaceAll('\\', '')
|
|
371
|
+
.replaceAll('.', '')
|
|
372
|
+
.replaceAll('-', '')
|
|
373
|
+
.replaceAll('_', '')
|
|
374
|
+
.replaceAll('+', '');
|
|
375
|
+
return `import ${varName} from '${new URL(url, appDir).pathname}'; onAppCreated.push(${varName});`;
|
|
376
|
+
})
|
|
377
|
+
.join('\n')}
|
|
324
378
|
export const onSetup = []
|
|
325
379
|
${onSetupFiles
|
|
326
380
|
.map((url, index) => {
|
|
@@ -332,7 +386,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
332
386
|
.replaceAll('-', '')
|
|
333
387
|
.replaceAll('_', '')
|
|
334
388
|
.replaceAll('+', '');
|
|
335
|
-
return `import ${varName} from '${new URL(url, appDir).pathname}'; onSetup.push(${varName})
|
|
389
|
+
return `import ${varName} from '${new URL(url, appDir).pathname}'; onSetup.push(${varName});`;
|
|
336
390
|
})
|
|
337
391
|
.join('\n')}`;
|
|
338
392
|
}
|
|
@@ -69,7 +69,7 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false, options }) => {
|
|
|
69
69
|
$q.onSSRHydrated();
|
|
70
70
|
}
|
|
71
71
|
];
|
|
72
|
-
const
|
|
72
|
+
const onAppCreatedHooks = [
|
|
73
73
|
async ({ app, ssrContext, staticImports }) => {
|
|
74
74
|
// @ts-expect-error undefined
|
|
75
75
|
const quasarPlugins = await import('virtual:quasar-plugins');
|
|
@@ -117,7 +117,7 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false, options }) => {
|
|
|
117
117
|
quasar: ['Quasar']
|
|
118
118
|
},
|
|
119
119
|
hooks: {
|
|
120
|
-
|
|
120
|
+
onAppCreated: onAppCreatedHooks,
|
|
121
121
|
onAppMounted: onAppMountedHooks,
|
|
122
122
|
onTemplateRendered: [injectSsrContext]
|
|
123
123
|
},
|
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
import type {
|
|
2
|
-
export {
|
|
1
|
+
import type { OnAppCreatedHook, OnAppCreatedHookFile, OnAppMountedHook, OnAppMountedHookFile, OnRenderedHook, OnRenderedHookFile, OnTemplateRenderedHook, OnTemplateRenderedHookFile, OnSetupHookFile, OnSetupHook } from '../vitrify-config.js';
|
|
2
|
+
export { OnAppCreatedHook, OnAppCreatedHookFile, OnAppMountedHook, OnAppMountedHookFile, OnRenderedHook, OnRenderedHookFile, OnTemplateRenderedHook, OnTemplateRenderedHookFile, OnSetupHookFile, OnSetupHook };
|
package/dist/types/index.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { InlineConfig } from 'vite';
|
|
2
|
-
import type { VitrifyConfig, VitrifyConfigAsync, VitrifyCommands, VitrifyModes, VitrifyUIFrameworks, VitrifySSRModes
|
|
2
|
+
import type { VitrifyConfig, VitrifyConfigAsync, VitrifyCommands, VitrifyModes, VitrifyUIFrameworks, VitrifySSRModes } from './vitrify-config.js';
|
|
3
3
|
import type { VitrifyContext } from './bin/run.js';
|
|
4
4
|
import type { VitrifyPlugin } from './plugins/index.js';
|
|
5
5
|
export declare const VIRTUAL_MODULES: string[];
|
|
@@ -16,4 +16,4 @@ export declare const baseConfig: ({ ssr, appDir, publicDir, base, command, mode,
|
|
|
16
16
|
}) => Promise<InlineConfig>;
|
|
17
17
|
export declare const vitrifyDir: URL;
|
|
18
18
|
export { prerender } from './frameworks/vue/prerender.js';
|
|
19
|
-
export type { VitrifyConfig, VitrifyConfigAsync, VitrifyPlugin, VitrifyContext
|
|
19
|
+
export type { VitrifyConfig, VitrifyConfigAsync, VitrifyPlugin, VitrifyContext };
|
|
@@ -38,7 +38,8 @@ export type SSRContext = {
|
|
|
38
38
|
transports?: Record<string, unknown>;
|
|
39
39
|
[key: string]: unknown;
|
|
40
40
|
};
|
|
41
|
-
export type
|
|
41
|
+
export type OnAppCreatedHookFile = URL;
|
|
42
|
+
export type OnAppCreatedHook = ({ app, router, ctx, initialState, ssrContext, staticImports }: {
|
|
42
43
|
app: App;
|
|
43
44
|
router: Router;
|
|
44
45
|
ctx: {
|
|
@@ -52,17 +53,14 @@ export type onAppCreatedHook = ({ app, router, ctx, initialState, ssrContext }:
|
|
|
52
53
|
[key: string]: unknown;
|
|
53
54
|
};
|
|
54
55
|
ssrContext?: SSRContext;
|
|
55
|
-
}) => Promise<void> | void;
|
|
56
|
-
export type OnBootHook = ({ app, ssrContext, staticImports }: {
|
|
57
|
-
app: App;
|
|
58
|
-
ssrContext: SSRContext;
|
|
59
56
|
staticImports?: Record<string, any>;
|
|
60
57
|
}) => Promise<void> | void;
|
|
58
|
+
export type OnAppMountedHookFile = URL;
|
|
61
59
|
export type OnAppMountedHook = ({ instance }: {
|
|
62
60
|
instance: ComponentInternalInstance;
|
|
63
61
|
}) => Promise<void> | void;
|
|
64
62
|
export type StaticImports = Record<string, string[]>;
|
|
65
|
-
export type
|
|
63
|
+
export type OnSetupHookFile = URL;
|
|
66
64
|
export type OnSetupHook = (fastify: FastifyInstance, options?: {
|
|
67
65
|
vite?: ViteDevServer;
|
|
68
66
|
}) => any;
|
|
@@ -71,10 +69,12 @@ export type Render = (url: string, manifest: Record<string, unknown>, ssrContext
|
|
|
71
69
|
preloadLinks: string;
|
|
72
70
|
app: App;
|
|
73
71
|
}>;
|
|
72
|
+
export type OnRenderedHookFile = URL;
|
|
74
73
|
export type OnRenderedHook = ({ app, ssrContext }: {
|
|
75
74
|
app: App;
|
|
76
75
|
ssrContext?: SSRContext;
|
|
77
76
|
}) => Promise<void> | void;
|
|
77
|
+
export type OnTemplateRenderedHookFile = URL;
|
|
78
78
|
export type OnTemplateRenderedHook = ({ html, ssrContext }: {
|
|
79
79
|
html: string;
|
|
80
80
|
ssrContext?: SSRContext;
|
|
@@ -98,27 +98,39 @@ export interface VitrifyConfig extends ViteUserConfig {
|
|
|
98
98
|
/**
|
|
99
99
|
* setup() is called directly after instantiating fastify. Use it to register your own plugins, routes etc.
|
|
100
100
|
*/
|
|
101
|
-
onSetup?:
|
|
101
|
+
onSetup?: OnSetupHookFile[];
|
|
102
|
+
/**
|
|
103
|
+
* Functions which run directly after initializing the application
|
|
104
|
+
*/
|
|
105
|
+
onAppCreated?: OnAppCreatedHook[];
|
|
106
|
+
/**
|
|
107
|
+
* Functions which run directly after initializing the application
|
|
108
|
+
*/
|
|
109
|
+
onAppCreatedFiles?: OnAppCreatedHookFile[];
|
|
102
110
|
/**
|
|
103
111
|
* Functions which run in the onMounted hook of the app
|
|
104
112
|
*/
|
|
105
113
|
onAppMounted?: OnAppMountedHook[];
|
|
106
114
|
/**
|
|
107
|
-
*
|
|
115
|
+
* Files with functions which run in the onMounted hook of the app
|
|
108
116
|
*/
|
|
109
|
-
|
|
117
|
+
onAppMountedFiles?: OnAppMountedHookFile[];
|
|
110
118
|
/**
|
|
111
119
|
* Functions which run after rendering the app (SSR)
|
|
112
120
|
*/
|
|
113
121
|
onRendered?: OnRenderedHook[];
|
|
122
|
+
/**
|
|
123
|
+
* Files with functions which run after rendering the app (SSR)
|
|
124
|
+
*/
|
|
125
|
+
onRenderedFiles?: OnRenderedHookFile[];
|
|
114
126
|
/**
|
|
115
127
|
* Functions which run after rendering the template (SSR)
|
|
116
128
|
*/
|
|
117
129
|
onTemplateRendered?: OnTemplateRenderedHook[];
|
|
118
130
|
/**
|
|
119
|
-
*
|
|
131
|
+
* Files with functions which run after rendering the template (SSR)
|
|
120
132
|
*/
|
|
121
|
-
|
|
133
|
+
onTemplateRenderedFiles?: OnTemplateRenderedHookFile[];
|
|
122
134
|
};
|
|
123
135
|
/**
|
|
124
136
|
* Global SASS variables
|
package/package.json
CHANGED
package/src/node/hooks/index.ts
CHANGED
|
@@ -1,19 +1,25 @@
|
|
|
1
1
|
import type {
|
|
2
|
-
|
|
3
|
-
|
|
2
|
+
OnAppCreatedHook,
|
|
3
|
+
OnAppCreatedHookFile,
|
|
4
4
|
OnAppMountedHook,
|
|
5
|
+
OnAppMountedHookFile,
|
|
5
6
|
OnRenderedHook,
|
|
7
|
+
OnRenderedHookFile,
|
|
6
8
|
OnTemplateRenderedHook,
|
|
7
|
-
|
|
9
|
+
OnTemplateRenderedHookFile,
|
|
10
|
+
OnSetupHookFile,
|
|
8
11
|
OnSetupHook
|
|
9
12
|
} from '../vitrify-config.js'
|
|
10
13
|
|
|
11
14
|
export {
|
|
12
|
-
|
|
13
|
-
|
|
15
|
+
OnAppCreatedHook,
|
|
16
|
+
OnAppCreatedHookFile,
|
|
14
17
|
OnAppMountedHook,
|
|
18
|
+
OnAppMountedHookFile,
|
|
15
19
|
OnRenderedHook,
|
|
20
|
+
OnRenderedHookFile,
|
|
16
21
|
OnTemplateRenderedHook,
|
|
17
|
-
|
|
22
|
+
OnTemplateRenderedHookFile,
|
|
23
|
+
OnSetupHookFile,
|
|
18
24
|
OnSetupHook
|
|
19
25
|
}
|
package/src/node/index.ts
CHANGED
|
@@ -25,10 +25,13 @@ import type {
|
|
|
25
25
|
VitrifyUIFrameworks,
|
|
26
26
|
VitrifySSRModes,
|
|
27
27
|
OnRenderedHook,
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
28
|
+
OnSetupHookFile,
|
|
29
|
+
OnAppCreatedHook,
|
|
30
|
+
OnTemplateRenderedHook,
|
|
31
|
+
OnAppCreatedHookFile,
|
|
32
|
+
OnRenderedHookFile,
|
|
33
|
+
OnTemplateRenderedHookFile,
|
|
34
|
+
OnAppMountedHookFile
|
|
32
35
|
} from './vitrify-config.js'
|
|
33
36
|
import type { VitrifyContext } from './bin/run.js'
|
|
34
37
|
import type { VitrifyPlugin } from './plugins/index.js'
|
|
@@ -278,12 +281,15 @@ export const baseConfig = async ({
|
|
|
278
281
|
}
|
|
279
282
|
}
|
|
280
283
|
|
|
281
|
-
let onBootHooks: OnBootHook[]
|
|
282
284
|
let onRenderedHooks: OnRenderedHook[]
|
|
285
|
+
let onRenderedFiles: OnRenderedHookFile[]
|
|
283
286
|
let onTemplateRenderedHooks: OnTemplateRenderedHook[]
|
|
287
|
+
let onTemplateRenderedFiles: OnTemplateRenderedHookFile[]
|
|
284
288
|
let onAppMountedHooks: OnAppMountedHook[]
|
|
285
|
-
let
|
|
286
|
-
let
|
|
289
|
+
let onAppMountedFiles: OnAppMountedHookFile[]
|
|
290
|
+
let OnAppCreatedHooks: OnAppCreatedHook[]
|
|
291
|
+
let onAppCreatedFiles: OnAppCreatedHookFile[]
|
|
292
|
+
let onSetupFiles: OnSetupHookFile[]
|
|
287
293
|
let globalCss: string[] = []
|
|
288
294
|
let staticImports: StaticImports
|
|
289
295
|
let sassVariables: Record<string, string | undefined>
|
|
@@ -358,12 +364,16 @@ export const baseConfig = async ({
|
|
|
358
364
|
name: 'vitrify-setup',
|
|
359
365
|
enforce: 'post',
|
|
360
366
|
config: (config: VitrifyConfig, env) => {
|
|
361
|
-
onBootHooks = config.vitrify?.hooks?.onBoot || []
|
|
362
367
|
onRenderedHooks = config.vitrify?.hooks?.onRendered || []
|
|
368
|
+
onRenderedFiles = config.vitrify?.hooks?.onRenderedFiles || []
|
|
363
369
|
onTemplateRenderedHooks =
|
|
364
370
|
config.vitrify?.hooks?.onTemplateRendered || []
|
|
371
|
+
onTemplateRenderedFiles =
|
|
372
|
+
config.vitrify?.hooks?.onTemplateRenderedFiles || []
|
|
365
373
|
onAppMountedHooks = config.vitrify?.hooks?.onAppMounted || []
|
|
366
|
-
|
|
374
|
+
onAppMountedFiles = config.vitrify?.hooks?.onAppMountedFiles || []
|
|
375
|
+
OnAppCreatedHooks = config.vitrify?.hooks?.onAppCreated || []
|
|
376
|
+
onAppCreatedFiles = config.vitrify?.hooks?.onAppCreatedFiles || []
|
|
367
377
|
onSetupFiles = config?.vitrify?.hooks?.onSetup || []
|
|
368
378
|
globalCss = config.vitrify?.globalCss || []
|
|
369
379
|
staticImports = config.vitrify?.staticImports || {}
|
|
@@ -392,21 +402,82 @@ export const baseConfig = async ({
|
|
|
392
402
|
},
|
|
393
403
|
load(id) {
|
|
394
404
|
if (id === 'virtual:vitrify-hooks') {
|
|
395
|
-
return `export const
|
|
405
|
+
return `export const onAppMounted = [${onAppMountedHooks
|
|
396
406
|
.map((fn) => `${String(fn)}`)
|
|
397
407
|
.join(', ')}]
|
|
398
|
-
|
|
399
|
-
.map((
|
|
400
|
-
|
|
408
|
+
${onAppMountedFiles
|
|
409
|
+
.map((url, index) => {
|
|
410
|
+
const varName = fileURLToPath(url)
|
|
411
|
+
.replaceAll('/', '')
|
|
412
|
+
.replaceAll(':', '')
|
|
413
|
+
.replaceAll('\\', '')
|
|
414
|
+
.replaceAll('.', '')
|
|
415
|
+
.replaceAll('-', '')
|
|
416
|
+
.replaceAll('_', '')
|
|
417
|
+
.replaceAll('+', '')
|
|
418
|
+
|
|
419
|
+
return `import ${varName} from '${
|
|
420
|
+
new URL(url, appDir).pathname
|
|
421
|
+
}'; onAppMounted.push(${varName});`
|
|
422
|
+
})
|
|
423
|
+
.join('\n')}
|
|
401
424
|
export const onRendered = [${onRenderedHooks
|
|
402
425
|
.map((fn) => `${String(fn)}`)
|
|
403
426
|
.join(', ')}]
|
|
427
|
+
${onRenderedFiles
|
|
428
|
+
.map((url, index) => {
|
|
429
|
+
const varName = fileURLToPath(url)
|
|
430
|
+
.replaceAll('/', '')
|
|
431
|
+
.replaceAll(':', '')
|
|
432
|
+
.replaceAll('\\', '')
|
|
433
|
+
.replaceAll('.', '')
|
|
434
|
+
.replaceAll('-', '')
|
|
435
|
+
.replaceAll('_', '')
|
|
436
|
+
.replaceAll('+', '')
|
|
437
|
+
|
|
438
|
+
return `import ${varName} from '${
|
|
439
|
+
new URL(url, appDir).pathname
|
|
440
|
+
}'; onRendered.push(${varName});`
|
|
441
|
+
})
|
|
442
|
+
.join('\n')}
|
|
404
443
|
export const onTemplateRendered = [${onTemplateRenderedHooks
|
|
405
444
|
.map((fn) => `${String(fn)}`)
|
|
406
445
|
.join(', ')}]
|
|
407
|
-
|
|
408
|
-
.map((
|
|
409
|
-
|
|
446
|
+
${onTemplateRenderedFiles
|
|
447
|
+
.map((url, index) => {
|
|
448
|
+
const varName = fileURLToPath(url)
|
|
449
|
+
.replaceAll('/', '')
|
|
450
|
+
.replaceAll(':', '')
|
|
451
|
+
.replaceAll('\\', '')
|
|
452
|
+
.replaceAll('.', '')
|
|
453
|
+
.replaceAll('-', '')
|
|
454
|
+
.replaceAll('_', '')
|
|
455
|
+
.replaceAll('+', '')
|
|
456
|
+
|
|
457
|
+
return `import ${varName} from '${
|
|
458
|
+
new URL(url, appDir).pathname
|
|
459
|
+
}'; onTemplateRendered.push(${varName});`
|
|
460
|
+
})
|
|
461
|
+
.join('\n')}
|
|
462
|
+
export const onAppCreated = [${OnAppCreatedHooks.map(
|
|
463
|
+
(fn) => `${String(fn)}`
|
|
464
|
+
).join(', ')}]
|
|
465
|
+
${onAppCreatedFiles
|
|
466
|
+
.map((url, index) => {
|
|
467
|
+
const varName = fileURLToPath(url)
|
|
468
|
+
.replaceAll('/', '')
|
|
469
|
+
.replaceAll(':', '')
|
|
470
|
+
.replaceAll('\\', '')
|
|
471
|
+
.replaceAll('.', '')
|
|
472
|
+
.replaceAll('-', '')
|
|
473
|
+
.replaceAll('_', '')
|
|
474
|
+
.replaceAll('+', '')
|
|
475
|
+
|
|
476
|
+
return `import ${varName} from '${
|
|
477
|
+
new URL(url, appDir).pathname
|
|
478
|
+
}'; onAppCreated.push(${varName});`
|
|
479
|
+
})
|
|
480
|
+
.join('\n')}
|
|
410
481
|
export const onSetup = []
|
|
411
482
|
${onSetupFiles
|
|
412
483
|
.map((url, index) => {
|
|
@@ -421,7 +492,7 @@ export const baseConfig = async ({
|
|
|
421
492
|
|
|
422
493
|
return `import ${varName} from '${
|
|
423
494
|
new URL(url, appDir).pathname
|
|
424
|
-
}'; onSetup.push(${varName})
|
|
495
|
+
}'; onSetup.push(${varName});`
|
|
425
496
|
})
|
|
426
497
|
.join('\n')}`
|
|
427
498
|
} else if (id === 'virtual:static-imports') {
|
|
@@ -733,10 +804,4 @@ export const baseConfig = async ({
|
|
|
733
804
|
export const vitrifyDir = new URL('..', import.meta.url)
|
|
734
805
|
export { prerender } from './frameworks/vue/prerender.js'
|
|
735
806
|
|
|
736
|
-
export type {
|
|
737
|
-
VitrifyConfig,
|
|
738
|
-
VitrifyConfigAsync,
|
|
739
|
-
VitrifyPlugin,
|
|
740
|
-
VitrifyContext,
|
|
741
|
-
OnBootHook
|
|
742
|
-
}
|
|
807
|
+
export type { VitrifyConfig, VitrifyConfigAsync, VitrifyPlugin, VitrifyContext }
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { OnAppCreatedHook, OnRenderedHook } from '../../vitrify-config.js'
|
|
2
2
|
import type { VitrifyPlugin } from '../index.js'
|
|
3
3
|
|
|
4
4
|
export type PiniaPluginOptions = {
|
|
@@ -6,7 +6,7 @@ export type PiniaPluginOptions = {
|
|
|
6
6
|
colada?: boolean
|
|
7
7
|
}
|
|
8
8
|
|
|
9
|
-
const piniaOnAppCreated:
|
|
9
|
+
const piniaOnAppCreated: OnAppCreatedHook = async ({
|
|
10
10
|
app,
|
|
11
11
|
ctx,
|
|
12
12
|
initialState,
|
|
@@ -30,7 +30,7 @@ const piniaOnRenderedHook: OnRenderedHook = async ({ app, ssrContext }) => {
|
|
|
30
30
|
}
|
|
31
31
|
}
|
|
32
32
|
|
|
33
|
-
const piniaColadaonAppCreated:
|
|
33
|
+
const piniaColadaonAppCreated: OnAppCreatedHook = async ({
|
|
34
34
|
app,
|
|
35
35
|
ctx,
|
|
36
36
|
initialState
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { fileURLToPath } from 'url'
|
|
2
2
|
import type {
|
|
3
|
-
OnBootHook,
|
|
4
3
|
OnAppMountedHook,
|
|
5
4
|
OnTemplateRenderedHook,
|
|
6
|
-
VitrifyConfig
|
|
5
|
+
VitrifyConfig,
|
|
6
|
+
OnAppCreatedHook
|
|
7
7
|
} from '../../vitrify-config.js'
|
|
8
8
|
import type { VitrifyPlugin } from '../index.js'
|
|
9
9
|
import { findDepPkgJsonPath } from 'vitefu'
|
|
@@ -145,7 +145,7 @@ export const QuasarPlugin: VitrifyPlugin<QuasarPluginOptions> = async ({
|
|
|
145
145
|
}
|
|
146
146
|
]
|
|
147
147
|
|
|
148
|
-
const
|
|
148
|
+
const onAppCreatedHooks: OnAppCreatedHook[] = [
|
|
149
149
|
async ({ app, ssrContext, staticImports }) => {
|
|
150
150
|
// @ts-expect-error undefined
|
|
151
151
|
const quasarPlugins = await import('virtual:quasar-plugins')
|
|
@@ -202,7 +202,7 @@ export const QuasarPlugin: VitrifyPlugin<QuasarPluginOptions> = async ({
|
|
|
202
202
|
quasar: ['Quasar']
|
|
203
203
|
},
|
|
204
204
|
hooks: {
|
|
205
|
-
|
|
205
|
+
onAppCreated: onAppCreatedHooks,
|
|
206
206
|
onAppMounted: onAppMountedHooks,
|
|
207
207
|
onTemplateRendered: [injectSsrContext]
|
|
208
208
|
},
|
|
@@ -49,12 +49,14 @@ export type SSRContext = {
|
|
|
49
49
|
[key: string]: unknown
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
-
export type
|
|
52
|
+
export type OnAppCreatedHookFile = URL
|
|
53
|
+
export type OnAppCreatedHook = ({
|
|
53
54
|
app,
|
|
54
55
|
router,
|
|
55
56
|
ctx,
|
|
56
57
|
initialState,
|
|
57
|
-
ssrContext
|
|
58
|
+
ssrContext,
|
|
59
|
+
staticImports
|
|
58
60
|
}: {
|
|
59
61
|
app: App
|
|
60
62
|
router: Router
|
|
@@ -69,18 +71,10 @@ export type onAppCreatedHook = ({
|
|
|
69
71
|
[key: string]: unknown
|
|
70
72
|
}
|
|
71
73
|
ssrContext?: SSRContext
|
|
72
|
-
}) => Promise<void> | void
|
|
73
|
-
|
|
74
|
-
export type OnBootHook = ({
|
|
75
|
-
app,
|
|
76
|
-
ssrContext,
|
|
77
|
-
staticImports
|
|
78
|
-
}: {
|
|
79
|
-
app: App
|
|
80
|
-
ssrContext: SSRContext
|
|
81
74
|
staticImports?: Record<string, any>
|
|
82
75
|
}) => Promise<void> | void
|
|
83
76
|
|
|
77
|
+
export type OnAppMountedHookFile = URL
|
|
84
78
|
export type OnAppMountedHook = ({
|
|
85
79
|
instance
|
|
86
80
|
}: {
|
|
@@ -88,7 +82,7 @@ export type OnAppMountedHook = ({
|
|
|
88
82
|
}) => Promise<void> | void
|
|
89
83
|
export type StaticImports = Record<string, string[]>
|
|
90
84
|
|
|
91
|
-
export type
|
|
85
|
+
export type OnSetupHookFile = URL
|
|
92
86
|
export type OnSetupHook = (
|
|
93
87
|
fastify: FastifyInstance,
|
|
94
88
|
options?: {
|
|
@@ -107,6 +101,7 @@ export type Render = (
|
|
|
107
101
|
app: App
|
|
108
102
|
}>
|
|
109
103
|
|
|
104
|
+
export type OnRenderedHookFile = URL
|
|
110
105
|
export type OnRenderedHook = ({
|
|
111
106
|
app,
|
|
112
107
|
ssrContext
|
|
@@ -115,6 +110,7 @@ export type OnRenderedHook = ({
|
|
|
115
110
|
ssrContext?: SSRContext
|
|
116
111
|
}) => Promise<void> | void
|
|
117
112
|
|
|
113
|
+
export type OnTemplateRenderedHookFile = URL
|
|
118
114
|
export type OnTemplateRenderedHook = ({
|
|
119
115
|
html,
|
|
120
116
|
ssrContext
|
|
@@ -142,27 +138,39 @@ export interface VitrifyConfig extends ViteUserConfig {
|
|
|
142
138
|
/**
|
|
143
139
|
* setup() is called directly after instantiating fastify. Use it to register your own plugins, routes etc.
|
|
144
140
|
*/
|
|
145
|
-
onSetup?:
|
|
141
|
+
onSetup?: OnSetupHookFile[]
|
|
142
|
+
/**
|
|
143
|
+
* Functions which run directly after initializing the application
|
|
144
|
+
*/
|
|
145
|
+
onAppCreated?: OnAppCreatedHook[]
|
|
146
|
+
/**
|
|
147
|
+
* Functions which run directly after initializing the application
|
|
148
|
+
*/
|
|
149
|
+
onAppCreatedFiles?: OnAppCreatedHookFile[]
|
|
146
150
|
/**
|
|
147
151
|
* Functions which run in the onMounted hook of the app
|
|
148
152
|
*/
|
|
149
153
|
onAppMounted?: OnAppMountedHook[]
|
|
150
154
|
/**
|
|
151
|
-
*
|
|
155
|
+
* Files with functions which run in the onMounted hook of the app
|
|
152
156
|
*/
|
|
153
|
-
|
|
157
|
+
onAppMountedFiles?: OnAppMountedHookFile[]
|
|
154
158
|
/**
|
|
155
159
|
* Functions which run after rendering the app (SSR)
|
|
156
160
|
*/
|
|
157
161
|
onRendered?: OnRenderedHook[]
|
|
162
|
+
/**
|
|
163
|
+
* Files with functions which run after rendering the app (SSR)
|
|
164
|
+
*/
|
|
165
|
+
onRenderedFiles?: OnRenderedHookFile[]
|
|
158
166
|
/**
|
|
159
167
|
* Functions which run after rendering the template (SSR)
|
|
160
168
|
*/
|
|
161
169
|
onTemplateRendered?: OnTemplateRenderedHook[]
|
|
162
170
|
/**
|
|
163
|
-
*
|
|
171
|
+
* Files with functions which run after rendering the template (SSR)
|
|
164
172
|
*/
|
|
165
|
-
|
|
173
|
+
onTemplateRenderedFiles?: OnTemplateRenderedHookFile[]
|
|
166
174
|
}
|
|
167
175
|
/**
|
|
168
176
|
* Global SASS variables
|
|
@@ -215,7 +223,6 @@ export interface VitrifyConfig extends ViteUserConfig {
|
|
|
215
223
|
*/
|
|
216
224
|
unpluginVueComponents?: unpluginVueComponentsOptions
|
|
217
225
|
}
|
|
218
|
-
// quasar?: QuasarConf
|
|
219
226
|
}
|
|
220
227
|
|
|
221
228
|
export type VitrifyCommands = 'build' | 'dev' | 'test'
|
package/src/vite/vue/main.ts
CHANGED
|
@@ -70,7 +70,7 @@ export async function createApp(
|
|
|
70
70
|
app.use(router)
|
|
71
71
|
|
|
72
72
|
for (const fn of onAppCreated) {
|
|
73
|
-
await fn({ app, router, ctx, initialState, ssrContext })
|
|
73
|
+
await fn({ app, router, ctx, initialState, ssrContext, staticImports })
|
|
74
74
|
}
|
|
75
75
|
|
|
76
76
|
// Workaround to fix hydration errors when serving html files directly
|
|
@@ -95,9 +95,9 @@ export async function createApp(
|
|
|
95
95
|
}
|
|
96
96
|
}
|
|
97
97
|
|
|
98
|
-
for (const fn of onBoot) {
|
|
99
|
-
|
|
100
|
-
}
|
|
98
|
+
// for (const fn of onBoot) {
|
|
99
|
+
// await fn({ app, ssrContext, staticImports })
|
|
100
|
+
// }
|
|
101
101
|
|
|
102
102
|
// @vitrify-pwa-only
|
|
103
103
|
// @ts-expect-error undefined
|