vitrify 0.3.0 → 0.4.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.
Files changed (36) hide show
  1. package/dist/app-urls.js +1 -1
  2. package/dist/bin/cli.js +26 -4
  3. package/dist/bin/dev.js +59 -27
  4. package/dist/frameworks/vue/fastify-ssr-plugin.js +67 -16
  5. package/dist/frameworks/vue/server.js +9 -4
  6. package/dist/helpers/collect-css-ssr.js +57 -0
  7. package/dist/index.js +255 -69
  8. package/dist/plugins/quasar.js +9 -4
  9. package/dist/types/bin/build.d.ts +2 -2
  10. package/dist/types/bin/dev.d.ts +39 -3
  11. package/dist/types/frameworks/vue/fastify-ssr-plugin.d.ts +6 -3
  12. package/dist/types/frameworks/vue/server.d.ts +9 -5
  13. package/dist/types/helpers/collect-css-ssr.d.ts +10 -0
  14. package/dist/types/helpers/routes.d.ts +1 -1
  15. package/dist/types/index.d.ts +1 -1
  16. package/dist/types/plugins/index.d.ts +1 -1
  17. package/dist/types/vitrify-config.d.ts +3 -4
  18. package/package.json +32 -32
  19. package/src/node/app-urls.ts +1 -1
  20. package/src/node/bin/build.ts +2 -2
  21. package/src/node/bin/cli.ts +33 -5
  22. package/src/node/bin/dev.ts +92 -34
  23. package/src/node/frameworks/vue/fastify-ssr-plugin.ts +80 -18
  24. package/src/node/frameworks/vue/server.ts +22 -8
  25. package/src/node/helpers/collect-css-ssr.ts +77 -0
  26. package/src/node/index.ts +285 -81
  27. package/src/node/plugins/index.ts +1 -1
  28. package/src/node/plugins/quasar.ts +9 -4
  29. package/src/node/vitrify-config.ts +7 -4
  30. package/src/vite/fastify/entry.ts +11 -0
  31. package/src/vite/fastify/server.ts +10 -0
  32. package/src/vite/vue/index.html +1 -0
  33. package/src/vite/vue/main.ts +0 -1
  34. package/src/vite/vue/ssr/app.ts +25 -0
  35. package/src/vite/vue/ssr/entry-server.ts +13 -1
  36. package/src/vite/vue/ssr/server.ts +23 -14
package/dist/index.js CHANGED
@@ -1,10 +1,39 @@
1
1
  import vuePlugin from '@vitejs/plugin-vue';
2
2
  import { mergeConfig } from 'vite';
3
+ import { build } from 'esbuild';
4
+ import fs from 'fs';
5
+ import path from 'path';
6
+ import { pathToFileURL } from 'url';
3
7
  import { readFileSync } from 'fs';
4
8
  import builtinModules from 'builtin-modules';
5
9
  import { resolve } from 'import-meta-resolve';
6
10
  import { getPkgJsonDir } from './app-urls.js';
7
- const serverModules = ['fastify', 'middie'];
11
+ const serverModules = [
12
+ // 'fs',
13
+ // 'path',
14
+ // 'url',
15
+ // 'module',
16
+ // 'crypto',
17
+ // 'node:fs',
18
+ 'util',
19
+ 'node:url',
20
+ 'node:util',
21
+ 'node:fs',
22
+ 'vitrify',
23
+ 'vite',
24
+ 'fastify',
25
+ 'middie',
26
+ 'knex',
27
+ 'bcrypt',
28
+ 'objection',
29
+ '@fastify/formbody',
30
+ '@fastify/static',
31
+ '@fastify/cors',
32
+ '@fastify/cookie',
33
+ 'mercurius',
34
+ 'jose',
35
+ 'oidc-provider'
36
+ ];
8
37
  const configPluginMap = {
9
38
  quasar: () => import('./plugins/quasar.js').then((module) => module.QuasarPlugin)
10
39
  };
@@ -14,6 +43,54 @@ export const VIRTUAL_MODULES = [
14
43
  'virtual:global-css',
15
44
  'virtual:static-imports'
16
45
  ];
46
+ async function bundleConfigFile(fileName, isESM = false) {
47
+ const result = await build({
48
+ absWorkingDir: process.cwd(),
49
+ entryPoints: [fileName],
50
+ outfile: 'out.js',
51
+ write: false,
52
+ platform: 'node',
53
+ bundle: true,
54
+ format: 'esm',
55
+ sourcemap: 'inline',
56
+ metafile: true,
57
+ plugins: [
58
+ {
59
+ name: 'externalize-deps',
60
+ setup(build) {
61
+ build.onResolve({ filter: /.*/ }, (args) => {
62
+ const id = args.path;
63
+ if (id[0] !== '.' && !path.isAbsolute(id)) {
64
+ return {
65
+ external: true
66
+ };
67
+ }
68
+ });
69
+ }
70
+ },
71
+ {
72
+ name: 'replace-import-meta',
73
+ setup(build) {
74
+ build.onLoad({ filter: /\.[jt]s$/ }, async (args) => {
75
+ const contents = await fs.promises.readFile(args.path, 'utf8');
76
+ return {
77
+ loader: args.path.endsWith('.ts') ? 'ts' : 'js',
78
+ contents: contents
79
+ .replace(/\bimport\.meta\.url\b/g, JSON.stringify(pathToFileURL(args.path).href))
80
+ .replace(/\b__dirname\b/g, JSON.stringify(path.dirname(args.path)))
81
+ .replace(/\b__filename\b/g, JSON.stringify(args.path))
82
+ };
83
+ });
84
+ }
85
+ }
86
+ ]
87
+ });
88
+ const { text } = result.outputFiles[0];
89
+ return {
90
+ code: text,
91
+ dependencies: result.metafile ? Object.keys(result.metafile.inputs) : []
92
+ };
93
+ }
17
94
  export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mode = 'production', framework = 'vue', pwa = false }) => {
18
95
  const { getAppDir, getCliDir, getCliViteDir, getSrcDir, getCwd } = await import('./app-urls.js');
19
96
  if (!appDir) {
@@ -24,17 +101,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
24
101
  const cliDir = getCliDir();
25
102
  const cliViteDir = getCliViteDir(cliDir);
26
103
  const frameworkDir = new URL(`${framework}/`, cliViteDir);
27
- const localPackages = ['vue', 'vue-router'];
28
- const cliPackages = ['vitest'];
29
- const packageUrls = {};
30
- await (async () => {
31
- for (const val of localPackages)
32
- packageUrls[val] = getPkgJsonDir(new URL(await resolve(val, appDir.href)));
33
- })();
34
- await (async () => {
35
- for (const val of cliPackages)
36
- packageUrls[val] = getPkgJsonDir(new URL(await resolve(val, cliDir.href)));
37
- })();
104
+ const fastifyDir = new URL('fastify/', cliViteDir);
38
105
  if (!publicDir)
39
106
  publicDir = new URL('public/', appDir);
40
107
  /**
@@ -42,18 +109,46 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
42
109
  */
43
110
  let vitrifyConfig;
44
111
  try {
45
- vitrifyConfig = (await import(new URL('vitrify.config.js', appDir).pathname)).default;
112
+ if (fs.existsSync(new URL('vitrify.config.ts', appDir).pathname)) {
113
+ const configPath = new URL('vitrify.config.ts', appDir).pathname;
114
+ const bundledConfig = await bundleConfigFile(new URL('vitrify.config.ts', appDir).pathname);
115
+ fs.writeFileSync(configPath + '.js', bundledConfig.code);
116
+ vitrifyConfig = (await import(configPath + '.js')).default;
117
+ // fs.unlinkSync(configPath + '.js')
118
+ }
119
+ else {
120
+ vitrifyConfig = (await import(new URL('vitrify.config.js', appDir).pathname)).default;
121
+ }
46
122
  if (typeof vitrifyConfig === 'function')
47
- vitrifyConfig = vitrifyConfig({ mode, command });
123
+ vitrifyConfig = await vitrifyConfig({ mode, command });
48
124
  }
49
125
  catch (e) {
50
- console.error(e);
51
- console.log('No vitrify.config.js file found, using defaults');
126
+ console.log('No vitrify.config.(ts|js) file found, using defaults');
52
127
  vitrifyConfig = {};
53
128
  }
54
- let { productName = 'Product name' } = JSON.parse(readFileSync(new URL('package.json', appDir).pathname, {
55
- encoding: 'utf-8'
56
- }));
129
+ const localPackages = ['vue', 'vue-router'];
130
+ const cliPackages = [];
131
+ const packageUrls = vitrifyConfig.vitrify?.urls?.packages || {};
132
+ await (async () => {
133
+ for (const val of localPackages)
134
+ packageUrls[val] = getPkgJsonDir(new URL(await resolve(val, appDir.href)));
135
+ })();
136
+ // await (async () => {
137
+ // for (const val of cliPackages)
138
+ // packageUrls[val] = getPkgJsonDir(
139
+ // new URL(await resolve(val, cliDir!.href))
140
+ // )
141
+ // })()
142
+ let productName = 'Product name';
143
+ try {
144
+ ;
145
+ ({ productName } = JSON.parse(readFileSync(new URL('package.json', appDir).pathname, {
146
+ encoding: 'utf-8'
147
+ })));
148
+ }
149
+ catch (e) {
150
+ console.error('package.json not found');
151
+ }
57
152
  const ssrTransformCustomDir = () => {
58
153
  return {
59
154
  props: [],
@@ -73,13 +168,14 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
73
168
  let onBootHooks;
74
169
  let onRenderedHooks;
75
170
  let onMountedHooks;
76
- let onSetupHooks;
171
+ let onSetupFiles;
77
172
  let globalCss;
78
173
  let staticImports;
79
174
  let sassVariables;
80
175
  let additionalData;
81
176
  const plugins = [
82
177
  vuePlugin({
178
+ compiler: await import('vue/compiler-sfc'),
83
179
  template: {
84
180
  ssr: !!ssr,
85
181
  compilerOptions: {
@@ -107,7 +203,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
107
203
  onBootHooks = config.vitrify?.hooks?.onBoot || [];
108
204
  onRenderedHooks = config.vitrify?.hooks?.onRendered || [];
109
205
  onMountedHooks = config.vitrify?.hooks?.onMounted || [];
110
- onSetupHooks = config?.vitrify?.hooks?.onSetup || [];
206
+ onSetupFiles = config?.vitrify?.hooks?.onSetup || [];
111
207
  globalCss = config.vitrify?.globalCss || [];
112
208
  staticImports = config.vitrify?.staticImports || {};
113
209
  sassVariables = config.vitrify?.sass?.variables || {};
@@ -134,9 +230,16 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
134
230
  },
135
231
  resolveId(id) {
136
232
  if (VIRTUAL_MODULES.includes(id))
137
- return id;
233
+ return { id, moduleSideEffects: false };
138
234
  return;
139
235
  },
236
+ transform: (code, id) => {
237
+ if (id.endsWith('main.ts') && id.includes('vitrify')) {
238
+ code =
239
+ `${globalCss.map((css) => `import '${css}'`).join('\n')}\n` + code;
240
+ }
241
+ return code;
242
+ },
140
243
  load(id) {
141
244
  if (id === 'virtual:vitrify-hooks') {
142
245
  return `export const onBoot = [${onBootHooks
@@ -148,12 +251,22 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
148
251
  export const onRendered = [${onRenderedHooks
149
252
  .map((fn) => `${String(fn)}`)
150
253
  .join(', ')}]
151
- export const onSetup = [${onSetupHooks
152
- .map((fn) => `${String(fn)}`)
153
- .join(', ')}]`;
154
- }
155
- else if (id === 'virtual:global-css') {
156
- return `${globalCss.map((css) => `import '${css}'`).join('\n')}`;
254
+ export const onSetup = []
255
+ ${onSetupFiles
256
+ .map((url, index) => `import ${url.pathname
257
+ .replaceAll('/', '')
258
+ .replaceAll('.', '')} from '${url.pathname}'; onSetup.push(${url.pathname
259
+ .replaceAll('/', '')
260
+ .replaceAll('.', '')})`)
261
+ .join('\n')}`;
262
+ // export const onSetup = [${onSetupHooks
263
+ // .map((fn) => `${String(fn)}`)
264
+ // .join(', ')}]`
265
+ /**
266
+ * CSS imports in virtual files do not seem to work. Using transform() instead
267
+ */
268
+ // } else if (id === 'virtual:global-css') {
269
+ // return `${globalCss.map((css) => `import '${css}'`).join('\n')}`
157
270
  }
158
271
  else if (id === 'virtual:static-imports') {
159
272
  return `${Object.entries(staticImports)
@@ -188,6 +301,9 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
188
301
  case 'client':
189
302
  entry = new URL('ssr/entry-client.ts', frameworkDir).pathname;
190
303
  break;
304
+ case 'fastify':
305
+ entry = new URL('entry.ts', fastifyDir).pathname;
306
+ break;
191
307
  default:
192
308
  entry = new URL('csr/entry.ts', frameworkDir).pathname;
193
309
  }
@@ -221,18 +337,91 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
221
337
  { find: 'cwd', replacement: cwd.pathname },
222
338
  { find: 'boot', replacement: new URL('boot/', srcDir).pathname },
223
339
  { find: 'assets', replacement: new URL('assets/', srcDir).pathname },
224
- { find: 'vue', replacement: packageUrls['vue'].pathname },
225
- { find: 'vue-router', replacement: packageUrls['vue-router'].pathname },
226
- { find: 'vitrify', replacement: cliDir.pathname }
340
+ ...Object.entries(packageUrls).map(([key, value]) => ({
341
+ find: key,
342
+ replacement: value.pathname
343
+ }))
344
+ // { find: 'vue', replacement: packageUrls['vue'].pathname },
345
+ // { find: 'vue-router', replacement: packageUrls['vue-router'].pathname },
346
+ // { find: 'vitrify', replacement: cliDir.pathname }
227
347
  ];
228
348
  if (command === 'test')
229
349
  alias.push({
230
350
  find: 'vitest',
231
- replacement: packageUrls.vitest.pathname
351
+ replacement: new URL(await resolve('vitest', cliDir.href)).pathname
232
352
  });
353
+ let rollupOptions;
354
+ let noExternal = [];
355
+ const external = [...builtinModules, ...serverModules];
356
+ if (ssr === 'server') {
357
+ rollupOptions = {
358
+ input: [
359
+ new URL('ssr/entry-server.ts', frameworkDir).pathname,
360
+ new URL('ssr/prerender.ts', frameworkDir).pathname,
361
+ new URL('ssr/server.ts', frameworkDir).pathname
362
+ ],
363
+ external,
364
+ output: {
365
+ minifyInternalExports: false,
366
+ entryFileNames: '[name].mjs',
367
+ chunkFileNames: '[name].mjs',
368
+ // format: 'es',
369
+ manualChunks: (id) => {
370
+ if (id.includes('vitrify/src/vite/')) {
371
+ const name = id.split('/').at(-1)?.split('.').at(0);
372
+ if (name && manualChunks.includes(name))
373
+ return name;
374
+ }
375
+ else if (id.includes('node_modules')) {
376
+ return 'vendor';
377
+ }
378
+ }
379
+ }
380
+ };
381
+ // Create a SSR bundle
382
+ noExternal = [
383
+ new RegExp(`^(?!(${[...builtinModules, ...serverModules].join('|')}))`)
384
+ // new RegExp(`^(?!.*(${[...builtinModules, ...serverModules].join('|')}))`)
385
+ ];
386
+ }
387
+ else if (ssr === 'fastify') {
388
+ rollupOptions = {
389
+ input: [new URL('server.ts', fastifyDir).pathname],
390
+ external,
391
+ output: {
392
+ minifyInternalExports: false,
393
+ entryFileNames: '[name].mjs',
394
+ chunkFileNames: '[name].mjs',
395
+ // format: 'es',
396
+ manualChunks: (id) => {
397
+ if (id.includes('vitrify/src/vite/')) {
398
+ const name = id.split('/').at(-1)?.split('.').at(0);
399
+ if (name && manualChunks.includes(name))
400
+ return name;
401
+ }
402
+ else if (id.includes('node_modules')) {
403
+ return 'vendor';
404
+ }
405
+ }
406
+ }
407
+ };
408
+ // Create a SSR bundle
409
+ noExternal = [
410
+ new RegExp(`^(?!(${[...builtinModules, ...serverModules].join('|')}))`)
411
+ ];
412
+ }
413
+ else {
414
+ rollupOptions = {
415
+ // input: [new URL('index.html', frameworkDir).pathname],
416
+ // output: {
417
+ // format: 'es'
418
+ // }
419
+ };
420
+ }
233
421
  const config = {
234
- root: frameworkDir.pathname,
422
+ root: ssr === 'fastify' ? appDir.pathname : frameworkDir.pathname,
235
423
  publicDir: publicDir.pathname,
424
+ envDir: appDir.pathname,
236
425
  vitrify: {
237
426
  productName,
238
427
  urls: {
@@ -245,7 +434,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
245
434
  },
246
435
  plugins,
247
436
  optimizeDeps: {
248
- exclude: ['vue']
437
+ exclude: ['vue', ...serverModules, ...builtinModules]
249
438
  },
250
439
  resolve: {
251
440
  // Dedupe uses require which breaks ESM SSR builds
@@ -256,45 +445,42 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
256
445
  alias
257
446
  },
258
447
  build: {
259
- target: ssr === 'server' ? 'esnext' : 'modules',
260
- ssr: ssr === 'server' ? true : false,
448
+ target: ssr === 'server' || ssr === 'fastify' ? 'esnext' : 'modules',
449
+ ssr: ssr === 'server' || ssr === 'fastify' ? true : false,
261
450
  ssrManifest: ssr === 'client' || ssr === 'ssg',
262
- rollupOptions: ssr === 'server'
263
- ? {
264
- input: [
265
- new URL('ssr/entry-server.ts', frameworkDir).pathname,
266
- new URL('ssr/prerender.ts', frameworkDir).pathname,
267
- new URL('ssr/server.ts', frameworkDir).pathname
268
- ],
269
- output: {
270
- minifyInternalExports: false,
271
- entryFileNames: '[name].mjs',
272
- chunkFileNames: '[name].mjs',
273
- format: 'es',
274
- manualChunks: (id) => {
275
- if (id.includes('vitrify/src/vite/')) {
276
- const name = id.split('/').at(-1)?.split('.').at(0);
277
- console.log(name);
278
- if (manualChunks.includes(id))
279
- return name;
280
- }
281
- else if (id.includes('node_modules')) {
282
- return 'vendor';
283
- }
284
- }
285
- }
286
- }
287
- : {
288
- output: {
289
- format: 'es'
290
- }
291
- }
451
+ rollupOptions
452
+ // ssr === 'server'
453
+ // ? {
454
+ // input: [
455
+ // new URL('ssr/entry-server.ts', frameworkDir).pathname,
456
+ // new URL('ssr/prerender.ts', frameworkDir).pathname,
457
+ // new URL('ssr/server.ts', frameworkDir).pathname
458
+ // ],
459
+ // output: {
460
+ // minifyInternalExports: false,
461
+ // entryFileNames: '[name].mjs',
462
+ // chunkFileNames: '[name].mjs',
463
+ // format: 'es',
464
+ // manualChunks: (id) => {
465
+ // if (id.includes('vitrify/src/vite/')) {
466
+ // const name = id.split('/').at(-1)?.split('.').at(0)
467
+ // if (name && manualChunks.includes(name)) return name
468
+ // } else if (id.includes('node_modules')) {
469
+ // return 'vendor'
470
+ // }
471
+ // }
472
+ // }
473
+ // }
474
+ // : {
475
+ // output: {
476
+ // format: 'es'
477
+ // }
478
+ // }
292
479
  },
293
480
  ssr: {
294
481
  // Create a SSR bundle
295
- noExternal: [
296
- new RegExp(`^(?!.*(${[...builtinModules, ...serverModules].join('|')}))`)
297
- ]
482
+ external,
483
+ noExternal
298
484
  },
299
485
  define: {
300
486
  __BASE_URL__: `'/'`
@@ -61,7 +61,7 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
61
61
  const quasarPlugins = await import('virtual:quasar-plugins');
62
62
  // @ts-ignore
63
63
  const directives = await import('quasar/src/directives.js');
64
- app.use(staticImports.Quasar, {
64
+ app.use(staticImports?.Quasar, {
65
65
  plugins: quasarPlugins,
66
66
  directives
67
67
  }, ssrContext);
@@ -137,9 +137,14 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
137
137
  replacement: new URL('src/', urls?.packages?.quasar).pathname
138
138
  },
139
139
  {
140
- find: 'quasar',
141
- replacement: new URL('src/', urls?.packages?.quasar).pathname
140
+ find: new RegExp('^quasar$'),
141
+ replacement: new URL('src/index.all.js', urls?.packages?.quasar)
142
+ .pathname
142
143
  },
144
+ // {
145
+ // find: 'quasar',
146
+ // replacement: new URL('src/index.all.js', urls?.packages?.quasar).pathname
147
+ // },
143
148
  {
144
149
  find: `@quasar/extras`,
145
150
  replacement: new URL('.', urls?.packages?.['@quasar/extras'])
@@ -167,7 +172,7 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
167
172
  config: async (config, env) => ({
168
173
  resolve: {
169
174
  alias: [
170
- { find: new RegExp('^quasar$'), replacement: 'virtual:quasar' }
175
+ // { find: new RegExp('^quasar$'), replacement: 'virtual:quasar' }
171
176
  ]
172
177
  }
173
178
  }),
@@ -1,8 +1,8 @@
1
1
  #!/usr/bin/node --experimental-specifier-resolution=node
2
2
  export declare function build(opts: {
3
- ssr?: 'client' | 'server' | 'ssg';
3
+ ssr?: 'client' | 'server' | 'ssg' | 'fastify';
4
4
  base?: string;
5
- outDir?: string;
5
+ outDir: string;
6
6
  appDir?: URL;
7
7
  publicDir?: URL;
8
8
  }): Promise<import("rollup").RollupOutput | import("rollup").RollupOutput[] | import("rollup").RollupWatcher>;
@@ -1,15 +1,51 @@
1
1
  /// <reference types="node" />
2
- import type { ViteDevServer, LogLevel } from 'vite';
2
+ import type { LogLevel, InlineConfig } from 'vite';
3
+ import { ViteDevServer } from 'vite';
3
4
  import type { Server } from 'net';
5
+ export declare function createVitrifyDevServer({ port, logLevel, mode, framework, host, appDir, publicDir }: {
6
+ port?: number;
7
+ logLevel?: LogLevel;
8
+ mode?: 'csr' | 'ssr' | 'fastify';
9
+ framework?: 'vue';
10
+ host?: string;
11
+ appDir?: URL;
12
+ publicDir?: URL;
13
+ }): Promise<ViteDevServer>;
4
14
  export declare function createServer({ port, logLevel, mode, framework, host, appDir, publicDir }: {
5
15
  port?: number;
6
16
  logLevel?: LogLevel;
7
- mode?: 'csr' | 'ssr';
17
+ mode?: 'csr' | 'ssr' | 'fastify';
8
18
  framework?: 'vue';
9
19
  host?: string;
10
20
  appDir?: URL;
11
21
  publicDir?: URL;
12
22
  }): Promise<{
13
23
  server: Server;
14
- vite: ViteDevServer;
24
+ config: Readonly<Omit<import("vite").UserConfig, "plugins" | "assetsInclude" | "optimizeDeps" | "worker"> & {
25
+ configFile: string | undefined;
26
+ configFileDependencies: string[];
27
+ inlineConfig: InlineConfig;
28
+ root: string;
29
+ base: string;
30
+ publicDir: string;
31
+ cacheDir: string;
32
+ command: "build" | "serve";
33
+ mode: string;
34
+ isWorker: boolean;
35
+ isProduction: boolean;
36
+ env: Record<string, any>;
37
+ resolve: import("vite").ResolveOptions & {
38
+ alias: import("vite").Alias[];
39
+ };
40
+ plugins: readonly import("vite").Plugin[];
41
+ server: import("vite").ResolvedServerOptions;
42
+ build: Required<import("vite").BuildOptions>;
43
+ preview: import("vite").ResolvedPreviewOptions;
44
+ assetsInclude: (file: string) => boolean;
45
+ logger: import("vite").Logger;
46
+ createResolver: (options?: Partial<import("vite").InternalResolveOptions> | undefined) => import("vite").ResolveFn;
47
+ optimizeDeps: import("vite").DepOptimizationOptions;
48
+ worker: import("vite").ResolveWorkerOptions;
49
+ spa: boolean;
50
+ }>;
15
51
  }>;
@@ -1,14 +1,17 @@
1
1
  import type { FastifyPluginCallback, FastifyRequest, FastifyReply } from 'fastify';
2
- import type { ViteDevServer } from 'vite';
3
2
  import type { OnRenderedHook } from '../../vitrify-config.js';
3
+ import type { ViteDevServer } from 'vite';
4
4
  export interface FastifySsrOptions {
5
5
  baseUrl?: string;
6
6
  provide?: (req: FastifyRequest, res: FastifyReply) => Promise<Record<string, unknown>>;
7
+ vitrifyDir?: URL;
7
8
  vite?: ViteDevServer;
8
- cliDir?: URL;
9
9
  appDir?: URL;
10
+ publicDir?: URL;
10
11
  productName?: string;
11
- onRenderedHooks?: OnRenderedHook[];
12
+ onRendered?: OnRenderedHook[];
13
+ mode?: string;
12
14
  }
13
15
  declare const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions>;
14
16
  export { fastifySsrPlugin };
17
+ export declare type FastifySsrPlugin = typeof fastifySsrPlugin;
@@ -1,9 +1,13 @@
1
1
  /// <reference types="node" />
2
2
  import type { FastifyInstance } from 'fastify';
3
- import type { OnRenderedHook } from '../../vitrify-config.js';
4
- export declare const createApp: ({ setup, appDir, baseUrl, onRenderedHooks }: {
5
- setup: (fastify: FastifyInstance) => any;
3
+ import type { OnRenderedHook, OnSetupFile } from '../../vitrify-config.js';
4
+ import type { FastifySsrPlugin } from './fastify-ssr-plugin.js';
5
+ export declare const createApp: ({ onSetup, appDir, baseUrl, onRendered, fastifySsrPlugin, vitrifyDir, mode }: {
6
+ onSetup: OnSetupFile[];
6
7
  appDir: URL;
7
8
  baseUrl?: string | undefined;
8
- onRenderedHooks?: OnRenderedHook[] | undefined;
9
- }) => FastifyInstance<import("http").Server, import("http").IncomingMessage, import("http").ServerResponse, import("fastify").FastifyLoggerInstance> & PromiseLike<FastifyInstance<import("http").Server, import("http").IncomingMessage, import("http").ServerResponse, import("fastify").FastifyLoggerInstance>>;
9
+ onRendered?: OnRenderedHook[] | undefined;
10
+ fastifySsrPlugin: FastifySsrPlugin;
11
+ vitrifyDir?: URL | undefined;
12
+ mode: string;
13
+ }) => FastifyInstance<import("http").Server, import("http").IncomingMessage, import("http").ServerResponse, pino.Logger, import("fastify").FastifyTypeProviderDefault> & PromiseLike<FastifyInstance<import("http").Server, import("http").IncomingMessage, import("http").ServerResponse, pino.Logger, import("fastify").FastifyTypeProviderDefault>>;
@@ -0,0 +1,10 @@
1
+ import type { ViteDevServer, ModuleNode } from 'vite';
2
+ /**
3
+ * Collect SSR CSS for Vite
4
+ */
5
+ export declare const componentsModules: (components: string[], vite: ViteDevServer) => Set<ModuleNode>;
6
+ export declare const collectCss: (mods: Set<ModuleNode>, styles?: Map<string, string>, checkedComponents?: Set<unknown>) => string;
7
+ /**
8
+ * Client listener to detect updated modules through HMR, and remove the initial styled attached to the head
9
+ */
10
+ export declare const removeCssHotReloaded: () => void;
@@ -1,2 +1,2 @@
1
1
  import type { RouteRecordRaw } from 'vue-router';
2
- export declare const routesToPaths: (routes?: RouteRecordRaw[] | undefined) => string[];
2
+ export declare const routesToPaths: (routes?: RouteRecordRaw[]) => string[];
@@ -4,7 +4,7 @@ import type { VitrifyContext } from './bin/run.js';
4
4
  import type { VitrifyPlugin } from './plugins/index.js';
5
5
  export declare const VIRTUAL_MODULES: string[];
6
6
  export declare const baseConfig: ({ ssr, appDir, publicDir, command, mode, framework, pwa }: {
7
- ssr?: "server" | "client" | "ssg" | undefined;
7
+ ssr?: "server" | "client" | "ssg" | "fastify" | undefined;
8
8
  appDir?: URL | undefined;
9
9
  publicDir?: URL | undefined;
10
10
  command?: "build" | "dev" | "test" | undefined;
@@ -1,6 +1,6 @@
1
1
  import type { Plugin } from 'vite';
2
2
  export declare type VitrifyPlugin = ({ ssr, mode, command }: {
3
- ssr?: 'server' | 'client' | 'ssg' | false;
3
+ ssr?: 'server' | 'client' | 'ssg' | 'fastify' | false;
4
4
  pwa?: boolean;
5
5
  mode?: 'production' | 'development';
6
6
  command?: 'build' | 'dev' | 'test';
@@ -1,4 +1,3 @@
1
- import type { FastifyInstance } from 'fastify';
2
1
  import type { UserConfig } from 'vite';
3
2
  import type { QuasarConf } from './plugins/quasar.js';
4
3
  import type { ComponentInternalInstance } from '@vue/runtime-core';
@@ -10,13 +9,13 @@ export declare type BootFunction = ({ app, ssrContext, staticImports }: {
10
9
  export declare type OnBootHook = ({ app, ssrContext, staticImports }: {
11
10
  app: any;
12
11
  ssrContext: Record<string, unknown>;
13
- staticImports: Record<string, any>;
12
+ staticImports?: Record<string, any>;
14
13
  }) => Promise<void> | void;
15
14
  export declare type OnMountedHook = (instance: ComponentInternalInstance) => Promise<void> | void;
16
15
  export declare type StaticImports = Record<string, string[]>;
17
16
  export declare type SsrFunction = (html: string, ssrContext: Record<string, any>) => string;
18
17
  export declare type OnRenderedHook = (html: string, ssrContext: Record<string, any>) => string;
19
- export declare type OnSetupHook = (fastify: FastifyInstance) => any;
18
+ export declare type OnSetupFile = URL;
20
19
  export interface VitrifyConfig extends UserConfig {
21
20
  vitrify?: {
22
21
  /**
@@ -31,7 +30,7 @@ export interface VitrifyConfig extends UserConfig {
31
30
  /**
32
31
  * setup() is called directly after instantiating fastify. Use it to register your own plugins, routes etc.
33
32
  */
34
- onSetup?: OnSetupHook[];
33
+ onSetup?: OnSetupFile[];
35
34
  /**
36
35
  * Functions which run in the onMounted hook of the app
37
36
  */