vitrify 0.2.5 → 0.5.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 +2 -2
- package/dist/app-urls.js +1 -2
- package/dist/bin/build.js +9 -51
- package/dist/bin/cli.js +31 -9
- package/dist/bin/dev.js +72 -70
- package/dist/frameworks/vue/fastify-csr-plugin.js +38 -0
- package/dist/frameworks/vue/fastify-ssr-plugin.js +83 -25
- package/dist/frameworks/vue/prerender.js +3 -3
- package/dist/frameworks/vue/server.js +10 -11
- package/dist/helpers/collect-css-ssr.js +61 -0
- package/dist/helpers/logger.js +0 -72
- package/dist/index.js +310 -130
- package/dist/plugins/quasar.js +34 -111
- package/dist/types/bin/build.d.ts +2 -2
- package/dist/types/bin/dev.d.ts +42 -4
- package/dist/types/frameworks/vue/fastify-csr-plugin.d.ts +17 -0
- package/dist/types/frameworks/vue/fastify-ssr-plugin.d.ts +6 -3
- package/dist/types/frameworks/vue/prerender.d.ts +3 -3
- package/dist/types/frameworks/vue/server.d.ts +10 -5
- package/dist/types/helpers/collect-css-ssr.d.ts +14 -0
- package/dist/types/helpers/logger.d.ts +0 -19
- package/dist/types/helpers/routes.d.ts +1 -1
- package/dist/types/index.d.ts +4 -2
- package/dist/types/plugins/index.d.ts +1 -1
- package/dist/types/vitrify-config.d.ts +33 -17
- package/package.json +33 -32
- package/src/node/app-urls.ts +1 -2
- package/src/node/bin/build.ts +11 -57
- package/src/node/bin/cli.ts +38 -10
- package/src/node/bin/dev.ts +106 -80
- package/src/node/bin/test.ts +0 -3
- package/src/node/frameworks/vue/fastify-csr-plugin.ts +72 -0
- package/src/node/frameworks/vue/fastify-ssr-plugin.ts +99 -28
- package/src/node/frameworks/vue/prerender.ts +5 -5
- package/src/node/frameworks/vue/server.ts +24 -17
- package/src/node/helpers/collect-css-ssr.ts +85 -0
- package/src/node/helpers/logger.ts +0 -87
- package/src/node/index.ts +353 -146
- package/src/node/plugins/index.ts +1 -1
- package/src/node/plugins/quasar.ts +39 -116
- package/src/node/vitrify-config.ts +44 -17
- package/src/vite/fastify/entry.ts +11 -0
- package/src/vite/fastify/server.ts +12 -0
- package/src/vite/vue/csr/app.ts +25 -0
- package/src/vite/vue/csr/fastify-csr-plugin.ts +3 -0
- package/src/vite/vue/csr/server.ts +8 -0
- package/src/vite/vue/index.html +1 -0
- package/src/vite/vue/main.ts +5 -20
- package/src/vite/vue/ssr/app.ts +25 -0
- package/src/vite/vue/ssr/entry-server.ts +13 -1
- package/src/vite/vue/ssr/fastify-ssr-plugin.ts +2 -118
- package/src/vite/vue/ssr/prerender.ts +2 -2
- package/src/vite/vue/ssr/server.ts +24 -15
- package/src/node/helpers/ssr.ts.bak +0 -52
|
@@ -4,6 +4,7 @@ import Components from 'unplugin-vue-components/vite'
|
|
|
4
4
|
// import { prepareQuasarConf } from './quasar-conf-file.js'
|
|
5
5
|
import type {
|
|
6
6
|
BootFunction,
|
|
7
|
+
OnBootHook,
|
|
7
8
|
OnMountedHook,
|
|
8
9
|
VitrifyConfig
|
|
9
10
|
} from '../vitrify-config.js'
|
|
@@ -75,46 +76,32 @@ export const injectSsrContext = (
|
|
|
75
76
|
}${end}${ssrContext._meta.bodyTags || ''}`
|
|
76
77
|
})
|
|
77
78
|
|
|
78
|
-
// export interface Configuration {
|
|
79
|
-
// ssr?: 'server' | 'client' | 'ssg' | false
|
|
80
|
-
// }
|
|
81
|
-
|
|
82
79
|
export const QuasarPlugin: VitrifyPlugin = async ({
|
|
83
80
|
ssr = false,
|
|
84
81
|
pwa = false
|
|
85
82
|
}): Promise<Plugin[]> => {
|
|
86
|
-
// const extraPlugins: Plugin[] = []
|
|
87
|
-
// const ctx = {
|
|
88
|
-
// prod: process.env.MODE === 'production',
|
|
89
|
-
// dev: process.env.MODE === 'development',
|
|
90
|
-
// mode: {
|
|
91
|
-
// ssr: !!ssr,
|
|
92
|
-
// pwa: !!pwa
|
|
93
|
-
// }
|
|
94
|
-
// }
|
|
95
|
-
|
|
96
|
-
// let bootFilePaths: Record<string, any> = {}
|
|
97
|
-
// let components: string[] = []
|
|
98
83
|
let plugins: string[] = []
|
|
99
|
-
// let css: string[] = []
|
|
100
|
-
let extras: string[] = []
|
|
101
84
|
return [
|
|
102
|
-
// {
|
|
103
|
-
// name: 'legacy-support',
|
|
104
|
-
// enforce: 'pre',
|
|
105
|
-
// transform (code, id) {
|
|
106
|
-
// /**
|
|
107
|
-
// * ESM does not resolve an import to .default when there are multiple exports. The following is required to make the VuePlugin import of QCalendar work.
|
|
108
|
-
// */
|
|
109
|
-
// if (code.includes('app.use(VuePlugin)')) {
|
|
110
|
-
// code = code.replace(/app\.use\(VuePlugin\)/g, `app.use(VuePlugin.install ? VuePlugin : VuePlugin.default)`)
|
|
111
|
-
// }
|
|
112
|
-
// return code
|
|
113
|
-
// }
|
|
114
|
-
// },
|
|
115
85
|
Components({
|
|
116
86
|
resolvers: [QuasarResolver()]
|
|
117
87
|
}),
|
|
88
|
+
{
|
|
89
|
+
name: 'vite-plugin-quasar-transform',
|
|
90
|
+
enforce: 'pre',
|
|
91
|
+
transform: (code, id, options) => {
|
|
92
|
+
const { ssr } = options || {}
|
|
93
|
+
code = code
|
|
94
|
+
.replaceAll('__QUASAR_SSR__', ssr ? ssr.toString() : 'false')
|
|
95
|
+
.replaceAll('__QUASAR_SSR_SERVER__', 'import.meta.env.SSR')
|
|
96
|
+
.replaceAll('__QUASAR_SSR_CLIENT__', '!import.meta.env.SSR')
|
|
97
|
+
.replaceAll(
|
|
98
|
+
'__QUASAR_SSR_PWA__',
|
|
99
|
+
pwa ? '!import.meta.env.SSR' : 'false'
|
|
100
|
+
)
|
|
101
|
+
|
|
102
|
+
return code
|
|
103
|
+
}
|
|
104
|
+
},
|
|
118
105
|
{
|
|
119
106
|
name: 'vite-plugin-quasar-setup',
|
|
120
107
|
enforce: 'pre',
|
|
@@ -143,17 +130,15 @@ export const QuasarPlugin: VitrifyPlugin = async ({
|
|
|
143
130
|
}
|
|
144
131
|
]
|
|
145
132
|
|
|
146
|
-
const
|
|
133
|
+
const onBootHooks: OnBootHook[] = [
|
|
147
134
|
async ({ app, ssrContext, staticImports }) => {
|
|
148
|
-
// @ts-ignore
|
|
149
|
-
// const quasarVuePlugin = (await import('quasar/vue-plugin')).default
|
|
150
135
|
// @ts-ignore
|
|
151
136
|
const quasarPlugins = await import('virtual:quasar-plugins')
|
|
152
137
|
// @ts-ignore
|
|
153
138
|
const directives = await import('quasar/src/directives.js')
|
|
154
139
|
|
|
155
140
|
app.use(
|
|
156
|
-
staticImports
|
|
141
|
+
staticImports?.Quasar,
|
|
157
142
|
{
|
|
158
143
|
plugins: quasarPlugins,
|
|
159
144
|
directives
|
|
@@ -166,14 +151,14 @@ export const QuasarPlugin: VitrifyPlugin = async ({
|
|
|
166
151
|
return {
|
|
167
152
|
vitrify: {
|
|
168
153
|
urls,
|
|
169
|
-
bootFunctions,
|
|
170
|
-
ssrFunctions: [injectSsrContext],
|
|
171
154
|
globalCss,
|
|
172
155
|
staticImports: {
|
|
173
156
|
quasar: ['Quasar']
|
|
174
157
|
},
|
|
175
158
|
hooks: {
|
|
176
|
-
|
|
159
|
+
onBoot: onBootHooks,
|
|
160
|
+
onMounted: onMountedHooks,
|
|
161
|
+
onRendered: [injectSsrContext]
|
|
177
162
|
},
|
|
178
163
|
sass: {
|
|
179
164
|
additionalData: [`@import 'quasar/src/css/index.sass'`]
|
|
@@ -185,22 +170,7 @@ export const QuasarPlugin: VitrifyPlugin = async ({
|
|
|
185
170
|
{
|
|
186
171
|
name: 'vite-plugin-quasar',
|
|
187
172
|
enforce: 'post',
|
|
188
|
-
// transformIndexHtml: {
|
|
189
|
-
// enforce: 'post',
|
|
190
|
-
// transform: (html) => {
|
|
191
|
-
// return html.replace(
|
|
192
|
-
// '<!--product-name-->',
|
|
193
|
-
// productName
|
|
194
|
-
// )
|
|
195
|
-
// }
|
|
196
|
-
// },
|
|
197
173
|
config: async (config: VitrifyConfig, env) => {
|
|
198
|
-
// let appDir: URL
|
|
199
|
-
// let cliDir: URL
|
|
200
|
-
// let cwd: URL
|
|
201
|
-
// let quasarDir: URL
|
|
202
|
-
// let quasarConf: QuasarConf | undefined
|
|
203
|
-
|
|
204
174
|
const { quasar: quasarConf, vitrify: { urls } = {} } = config
|
|
205
175
|
|
|
206
176
|
const quasarPkgJsonPath = new URL(
|
|
@@ -211,33 +181,6 @@ export const QuasarPlugin: VitrifyPlugin = async ({
|
|
|
211
181
|
readFileSync(quasarPkgJsonPath, { encoding: 'utf-8' })
|
|
212
182
|
)
|
|
213
183
|
|
|
214
|
-
// if (quasarConf?.boot) {
|
|
215
|
-
// bootFilePaths = (quasarConf.boot as (Record<string, any> | string)[])
|
|
216
|
-
// .filter(entry => {
|
|
217
|
-
// if (typeof entry === 'object') return (entry.server && (ssr === 'server'))
|
|
218
|
-
// else if (entry !== '') return true
|
|
219
|
-
// })
|
|
220
|
-
// .map(entry => {
|
|
221
|
-
// if (typeof entry === 'string') return entry
|
|
222
|
-
// else if (typeof entry === 'object') return entry.path
|
|
223
|
-
// })
|
|
224
|
-
// .reduce((acc, entry) => {
|
|
225
|
-
// if (entry[0] === '~') {
|
|
226
|
-
// const split = entry.substring(1).split('/')
|
|
227
|
-
// const name = split[0].replace(/[|&;$%@"<>()+,]/g, "");
|
|
228
|
-
// acc[name] = {
|
|
229
|
-
// path: new URL(`node_modules/${entry.substring(1)}`, urls?.app).pathname
|
|
230
|
-
// }
|
|
231
|
-
// } else {
|
|
232
|
-
// const name = entry.split('.')[0]
|
|
233
|
-
// acc[name] = {
|
|
234
|
-
// path: `src/boot/${entry}`
|
|
235
|
-
// }
|
|
236
|
-
// }
|
|
237
|
-
// return acc
|
|
238
|
-
// }, {})
|
|
239
|
-
// }
|
|
240
|
-
|
|
241
184
|
/**
|
|
242
185
|
* All components should have been auto-imported
|
|
243
186
|
*/
|
|
@@ -249,14 +192,6 @@ export const QuasarPlugin: VitrifyPlugin = async ({
|
|
|
249
192
|
plugins = quasarConf?.framework.plugins
|
|
250
193
|
}
|
|
251
194
|
|
|
252
|
-
// css = (quasarConf?.css || []).map((v => {
|
|
253
|
-
// if (v[0] === '~') {
|
|
254
|
-
// return v.slice(1)
|
|
255
|
-
// }
|
|
256
|
-
// return v
|
|
257
|
-
// })).map((v) => `@import '${v}'`)
|
|
258
|
-
extras = quasarConf?.extras || []
|
|
259
|
-
|
|
260
195
|
return {
|
|
261
196
|
resolve: {
|
|
262
197
|
alias: [
|
|
@@ -302,45 +237,33 @@ export const QuasarPlugin: VitrifyPlugin = async ({
|
|
|
302
237
|
find: 'quasar/src',
|
|
303
238
|
replacement: new URL('src/', urls?.packages?.quasar).pathname
|
|
304
239
|
},
|
|
305
|
-
// ...extras.map(extra => ({
|
|
306
|
-
// find: `@quasar/extras/${extra}/${extra}.css`,
|
|
307
|
-
// replacement: new URL(`${extra}/${extra}.css`, urls?.packages?.['@quasar/extras']).pathname
|
|
308
|
-
// })
|
|
309
|
-
// ),
|
|
310
240
|
{
|
|
311
|
-
find: 'quasar',
|
|
312
|
-
replacement: new URL('src/', urls?.packages?.quasar)
|
|
241
|
+
find: new RegExp('^quasar$'),
|
|
242
|
+
replacement: new URL('src/index.all.js', urls?.packages?.quasar)
|
|
243
|
+
.pathname
|
|
313
244
|
},
|
|
245
|
+
// {
|
|
246
|
+
// find: 'quasar',
|
|
247
|
+
// replacement: new URL('src/index.all.js', urls?.packages?.quasar).pathname
|
|
248
|
+
// },
|
|
314
249
|
{
|
|
315
250
|
find: `@quasar/extras`,
|
|
316
251
|
replacement: new URL('.', urls?.packages?.['@quasar/extras'])
|
|
317
252
|
.pathname
|
|
318
253
|
}
|
|
319
|
-
// { find: new RegExp('^quasar$'), replacement: new URL('src/index.all.js', urls?.packages?.quasar).pathname },
|
|
320
|
-
// { find: new RegExp('^quasar$'), replacement: 'virtual:quasar' },
|
|
321
254
|
]
|
|
322
255
|
},
|
|
323
256
|
define: {
|
|
324
257
|
__DEV__: process.env.NODE_ENV !== 'production' || true,
|
|
325
|
-
__QUASAR_VERSION__: `'${version}'
|
|
326
|
-
__QUASAR_SSR__: !!ssr,
|
|
327
|
-
__QUASAR_SSR_SERVER__: ssr === 'server',
|
|
328
|
-
|
|
329
|
-
|
|
258
|
+
__QUASAR_VERSION__: `'${version}'`
|
|
259
|
+
// __QUASAR_SSR__: !!ssr,
|
|
260
|
+
// // __QUASAR_SSR_SERVER__: ssr === 'server',
|
|
261
|
+
// __QUASAR_SSR_SERVER__: `import.meta.env.SSR`,
|
|
262
|
+
// // __QUASAR_SSR_CLIENT__: ssr === 'client',
|
|
263
|
+
// __QUASAR_SSR_CLIENT__: `!import.meta.env.SSR`,
|
|
264
|
+
// // __QUASAR_SSR_PWA__: ssr === 'client' && pwa
|
|
265
|
+
// __QUASAR_SSR_PWA__: pwa ? `!import.meta.env.SSR` : false
|
|
330
266
|
},
|
|
331
|
-
// css: {
|
|
332
|
-
// preprocessorOptions: {
|
|
333
|
-
// sass: {
|
|
334
|
-
// additionalData: `@import 'quasar/src/css/index.sass'`
|
|
335
|
-
// // [
|
|
336
|
-
// // // ...extras.map(extra => `@import "@quasar/extras/${extra}/${extra}.css"`),
|
|
337
|
-
// // // ...extras.map(extra => `@import ${new URL(`${extra}/${extra}.css`, urls?.packages?.['@quasar/extras']).pathname}`) || [],
|
|
338
|
-
// // // config.css?.preprocessorOptions?.sass?.additionalData,
|
|
339
|
-
// // `@import 'quasar/src/css/index.sass'`
|
|
340
|
-
// // ].join('\n')
|
|
341
|
-
// }
|
|
342
|
-
// }
|
|
343
|
-
// },
|
|
344
267
|
ssr: {
|
|
345
268
|
noExternal: ['quasar']
|
|
346
269
|
}
|
|
@@ -353,7 +276,7 @@ export const QuasarPlugin: VitrifyPlugin = async ({
|
|
|
353
276
|
config: async (config, env) => ({
|
|
354
277
|
resolve: {
|
|
355
278
|
alias: [
|
|
356
|
-
{ find: new RegExp('^quasar$'), replacement: 'virtual:quasar' }
|
|
279
|
+
// { find: new RegExp('^quasar$'), replacement: 'virtual:quasar' }
|
|
357
280
|
]
|
|
358
281
|
}
|
|
359
282
|
}),
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FastifyInstance } from 'fastify'
|
|
2
|
-
import type { UserConfig } from 'vite'
|
|
2
|
+
import type { Alias, UserConfig } from 'vite'
|
|
3
3
|
import type { QuasarConf } from './plugins/quasar.js'
|
|
4
4
|
import type { ComponentInternalInstance } from '@vue/runtime-core'
|
|
5
5
|
|
|
@@ -12,6 +12,15 @@ export type BootFunction = ({
|
|
|
12
12
|
ssrContext: Record<string, unknown>
|
|
13
13
|
staticImports: Record<string, any>
|
|
14
14
|
}) => Promise<void> | void
|
|
15
|
+
export type OnBootHook = ({
|
|
16
|
+
app,
|
|
17
|
+
ssrContext,
|
|
18
|
+
staticImports
|
|
19
|
+
}: {
|
|
20
|
+
app: any
|
|
21
|
+
ssrContext: Record<string, unknown>
|
|
22
|
+
staticImports?: Record<string, any>
|
|
23
|
+
}) => Promise<void> | void
|
|
15
24
|
export type OnMountedHook = (
|
|
16
25
|
instance: ComponentInternalInstance
|
|
17
26
|
) => Promise<void> | void
|
|
@@ -20,30 +29,42 @@ export type SsrFunction = (
|
|
|
20
29
|
html: string,
|
|
21
30
|
ssrContext: Record<string, any>
|
|
22
31
|
) => string
|
|
23
|
-
|
|
32
|
+
export type OnRenderedHook = (
|
|
33
|
+
html: string,
|
|
34
|
+
ssrContext: Record<string, any>
|
|
35
|
+
) => string
|
|
36
|
+
// export type OnSetupHook = (
|
|
37
|
+
// fastify: FastifyInstance,
|
|
38
|
+
// staticImports?: Record<string, any>
|
|
39
|
+
// ) => any
|
|
40
|
+
export type OnSetupFile = URL
|
|
24
41
|
export interface VitrifyConfig extends UserConfig {
|
|
25
42
|
vitrify?: {
|
|
26
43
|
/**
|
|
27
44
|
* Global CSS imports
|
|
28
45
|
*/
|
|
29
46
|
globalCss?: string[]
|
|
30
|
-
/**
|
|
31
|
-
* Functions which run after initializing the app
|
|
32
|
-
*/
|
|
33
|
-
bootFunctions?: BootFunction[]
|
|
34
|
-
/**
|
|
35
|
-
* Functions which run on the server after rendering the app
|
|
36
|
-
*/
|
|
37
|
-
ssrFunctions?: SsrFunction[]
|
|
38
47
|
/**
|
|
39
48
|
* Static imports in the app: packageName: [imports]
|
|
40
49
|
*/
|
|
41
50
|
staticImports?: StaticImports
|
|
42
51
|
hooks?: {
|
|
52
|
+
/**
|
|
53
|
+
* setup() is called directly after instantiating fastify. Use it to register your own plugins, routes etc.
|
|
54
|
+
*/
|
|
55
|
+
onSetup?: OnSetupFile[]
|
|
43
56
|
/**
|
|
44
57
|
* Functions which run in the onMounted hook of the app
|
|
45
58
|
*/
|
|
46
|
-
onMounted
|
|
59
|
+
onMounted?: OnMountedHook[]
|
|
60
|
+
/**
|
|
61
|
+
* Functions which run after initializing the app
|
|
62
|
+
*/
|
|
63
|
+
onBoot?: OnBootHook[]
|
|
64
|
+
/**
|
|
65
|
+
* Functions which run after rendering the app (SSR)
|
|
66
|
+
*/
|
|
67
|
+
onRendered?: OnRenderedHook[]
|
|
47
68
|
}
|
|
48
69
|
/**
|
|
49
70
|
* Global SASS variables
|
|
@@ -52,12 +73,6 @@ export interface VitrifyConfig extends UserConfig {
|
|
|
52
73
|
variables?: Record<string, string>
|
|
53
74
|
additionalData?: string[]
|
|
54
75
|
}
|
|
55
|
-
fastify?: {
|
|
56
|
-
/**
|
|
57
|
-
* setup() is called directly after instantiating fastify. Use it to register your own plugins, routes etc.
|
|
58
|
-
*/
|
|
59
|
-
setup: (fastify: FastifyInstance) => any
|
|
60
|
-
}
|
|
61
76
|
/**
|
|
62
77
|
* Product name of the application. Will be used for the HTML title tag
|
|
63
78
|
*/
|
|
@@ -72,6 +87,18 @@ export interface VitrifyConfig extends UserConfig {
|
|
|
72
87
|
cwd?: URL
|
|
73
88
|
packages?: Record<string, URL>
|
|
74
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* SSR specific configuration
|
|
92
|
+
*/
|
|
93
|
+
ssr?: {
|
|
94
|
+
serverModules?: string[]
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Development only configuration
|
|
98
|
+
*/
|
|
99
|
+
dev?: {
|
|
100
|
+
alias?: Alias[]
|
|
101
|
+
}
|
|
75
102
|
}
|
|
76
103
|
quasar?: QuasarConf
|
|
77
104
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FastifyInstance } from 'fastify'
|
|
2
|
+
import { onSetup } from 'virtual:vitrify-hooks'
|
|
3
|
+
|
|
4
|
+
export const setup = async ({ fastify }: { fastify: FastifyInstance }) => {
|
|
5
|
+
if (onSetup?.length) {
|
|
6
|
+
for (const setup of onSetup) {
|
|
7
|
+
await setup(fastify)
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
return fastify
|
|
11
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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 { fastifyCsrPlugin } from './fastify-csr-plugin.js'
|
|
6
|
+
import type { ViteDevServer } from 'vite'
|
|
7
|
+
import * as imr from 'import-meta-resolve'
|
|
8
|
+
const { resolve } = imr
|
|
9
|
+
// const appDir = getPkgJsonDir(import.meta.url)
|
|
10
|
+
const getString = (str?: string) => str
|
|
11
|
+
let baseUrl = getString(__BASE_URL__)
|
|
12
|
+
const appDir = getAppDir()
|
|
13
|
+
|
|
14
|
+
export const setupApp = async () => {
|
|
15
|
+
const vitrifyDir = new URL('../', await resolve('vitrify', import.meta.url))
|
|
16
|
+
return createApp({
|
|
17
|
+
onSetup,
|
|
18
|
+
appDir,
|
|
19
|
+
baseUrl,
|
|
20
|
+
onRendered,
|
|
21
|
+
fastifyPlugin: fastifyCsrPlugin,
|
|
22
|
+
vitrifyDir,
|
|
23
|
+
mode: import.meta.env.MODE
|
|
24
|
+
})
|
|
25
|
+
}
|
package/src/vite/vue/index.html
CHANGED
package/src/vite/vue/main.ts
CHANGED
|
@@ -4,18 +4,11 @@ import {
|
|
|
4
4
|
createSSRApp,
|
|
5
5
|
createApp as createVueApp,
|
|
6
6
|
h,
|
|
7
|
-
onMounted,
|
|
7
|
+
onMounted as onMountedVue,
|
|
8
8
|
getCurrentInstance
|
|
9
9
|
} from 'vue'
|
|
10
|
-
|
|
11
|
-
// import quasarPlugins from 'virtual:quasar-plugins'
|
|
12
|
-
// import bootFunctions from 'virtual:quasar-boot'
|
|
13
|
-
import bootFunctions from 'virtual:boot-functions'
|
|
14
|
-
import onMountedHooks from 'virtual:on-mounted-hooks'
|
|
15
|
-
// import 'virtual:quasar-extras'
|
|
16
|
-
// import * as directives from 'quasar/directives'
|
|
10
|
+
import { onBoot, onMounted } from 'virtual:vitrify-hooks'
|
|
17
11
|
import routes from 'src/router/routes'
|
|
18
|
-
import 'virtual:global-css'
|
|
19
12
|
import * as staticImports from 'virtual:static-imports'
|
|
20
13
|
|
|
21
14
|
interface ssrContext {
|
|
@@ -34,13 +27,10 @@ export async function createApp(
|
|
|
34
27
|
setup(props) {
|
|
35
28
|
const instance = getCurrentInstance()
|
|
36
29
|
|
|
37
|
-
|
|
38
|
-
for (let fn of
|
|
30
|
+
onMountedVue(async () => {
|
|
31
|
+
for (let fn of onMounted) {
|
|
39
32
|
await fn(instance, staticImports)
|
|
40
33
|
}
|
|
41
|
-
// onAppMounted()
|
|
42
|
-
// const { proxy: { $q } } = getCurrentInstance()
|
|
43
|
-
// $q.onSSRHydrated !== void 0 && $q.onSSRHydrated()
|
|
44
34
|
})
|
|
45
35
|
|
|
46
36
|
return () => h(App, props)
|
|
@@ -63,11 +53,6 @@ export async function createApp(
|
|
|
63
53
|
next()
|
|
64
54
|
})
|
|
65
55
|
|
|
66
|
-
// app.use(Quasar, {
|
|
67
|
-
// plugins: quasarPlugins,
|
|
68
|
-
// directives
|
|
69
|
-
// }, ssrContext)
|
|
70
|
-
|
|
71
56
|
let provide: Record<string, unknown> = {}
|
|
72
57
|
if (import.meta.env.SSR) {
|
|
73
58
|
if (ssrContext?.provide) {
|
|
@@ -81,7 +66,7 @@ export async function createApp(
|
|
|
81
66
|
app.provide(key, provide[key])
|
|
82
67
|
}
|
|
83
68
|
|
|
84
|
-
for (let fn of
|
|
69
|
+
for (let fn of onBoot) {
|
|
85
70
|
await fn({ app, ssrContext, staticImports })
|
|
86
71
|
}
|
|
87
72
|
|
|
@@ -0,0 +1,25 @@
|
|
|
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
|
+
import type { ViteDevServer } from 'vite'
|
|
7
|
+
import * as imr from 'import-meta-resolve'
|
|
8
|
+
const { resolve } = imr
|
|
9
|
+
// const appDir = getPkgJsonDir(import.meta.url)
|
|
10
|
+
const getString = (str?: string) => str
|
|
11
|
+
let baseUrl = getString(__BASE_URL__)
|
|
12
|
+
const appDir = getAppDir()
|
|
13
|
+
|
|
14
|
+
export const setupApp = async () => {
|
|
15
|
+
const vitrifyDir = new URL('../', await resolve('vitrify', import.meta.url))
|
|
16
|
+
return createApp({
|
|
17
|
+
onSetup,
|
|
18
|
+
appDir,
|
|
19
|
+
baseUrl,
|
|
20
|
+
onRendered,
|
|
21
|
+
fastifyPlugin: fastifySsrPlugin,
|
|
22
|
+
vitrifyDir,
|
|
23
|
+
mode: import.meta.env.MODE
|
|
24
|
+
})
|
|
25
|
+
}
|
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import { createApp } from '../main.js'
|
|
2
|
-
import { renderToString } from '
|
|
2
|
+
import { renderToString } from 'vue/server-renderer'
|
|
3
|
+
import type { FastifyInstance } from 'fastify'
|
|
3
4
|
// import * as ApolloSSR from '@vue/apollo-ssr'
|
|
4
5
|
// import { ApolloClients } from '@vue/apollo-composable'
|
|
5
6
|
// import serialize from 'serialize-javascript'
|
|
6
7
|
|
|
8
|
+
import { onSetup } from 'virtual:vitrify-hooks'
|
|
9
|
+
|
|
10
|
+
export const setup = async ({ fastify }: { fastify: FastifyInstance }) => {
|
|
11
|
+
if (onSetup?.length) {
|
|
12
|
+
for (const setup of onSetup) {
|
|
13
|
+
await setup(fastify)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return fastify
|
|
17
|
+
}
|
|
18
|
+
|
|
7
19
|
const initializeApp = async (url, ssrContext) => {
|
|
8
20
|
const onRenderedList = []
|
|
9
21
|
Object.assign(ssrContext, {
|
|
@@ -1,120 +1,4 @@
|
|
|
1
1
|
import { fastifySsrPlugin } from '../../../node/frameworks/vue/fastify-ssr-plugin.js'
|
|
2
|
-
import
|
|
2
|
+
import { onRendered } from 'virtual:vitrify-hooks'
|
|
3
3
|
|
|
4
|
-
export { fastifySsrPlugin,
|
|
5
|
-
|
|
6
|
-
// import { FastifyPluginCallback, FastifyRequest, FastifyReply } from 'fastify'
|
|
7
|
-
// import fastifyStatic from 'fastify-static'
|
|
8
|
-
// import { readFileSync } from 'fs'
|
|
9
|
-
// import { injectSsrContext } from '../../node/helpers/ssr.js'
|
|
10
|
-
// import type { ViteDevServer } from 'vite'
|
|
11
|
-
|
|
12
|
-
// export interface FastifySsrOptions {
|
|
13
|
-
// baseUrl?: string
|
|
14
|
-
// provide?: (req: FastifyRequest, res: FastifyReply) => Promise<Record<string, unknown>>
|
|
15
|
-
// vite?: ViteDevServer
|
|
16
|
-
// cliDir?: URL
|
|
17
|
-
// appDir?: URL
|
|
18
|
-
// productName?: string
|
|
19
|
-
// }
|
|
20
|
-
|
|
21
|
-
// const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (fastify, options, done) => {
|
|
22
|
-
// if (import.meta.env.MODE === 'development') {
|
|
23
|
-
// if (!options.vite) throw new Error('Option vite cannot be undefined')
|
|
24
|
-
// const middie = (await import('middie')).default
|
|
25
|
-
// await fastify.register(middie)
|
|
26
|
-
// fastify.use(options.vite.middlewares)
|
|
27
|
-
|
|
28
|
-
// fastify.get('*', async (req, res) => {
|
|
29
|
-
// try {
|
|
30
|
-
// // const url = req.originalUrl
|
|
31
|
-
// const url = req.raw.url
|
|
32
|
-
// let template
|
|
33
|
-
// let render
|
|
34
|
-
// const ssrContext = {
|
|
35
|
-
// req,
|
|
36
|
-
// res
|
|
37
|
-
// }
|
|
38
|
-
// // always read fresh template in dev
|
|
39
|
-
// // template = readFileSync(resolve('index.html'), 'utf-8')
|
|
40
|
-
// template = readFileSync(new URL('index.html', options.cliDir)).toString()
|
|
41
|
-
|
|
42
|
-
// // template = await vite.transformIndexHtml(url, template)
|
|
43
|
-
// const entryUrl = new URL('ssr/entry-server.ts', options.cliDir).pathname
|
|
44
|
-
// render = (await options.vite!.ssrLoadModule(entryUrl)).render
|
|
45
|
-
// let manifest
|
|
46
|
-
// // TODO: https://github.com/vitejs/vite/issues/2282
|
|
47
|
-
// try {
|
|
48
|
-
// manifest = {}
|
|
49
|
-
// } catch (e) {
|
|
50
|
-
// manifest = {}
|
|
51
|
-
// }
|
|
52
|
-
|
|
53
|
-
// const [appHtml, preloadLinks] = await render(url, manifest, ssrContext)
|
|
54
|
-
// const html = template
|
|
55
|
-
// .replace(`<!--preload-links-->`, preloadLinks)
|
|
56
|
-
// .replace(`<!--app-html-->`, appHtml)
|
|
57
|
-
// .replace('<!--product-name-->', options.productName || 'Product name')
|
|
58
|
-
|
|
59
|
-
// res.code(200)
|
|
60
|
-
// res.type('text/html')
|
|
61
|
-
// res.send(html)
|
|
62
|
-
// // res.status(200).set({ 'Content-Type': 'text/html' }).end(html)
|
|
63
|
-
// } catch (e: any) {
|
|
64
|
-
// console.error(e.stack)
|
|
65
|
-
// options.vite && options.vite.ssrFixStacktrace(e)
|
|
66
|
-
// res.code(500)
|
|
67
|
-
// res.send(e.stack)
|
|
68
|
-
// }
|
|
69
|
-
// })
|
|
70
|
-
// } else {
|
|
71
|
-
// options.baseUrl = options.baseUrl || '/'
|
|
72
|
-
// fastify.register(fastifyStatic, {
|
|
73
|
-
// root: new URL('./dist/ssr/client', options.appDir).pathname,
|
|
74
|
-
// wildcard: false,
|
|
75
|
-
// index: false,
|
|
76
|
-
// prefix: options.baseUrl
|
|
77
|
-
// })
|
|
78
|
-
|
|
79
|
-
// fastify.get(`${options.baseUrl}*`, async (req, res) => {
|
|
80
|
-
// const url = req.raw.url
|
|
81
|
-
// const provide = options.provide ? await options.provide(req, res) : {}
|
|
82
|
-
// let template
|
|
83
|
-
// let render
|
|
84
|
-
// let manifest
|
|
85
|
-
// const ssrContext: Record<string, any> = {
|
|
86
|
-
// req,
|
|
87
|
-
// res,
|
|
88
|
-
// provide
|
|
89
|
-
// }
|
|
90
|
-
|
|
91
|
-
// // template = readFileSync(new URL('../client/index.html', import.meta.url).pathname).toString()
|
|
92
|
-
// // manifest = JSON.parse(readFileSync(new URL('../client/ssr-manifest.json', import.meta.url)).toString())
|
|
93
|
-
// // render = (await import(new URL('./entry-server.mjs', import.meta.url).pathname)).render
|
|
94
|
-
// template = readFileSync(new URL('./dist/ssr/client/index.html', options.appDir).pathname).toString()
|
|
95
|
-
// manifest = JSON.parse(readFileSync(new URL('./dist/ssr/client/ssr-manifest.json', options.appDir)).toString())
|
|
96
|
-
// render = (await import(new URL('./dist/ssr/server/entry-server.mjs', options.appDir).pathname)).render
|
|
97
|
-
|
|
98
|
-
// const [appHtml, preloadLinks] = await render(url, manifest, ssrContext)
|
|
99
|
-
|
|
100
|
-
// if (!ssrContext.initialState) ssrContext.initialState = {}
|
|
101
|
-
// ssrContext.initialState.provide = provide
|
|
102
|
-
|
|
103
|
-
// let html = template
|
|
104
|
-
// .replace(`<!--preload-links-->`, preloadLinks)
|
|
105
|
-
// .replace(`<!--app-html-->`, appHtml)
|
|
106
|
-
// html = injectSsrContext(html, ssrContext)
|
|
107
|
-
|
|
108
|
-
// res.code(200)
|
|
109
|
-
// res.type('text/html')
|
|
110
|
-
// res.send(html)
|
|
111
|
-
// })
|
|
112
|
-
// }
|
|
113
|
-
|
|
114
|
-
// done()
|
|
115
|
-
|
|
116
|
-
// }
|
|
117
|
-
|
|
118
|
-
// export {
|
|
119
|
-
// fastifySsrPlugin
|
|
120
|
-
// }
|
|
4
|
+
export { fastifySsrPlugin, onRendered }
|