vitrify 0.2.3 → 0.3.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/src/node/index.ts CHANGED
@@ -2,7 +2,6 @@ import vuePlugin from '@vitejs/plugin-vue'
2
2
  import type { InlineConfig, UserConfig } from 'vite'
3
3
  import { mergeConfig } from 'vite'
4
4
  import { readFileSync } from 'fs'
5
- import { QuasarPlugin } from './plugins/quasar.js'
6
5
  import builtinModules from 'builtin-modules'
7
6
  import { resolve } from 'import-meta-resolve'
8
7
  import type {
@@ -10,11 +9,12 @@ import type {
10
9
  BootFunction,
11
10
  OnMountedHook,
12
11
  VitrifyConfig,
13
- SsrFunction
12
+ OnRenderedHook,
13
+ OnBootHook,
14
+ OnSetupHook
14
15
  } from './vitrify-config.js'
15
16
  import type { VitrifyContext } from './bin/run.js'
16
17
  import type { VitrifyPlugin } from './plugins/index.js'
17
- import type { FastifyInstance } from 'fastify'
18
18
  import { getPkgJsonDir } from './app-urls.js'
19
19
 
20
20
  const serverModules = ['fastify', 'middie']
@@ -24,11 +24,10 @@ const configPluginMap: Record<string, () => Promise<VitrifyPlugin>> = {
24
24
  import('./plugins/quasar.js').then((module) => module.QuasarPlugin)
25
25
  }
26
26
 
27
+ const manualChunks = ['prerender', 'fastify-ssr-plugin', 'server']
28
+
27
29
  export const VIRTUAL_MODULES = [
28
- 'virtual:fastify-setup',
29
- 'virtual:boot-functions',
30
- 'virtual:ssr-functions',
31
- 'virtual:on-mounted-hooks',
30
+ 'virtual:vitrify-hooks',
32
31
  'virtual:global-css',
33
32
  'virtual:static-imports'
34
33
  ]
@@ -59,16 +58,8 @@ export const baseConfig = async ({
59
58
  const cwd = getCwd()
60
59
  const cliDir = getCliDir()
61
60
  const cliViteDir = getCliViteDir(cliDir)
62
- // const {
63
- // appDir: tempAppDir,
64
- // cliDir,
65
- // cliViteDir,
66
- // srcDir
67
- // } = await import('./app-urls.js')
68
- // const cwd = appDir || tempAppDir
69
61
  const frameworkDir = new URL(`${framework}/`, cliViteDir)
70
62
 
71
- // const localPackages = ['vue', 'vue-router', 'quasar']
72
63
  const localPackages = ['vue', 'vue-router']
73
64
  const cliPackages = ['vitest']
74
65
  const packageUrls: Record<string, URL> = {}
@@ -85,18 +76,6 @@ export const baseConfig = async ({
85
76
  )
86
77
  })()
87
78
 
88
- // if (appDir) {
89
- // srcDir = new URL('src/', appDir);
90
- // quasarDir = new URL(await resolve('quasar/', appDir.href));
91
- // ({ appDir: cwd, cliDir } = await import('./app-urls.js'))
92
- // } else {
93
- // ({ appDir, cliDir, srcDir, quasarDir } = await import('./app-urls.js'))
94
- // cwd = appDir
95
- // }
96
- // vueDir = new URL('./', await resolve('vue', appDir.href));
97
- // vueRouterDir = new URL('../', await resolve('vue-router', appDir.href));
98
- // vitestDir = new URL('../', await resolve('vitest', cliDir.href));
99
-
100
79
  if (!publicDir) publicDir = new URL('public/', appDir)
101
80
  /**
102
81
  * TODO:Perform some manual check if command is run inside a Quasar Project
@@ -122,9 +101,6 @@ export const baseConfig = async ({
122
101
  })
123
102
  )
124
103
 
125
- const fastifySetup =
126
- vitrifyConfig.vitrify?.fastify?.setup || ((fastify: FastifyInstance) => {})
127
-
128
104
  const ssrTransformCustomDir = () => {
129
105
  return {
130
106
  props: [],
@@ -145,9 +121,10 @@ export const baseConfig = async ({
145
121
  }
146
122
  }
147
123
 
148
- let bootFunctions: BootFunction[]
149
- let ssrFunctions: SsrFunction[]
124
+ let onBootHooks: OnBootHook[]
125
+ let onRenderedHooks: OnRenderedHook[]
150
126
  let onMountedHooks: OnMountedHook[]
127
+ let onSetupHooks: OnSetupHook[]
151
128
  let globalCss: string[]
152
129
  let staticImports: StaticImports
153
130
  let sassVariables: Record<string, string>
@@ -175,18 +152,14 @@ export const baseConfig = async ({
175
152
  }
176
153
  }),
177
154
  ...frameworkPlugins,
178
- // await QuasarPlugin({
179
- // ssr: ssr,
180
- // pwa: pwa
181
- // // quasarDir: packageUrls.quasar
182
- // }),
183
155
  {
184
156
  name: 'vitrify-setup',
185
157
  enforce: 'post',
186
158
  config: async (config: VitrifyConfig, env) => {
187
- bootFunctions = config.vitrify?.bootFunctions || []
188
- ssrFunctions = config.vitrify?.ssrFunctions || []
159
+ onBootHooks = config.vitrify?.hooks?.onBoot || []
160
+ onRenderedHooks = config.vitrify?.hooks?.onRendered || []
189
161
  onMountedHooks = config.vitrify?.hooks?.onMounted || []
162
+ onSetupHooks = config?.vitrify?.hooks?.onSetup || []
190
163
  globalCss = config.vitrify?.globalCss || []
191
164
  staticImports = config.vitrify?.staticImports || {}
192
165
  sassVariables = config.vitrify?.sass?.variables || {}
@@ -219,20 +192,19 @@ export const baseConfig = async ({
219
192
  return
220
193
  },
221
194
  load(id) {
222
- if (id === 'virtual:fastify-setup') {
223
- return `export const setup = ${String(fastifySetup)}`
224
- } else if (id === 'virtual:boot-functions') {
225
- return `export default [${bootFunctions
226
- .map((fn) => `${String(fn)}`)
227
- .join(', ')}]`
228
- } else if (id === 'virtual:ssr-functions') {
229
- return `export default [${ssrFunctions
230
- .map((fn) => `${String(fn)}`)
231
- .join(', ')}]`
232
- } else if (id === 'virtual:on-mounted-hooks') {
233
- return `export default [${onMountedHooks
195
+ if (id === 'virtual:vitrify-hooks') {
196
+ return `export const onBoot = [${onBootHooks
234
197
  .map((fn) => `${String(fn)}`)
235
- .join(', ')}]`
198
+ .join(', ')}]
199
+ export const onMounted = [${onMountedHooks
200
+ .map((fn) => `${String(fn)}`)
201
+ .join(', ')}]
202
+ export const onRendered = [${onRenderedHooks
203
+ .map((fn) => `${String(fn)}`)
204
+ .join(', ')}]
205
+ export const onSetup = [${onSetupHooks
206
+ .map((fn) => `${String(fn)}`)
207
+ .join(', ')}]`
236
208
  } else if (id === 'virtual:global-css') {
237
209
  return `${globalCss.map((css) => `import '${css}'`).join('\n')}`
238
210
  } else if (id === 'virtual:static-imports') {
@@ -305,9 +277,6 @@ export const baseConfig = async ({
305
277
  { find: 'cwd', replacement: cwd.pathname },
306
278
  { find: 'boot', replacement: new URL('boot/', srcDir).pathname },
307
279
  { find: 'assets', replacement: new URL('assets/', srcDir).pathname },
308
- // ...Object.entries(packageUrls).map(([key, value]) => ({
309
- // find: key, replacement: value.pathname
310
- // })),
311
280
  { find: 'vue', replacement: packageUrls['vue'].pathname },
312
281
  { find: 'vue-router', replacement: packageUrls['vue-router'].pathname },
313
282
  { find: 'vitrify', replacement: cliDir.pathname }
@@ -324,7 +293,6 @@ export const baseConfig = async ({
324
293
  vitrify: {
325
294
  productName,
326
295
  urls: {
327
- // @ts-ignore
328
296
  app: appDir,
329
297
  cli: cliDir,
330
298
  src: srcDir,
@@ -362,10 +330,10 @@ export const baseConfig = async ({
362
330
  chunkFileNames: '[name].mjs',
363
331
  format: 'es',
364
332
  manualChunks: (id) => {
365
- if (id.includes('fastify-ssr-plugin')) {
366
- return 'fastify-ssr-plugin'
367
- } else if (id.includes('prerender')) {
368
- return 'prerender'
333
+ if (id.includes('vitrify/src/vite/')) {
334
+ const name = id.split('/').at(-1)?.split('.').at(0)
335
+ console.log(name)
336
+ if (manualChunks.includes(id)) return name
369
337
  } else if (id.includes('node_modules')) {
370
338
  return 'vendor'
371
339
  }
@@ -378,13 +346,6 @@ export const baseConfig = async ({
378
346
  }
379
347
  }
380
348
  },
381
- // css: {
382
- // preprocessorOptions: {
383
- // sass: {
384
- // additionalData: sass ? [...sass].join('\n') : undefined
385
- // }
386
- // }
387
- // },
388
349
  ssr: {
389
350
  // Create a SSR bundle
390
351
  noExternal: [
@@ -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,43 +76,12 @@ 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
  }),
@@ -143,10 +113,8 @@ export const QuasarPlugin: VitrifyPlugin = async ({
143
113
  }
144
114
  ]
145
115
 
146
- const bootFunctions: BootFunction[] = [
116
+ const onBootHooks: OnBootHook[] = [
147
117
  async ({ app, ssrContext, staticImports }) => {
148
- // @ts-ignore
149
- // const quasarVuePlugin = (await import('quasar/vue-plugin')).default
150
118
  // @ts-ignore
151
119
  const quasarPlugins = await import('virtual:quasar-plugins')
152
120
  // @ts-ignore
@@ -166,14 +134,14 @@ export const QuasarPlugin: VitrifyPlugin = async ({
166
134
  return {
167
135
  vitrify: {
168
136
  urls,
169
- bootFunctions,
170
- ssrFunctions: [injectSsrContext],
171
137
  globalCss,
172
138
  staticImports: {
173
139
  quasar: ['Quasar']
174
140
  },
175
141
  hooks: {
176
- onMounted: onMountedHooks
142
+ onBoot: onBootHooks,
143
+ onMounted: onMountedHooks,
144
+ onRendered: [injectSsrContext]
177
145
  },
178
146
  sass: {
179
147
  additionalData: [`@import 'quasar/src/css/index.sass'`]
@@ -185,22 +153,7 @@ export const QuasarPlugin: VitrifyPlugin = async ({
185
153
  {
186
154
  name: 'vite-plugin-quasar',
187
155
  enforce: 'post',
188
- // transformIndexHtml: {
189
- // enforce: 'post',
190
- // transform: (html) => {
191
- // return html.replace(
192
- // '<!--product-name-->',
193
- // productName
194
- // )
195
- // }
196
- // },
197
156
  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
157
  const { quasar: quasarConf, vitrify: { urls } = {} } = config
205
158
 
206
159
  const quasarPkgJsonPath = new URL(
@@ -211,33 +164,6 @@ export const QuasarPlugin: VitrifyPlugin = async ({
211
164
  readFileSync(quasarPkgJsonPath, { encoding: 'utf-8' })
212
165
  )
213
166
 
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
167
  /**
242
168
  * All components should have been auto-imported
243
169
  */
@@ -249,14 +175,6 @@ export const QuasarPlugin: VitrifyPlugin = async ({
249
175
  plugins = quasarConf?.framework.plugins
250
176
  }
251
177
 
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
178
  return {
261
179
  resolve: {
262
180
  alias: [
@@ -302,11 +220,6 @@ export const QuasarPlugin: VitrifyPlugin = async ({
302
220
  find: 'quasar/src',
303
221
  replacement: new URL('src/', urls?.packages?.quasar).pathname
304
222
  },
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
223
  {
311
224
  find: 'quasar',
312
225
  replacement: new URL('src/', urls?.packages?.quasar).pathname
@@ -316,8 +229,6 @@ export const QuasarPlugin: VitrifyPlugin = async ({
316
229
  replacement: new URL('.', urls?.packages?.['@quasar/extras'])
317
230
  .pathname
318
231
  }
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
232
  ]
322
233
  },
323
234
  define: {
@@ -328,19 +239,6 @@ export const QuasarPlugin: VitrifyPlugin = async ({
328
239
  __QUASAR_SSR_CLIENT__: ssr === 'client',
329
240
  __QUASAR_SSR_PWA__: ssr === 'client' && pwa
330
241
  },
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
242
  ssr: {
345
243
  noExternal: ['quasar']
346
244
  }
@@ -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,6 +29,11 @@ export type SsrFunction = (
20
29
  html: string,
21
30
  ssrContext: Record<string, any>
22
31
  ) => string
32
+ export type OnRenderedHook = (
33
+ html: string,
34
+ ssrContext: Record<string, any>
35
+ ) => string
36
+ export type OnSetupHook = (fastify: FastifyInstance) => any
23
37
 
24
38
  export interface VitrifyConfig extends UserConfig {
25
39
  vitrify?: {
@@ -27,23 +41,27 @@ export interface VitrifyConfig extends UserConfig {
27
41
  * Global CSS imports
28
42
  */
29
43
  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
44
  /**
39
45
  * Static imports in the app: packageName: [imports]
40
46
  */
41
47
  staticImports?: StaticImports
42
48
  hooks?: {
49
+ /**
50
+ * setup() is called directly after instantiating fastify. Use it to register your own plugins, routes etc.
51
+ */
52
+ onSetup?: OnSetupHook[]
43
53
  /**
44
54
  * Functions which run in the onMounted hook of the app
45
55
  */
46
- onMounted: OnMountedHook[]
56
+ onMounted?: OnMountedHook[]
57
+ /**
58
+ * Functions which run after initializing the app
59
+ */
60
+ onBoot?: OnBootHook[]
61
+ /**
62
+ * Functions which run after rendering the app (SSR)
63
+ */
64
+ onRendered?: OnRenderedHook[]
47
65
  }
48
66
  /**
49
67
  * Global SASS variables
@@ -52,12 +70,6 @@ export interface VitrifyConfig extends UserConfig {
52
70
  variables?: Record<string, string>
53
71
  additionalData?: string[]
54
72
  }
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
73
  /**
62
74
  * Product name of the application. Will be used for the HTML title tag
63
75
  */
@@ -4,16 +4,10 @@ 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
- // import { Quasar, useQuasar } from 'quasar'
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
12
  import 'virtual:global-css'
19
13
  import * as staticImports from 'virtual:static-imports'
@@ -34,13 +28,10 @@ export async function createApp(
34
28
  setup(props) {
35
29
  const instance = getCurrentInstance()
36
30
 
37
- onMounted(async () => {
38
- for (let fn of onMountedHooks) {
31
+ onMountedVue(async () => {
32
+ for (let fn of onMounted) {
39
33
  await fn(instance, staticImports)
40
34
  }
41
- // onAppMounted()
42
- // const { proxy: { $q } } = getCurrentInstance()
43
- // $q.onSSRHydrated !== void 0 && $q.onSSRHydrated()
44
35
  })
45
36
 
46
37
  return () => h(App, props)
@@ -63,11 +54,6 @@ export async function createApp(
63
54
  next()
64
55
  })
65
56
 
66
- // app.use(Quasar, {
67
- // plugins: quasarPlugins,
68
- // directives
69
- // }, ssrContext)
70
-
71
57
  let provide: Record<string, unknown> = {}
72
58
  if (import.meta.env.SSR) {
73
59
  if (ssrContext?.provide) {
@@ -81,7 +67,7 @@ export async function createApp(
81
67
  app.provide(key, provide[key])
82
68
  }
83
69
 
84
- for (let fn of bootFunctions) {
70
+ for (let fn of onBoot) {
85
71
  await fn({ app, ssrContext, staticImports })
86
72
  }
87
73
 
@@ -1,120 +1,4 @@
1
1
  import { fastifySsrPlugin } from '../../../node/frameworks/vue/fastify-ssr-plugin.js'
2
- import ssrFunctions from 'virtual:ssr-functions'
2
+ import { onRendered } from 'virtual:vitrify-hooks'
3
3
 
4
- export { fastifySsrPlugin, ssrFunctions }
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 }
@@ -1,4 +1,4 @@
1
1
  import { prerender } from '../../../node/frameworks/vue/prerender.js'
2
- import ssrFunctions from 'virtual:ssr-functions'
2
+ import { onRendered } from 'virtual:vitrify-hooks'
3
3
 
4
- export { prerender, ssrFunctions }
4
+ export { prerender, onRendered }
@@ -1,7 +1,7 @@
1
1
  import { createApp } from '../../../node/frameworks/vue/server.js'
2
2
  import { getAppDir } from '../../../node/app-urls.js'
3
- import { setup } from 'virtual:fastify-setup'
4
- import ssrFunctions from 'virtual:ssr-functions'
3
+ // import { setup } from 'virtual:fastify-setup'
4
+ import { onRendered, setup } from 'virtual:vitrify-hooks'
5
5
 
6
6
  // const appDir = getPkgJsonDir(import.meta.url)
7
7
  const getString = (str?: string) => str
@@ -12,7 +12,7 @@ const app = createApp({
12
12
  setup,
13
13
  appDir,
14
14
  baseUrl,
15
- ssrFunctions
15
+ onRendered
16
16
  })
17
17
 
18
18
  app.listen(process.env.PORT || 3000, process.env.HOST || '127.0.0.1')