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.
Files changed (54) hide show
  1. package/README.md +2 -2
  2. package/dist/app-urls.js +1 -2
  3. package/dist/bin/build.js +9 -51
  4. package/dist/bin/cli.js +31 -9
  5. package/dist/bin/dev.js +72 -70
  6. package/dist/frameworks/vue/fastify-csr-plugin.js +38 -0
  7. package/dist/frameworks/vue/fastify-ssr-plugin.js +83 -25
  8. package/dist/frameworks/vue/prerender.js +3 -3
  9. package/dist/frameworks/vue/server.js +10 -11
  10. package/dist/helpers/collect-css-ssr.js +61 -0
  11. package/dist/helpers/logger.js +0 -72
  12. package/dist/index.js +310 -130
  13. package/dist/plugins/quasar.js +34 -111
  14. package/dist/types/bin/build.d.ts +2 -2
  15. package/dist/types/bin/dev.d.ts +42 -4
  16. package/dist/types/frameworks/vue/fastify-csr-plugin.d.ts +17 -0
  17. package/dist/types/frameworks/vue/fastify-ssr-plugin.d.ts +6 -3
  18. package/dist/types/frameworks/vue/prerender.d.ts +3 -3
  19. package/dist/types/frameworks/vue/server.d.ts +10 -5
  20. package/dist/types/helpers/collect-css-ssr.d.ts +14 -0
  21. package/dist/types/helpers/logger.d.ts +0 -19
  22. package/dist/types/helpers/routes.d.ts +1 -1
  23. package/dist/types/index.d.ts +4 -2
  24. package/dist/types/plugins/index.d.ts +1 -1
  25. package/dist/types/vitrify-config.d.ts +33 -17
  26. package/package.json +33 -32
  27. package/src/node/app-urls.ts +1 -2
  28. package/src/node/bin/build.ts +11 -57
  29. package/src/node/bin/cli.ts +38 -10
  30. package/src/node/bin/dev.ts +106 -80
  31. package/src/node/bin/test.ts +0 -3
  32. package/src/node/frameworks/vue/fastify-csr-plugin.ts +72 -0
  33. package/src/node/frameworks/vue/fastify-ssr-plugin.ts +99 -28
  34. package/src/node/frameworks/vue/prerender.ts +5 -5
  35. package/src/node/frameworks/vue/server.ts +24 -17
  36. package/src/node/helpers/collect-css-ssr.ts +85 -0
  37. package/src/node/helpers/logger.ts +0 -87
  38. package/src/node/index.ts +353 -146
  39. package/src/node/plugins/index.ts +1 -1
  40. package/src/node/plugins/quasar.ts +39 -116
  41. package/src/node/vitrify-config.ts +44 -17
  42. package/src/vite/fastify/entry.ts +11 -0
  43. package/src/vite/fastify/server.ts +12 -0
  44. package/src/vite/vue/csr/app.ts +25 -0
  45. package/src/vite/vue/csr/fastify-csr-plugin.ts +3 -0
  46. package/src/vite/vue/csr/server.ts +8 -0
  47. package/src/vite/vue/index.html +1 -0
  48. package/src/vite/vue/main.ts +5 -20
  49. package/src/vite/vue/ssr/app.ts +25 -0
  50. package/src/vite/vue/ssr/entry-server.ts +13 -1
  51. package/src/vite/vue/ssr/fastify-ssr-plugin.ts +2 -118
  52. package/src/vite/vue/ssr/prerender.ts +2 -2
  53. package/src/vite/vue/ssr/server.ts +24 -15
  54. package/src/node/helpers/ssr.ts.bak +0 -52
@@ -31,41 +31,25 @@ export const injectSsrContext = (html, ssrContext) => html
31
31
  }
32
32
  return `${start} class="${classes.trim()}" ${ssrContext._meta.bodyAttrs || ''}${end}${ssrContext._meta.bodyTags || ''}`;
33
33
  });
34
- // export interface Configuration {
35
- // ssr?: 'server' | 'client' | 'ssg' | false
36
- // }
37
34
  export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
38
- // const extraPlugins: Plugin[] = []
39
- // const ctx = {
40
- // prod: process.env.MODE === 'production',
41
- // dev: process.env.MODE === 'development',
42
- // mode: {
43
- // ssr: !!ssr,
44
- // pwa: !!pwa
45
- // }
46
- // }
47
- // let bootFilePaths: Record<string, any> = {}
48
- // let components: string[] = []
49
35
  let plugins = [];
50
- // let css: string[] = []
51
- let extras = [];
52
36
  return [
53
- // {
54
- // name: 'legacy-support',
55
- // enforce: 'pre',
56
- // transform (code, id) {
57
- // /**
58
- // * 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.
59
- // */
60
- // if (code.includes('app.use(VuePlugin)')) {
61
- // code = code.replace(/app\.use\(VuePlugin\)/g, `app.use(VuePlugin.install ? VuePlugin : VuePlugin.default)`)
62
- // }
63
- // return code
64
- // }
65
- // },
66
37
  Components({
67
38
  resolvers: [QuasarResolver()]
68
39
  }),
40
+ {
41
+ name: 'vite-plugin-quasar-transform',
42
+ enforce: 'pre',
43
+ transform: (code, id, options) => {
44
+ const { ssr } = options || {};
45
+ code = code
46
+ .replaceAll('__QUASAR_SSR__', ssr ? ssr.toString() : 'false')
47
+ .replaceAll('__QUASAR_SSR_SERVER__', 'import.meta.env.SSR')
48
+ .replaceAll('__QUASAR_SSR_CLIENT__', '!import.meta.env.SSR')
49
+ .replaceAll('__QUASAR_SSR_PWA__', pwa ? '!import.meta.env.SSR' : 'false');
50
+ return code;
51
+ }
52
+ },
69
53
  {
70
54
  name: 'vite-plugin-quasar-setup',
71
55
  enforce: 'pre',
@@ -84,15 +68,13 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
84
68
  $q.onSSRHydrated !== void 0 && $q.onSSRHydrated();
85
69
  }
86
70
  ];
87
- const bootFunctions = [
71
+ const onBootHooks = [
88
72
  async ({ app, ssrContext, staticImports }) => {
89
- // @ts-ignore
90
- // const quasarVuePlugin = (await import('quasar/vue-plugin')).default
91
73
  // @ts-ignore
92
74
  const quasarPlugins = await import('virtual:quasar-plugins');
93
75
  // @ts-ignore
94
76
  const directives = await import('quasar/src/directives.js');
95
- app.use(staticImports.Quasar, {
77
+ app.use(staticImports?.Quasar, {
96
78
  plugins: quasarPlugins,
97
79
  directives
98
80
  }, ssrContext);
@@ -101,14 +83,14 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
101
83
  return {
102
84
  vitrify: {
103
85
  urls,
104
- bootFunctions,
105
- ssrFunctions: [injectSsrContext],
106
86
  globalCss,
107
87
  staticImports: {
108
88
  quasar: ['Quasar']
109
89
  },
110
90
  hooks: {
111
- onMounted: onMountedHooks
91
+ onBoot: onBootHooks,
92
+ onMounted: onMountedHooks,
93
+ onRendered: [injectSsrContext]
112
94
  },
113
95
  sass: {
114
96
  additionalData: [`@import 'quasar/src/css/index.sass'`]
@@ -120,50 +102,10 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
120
102
  {
121
103
  name: 'vite-plugin-quasar',
122
104
  enforce: 'post',
123
- // transformIndexHtml: {
124
- // enforce: 'post',
125
- // transform: (html) => {
126
- // return html.replace(
127
- // '<!--product-name-->',
128
- // productName
129
- // )
130
- // }
131
- // },
132
105
  config: async (config, env) => {
133
- // let appDir: URL
134
- // let cliDir: URL
135
- // let cwd: URL
136
- // let quasarDir: URL
137
- // let quasarConf: QuasarConf | undefined
138
106
  const { quasar: quasarConf, vitrify: { urls } = {} } = config;
139
107
  const quasarPkgJsonPath = new URL('package.json', urls?.packages?.quasar).pathname;
140
108
  const { version } = JSON.parse(readFileSync(quasarPkgJsonPath, { encoding: 'utf-8' }));
141
- // if (quasarConf?.boot) {
142
- // bootFilePaths = (quasarConf.boot as (Record<string, any> | string)[])
143
- // .filter(entry => {
144
- // if (typeof entry === 'object') return (entry.server && (ssr === 'server'))
145
- // else if (entry !== '') return true
146
- // })
147
- // .map(entry => {
148
- // if (typeof entry === 'string') return entry
149
- // else if (typeof entry === 'object') return entry.path
150
- // })
151
- // .reduce((acc, entry) => {
152
- // if (entry[0] === '~') {
153
- // const split = entry.substring(1).split('/')
154
- // const name = split[0].replace(/[|&;$%@"<>()+,]/g, "");
155
- // acc[name] = {
156
- // path: new URL(`node_modules/${entry.substring(1)}`, urls?.app).pathname
157
- // }
158
- // } else {
159
- // const name = entry.split('.')[0]
160
- // acc[name] = {
161
- // path: `src/boot/${entry}`
162
- // }
163
- // }
164
- // return acc
165
- // }, {})
166
- // }
167
109
  /**
168
110
  * All components should have been auto-imported
169
111
  */
@@ -175,13 +117,6 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
175
117
  ];
176
118
  plugins = quasarConf?.framework.plugins;
177
119
  }
178
- // css = (quasarConf?.css || []).map((v => {
179
- // if (v[0] === '~') {
180
- // return v.slice(1)
181
- // }
182
- // return v
183
- // })).map((v) => `@import '${v}'`)
184
- extras = quasarConf?.extras || [];
185
120
  return {
186
121
  resolve: {
187
122
  alias: [
@@ -214,45 +149,33 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
214
149
  find: 'quasar/src',
215
150
  replacement: new URL('src/', urls?.packages?.quasar).pathname
216
151
  },
217
- // ...extras.map(extra => ({
218
- // find: `@quasar/extras/${extra}/${extra}.css`,
219
- // replacement: new URL(`${extra}/${extra}.css`, urls?.packages?.['@quasar/extras']).pathname
220
- // })
221
- // ),
222
152
  {
223
- find: 'quasar',
224
- replacement: new URL('src/', urls?.packages?.quasar).pathname
153
+ find: new RegExp('^quasar$'),
154
+ replacement: new URL('src/index.all.js', urls?.packages?.quasar)
155
+ .pathname
225
156
  },
157
+ // {
158
+ // find: 'quasar',
159
+ // replacement: new URL('src/index.all.js', urls?.packages?.quasar).pathname
160
+ // },
226
161
  {
227
162
  find: `@quasar/extras`,
228
163
  replacement: new URL('.', urls?.packages?.['@quasar/extras'])
229
164
  .pathname
230
165
  }
231
- // { find: new RegExp('^quasar$'), replacement: new URL('src/index.all.js', urls?.packages?.quasar).pathname },
232
- // { find: new RegExp('^quasar$'), replacement: 'virtual:quasar' },
233
166
  ]
234
167
  },
235
168
  define: {
236
169
  __DEV__: process.env.NODE_ENV !== 'production' || true,
237
- __QUASAR_VERSION__: `'${version}'`,
238
- __QUASAR_SSR__: !!ssr,
239
- __QUASAR_SSR_SERVER__: ssr === 'server',
240
- __QUASAR_SSR_CLIENT__: ssr === 'client',
241
- __QUASAR_SSR_PWA__: ssr === 'client' && pwa
170
+ __QUASAR_VERSION__: `'${version}'`
171
+ // __QUASAR_SSR__: !!ssr,
172
+ // // __QUASAR_SSR_SERVER__: ssr === 'server',
173
+ // __QUASAR_SSR_SERVER__: `import.meta.env.SSR`,
174
+ // // __QUASAR_SSR_CLIENT__: ssr === 'client',
175
+ // __QUASAR_SSR_CLIENT__: `!import.meta.env.SSR`,
176
+ // // __QUASAR_SSR_PWA__: ssr === 'client' && pwa
177
+ // __QUASAR_SSR_PWA__: pwa ? `!import.meta.env.SSR` : false
242
178
  },
243
- // css: {
244
- // preprocessorOptions: {
245
- // sass: {
246
- // additionalData: `@import 'quasar/src/css/index.sass'`
247
- // // [
248
- // // // ...extras.map(extra => `@import "@quasar/extras/${extra}/${extra}.css"`),
249
- // // // ...extras.map(extra => `@import ${new URL(`${extra}/${extra}.css`, urls?.packages?.['@quasar/extras']).pathname}`) || [],
250
- // // // config.css?.preprocessorOptions?.sass?.additionalData,
251
- // // `@import 'quasar/src/css/index.sass'`
252
- // // ].join('\n')
253
- // }
254
- // }
255
- // },
256
179
  ssr: {
257
180
  noExternal: ['quasar']
258
181
  }
@@ -265,7 +188,7 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
265
188
  config: async (config, env) => ({
266
189
  resolve: {
267
190
  alias: [
268
- { find: new RegExp('^quasar$'), replacement: 'virtual:quasar' }
191
+ // { find: new RegExp('^quasar$'), replacement: 'virtual:quasar' }
269
192
  ]
270
193
  }
271
194
  }),
@@ -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,53 @@
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';
4
- export declare function createServer({ port, logLevel, mode, framework, host, appDir, publicDir }: {
5
+ export declare function createVitrifyDevServer({ port, logLevel, ssr, framework, host, appDir, publicDir, base }: {
5
6
  port?: number;
6
7
  logLevel?: LogLevel;
7
- mode?: 'csr' | 'ssr';
8
+ ssr?: 'ssr' | 'fastify';
9
+ framework?: 'vue';
10
+ host?: string;
11
+ appDir?: URL;
12
+ publicDir?: URL;
13
+ base?: string;
14
+ }): Promise<ViteDevServer>;
15
+ export declare function createServer({ port, logLevel, ssr, framework, host, appDir, publicDir }: {
16
+ port?: number;
17
+ logLevel?: LogLevel;
18
+ ssr?: 'ssr' | 'fastify';
8
19
  framework?: 'vue';
9
20
  host?: string;
10
21
  appDir?: URL;
11
22
  publicDir?: URL;
12
23
  }): Promise<{
13
24
  server: Server;
14
- vite: ViteDevServer;
25
+ config: Readonly<Omit<import("vite").UserConfig, "plugins" | "assetsInclude" | "optimizeDeps" | "worker"> & {
26
+ configFile: string | undefined;
27
+ configFileDependencies: string[];
28
+ inlineConfig: InlineConfig;
29
+ root: string;
30
+ base: string;
31
+ publicDir: string;
32
+ cacheDir: string;
33
+ command: "build" | "serve";
34
+ mode: string;
35
+ isWorker: boolean;
36
+ isProduction: boolean;
37
+ env: Record<string, any>;
38
+ resolve: import("vite").ResolveOptions & {
39
+ alias: import("vite").Alias[];
40
+ };
41
+ plugins: readonly import("vite").Plugin[];
42
+ server: import("vite").ResolvedServerOptions;
43
+ build: Required<import("vite").BuildOptions>;
44
+ preview: import("vite").ResolvedPreviewOptions;
45
+ ssr: import("vite").ResolvedSSROptions | undefined;
46
+ assetsInclude: (file: string) => boolean;
47
+ logger: import("vite").Logger;
48
+ createResolver: (options?: Partial<import("vite").InternalResolveOptions> | undefined) => import("vite").ResolveFn;
49
+ optimizeDeps: import("vite").DepOptimizationOptions;
50
+ worker: import("vite").ResolveWorkerOptions;
51
+ spa: boolean;
52
+ }>;
15
53
  }>;
@@ -0,0 +1,17 @@
1
+ import type { FastifyPluginCallback, FastifyRequest, FastifyReply } from 'fastify';
2
+ import type { OnRenderedHook } from '../../vitrify-config.js';
3
+ import type { ViteDevServer } from 'vite';
4
+ export interface FastifySsrOptions {
5
+ baseUrl?: string;
6
+ provide?: (req: FastifyRequest, res: FastifyReply) => Promise<Record<string, unknown>>;
7
+ vitrifyDir?: URL;
8
+ vite?: ViteDevServer;
9
+ appDir?: URL;
10
+ publicDir?: URL;
11
+ productName?: string;
12
+ onRendered?: OnRenderedHook[];
13
+ mode?: string;
14
+ }
15
+ declare const fastifyCsrPlugin: FastifyPluginCallback<FastifySsrOptions>;
16
+ export { fastifyCsrPlugin };
17
+ export declare type FastifyCsrPlugin = typeof fastifyCsrPlugin;
@@ -1,14 +1,17 @@
1
1
  import type { FastifyPluginCallback, FastifyRequest, FastifyReply } from 'fastify';
2
+ import type { OnRenderedHook } from '../../vitrify-config.js';
2
3
  import type { ViteDevServer } from 'vite';
3
- import type { SsrFunction } from '../../vitrify-config.js';
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
- ssrFunctions?: SsrFunction[];
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,8 +1,8 @@
1
- import type { SsrFunction } from '../../vitrify-config.js';
2
- export declare const prerender: ({ outDir, templatePath, manifestPath, entryServerPath, ssrFunctions }: {
1
+ import type { OnRenderedHook } from '../../vitrify-config.js';
2
+ export declare const prerender: ({ outDir, templatePath, manifestPath, entryServerPath, onRenderedHooks }: {
3
3
  outDir: string;
4
4
  templatePath: string;
5
5
  manifestPath: string;
6
6
  entryServerPath: string;
7
- ssrFunctions: SsrFunction[];
7
+ onRenderedHooks: OnRenderedHook[];
8
8
  }) => Promise<void[]>;
@@ -1,9 +1,14 @@
1
1
  /// <reference types="node" />
2
2
  import type { FastifyInstance } from 'fastify';
3
- import type { SsrFunction } from '../../vitrify-config.js';
4
- export declare const createApp: ({ setup, appDir, baseUrl, ssrFunctions }: {
5
- setup: (fastify: FastifyInstance) => any;
3
+ import type { OnRenderedHook, OnSetupFile } from '../../vitrify-config.js';
4
+ import type { FastifyCsrPlugin } from './fastify-csr-plugin.js';
5
+ import type { FastifySsrPlugin } from './fastify-ssr-plugin.js';
6
+ export declare const createApp: ({ onSetup, appDir, baseUrl, onRendered, fastifyPlugin, vitrifyDir, mode }: {
7
+ onSetup: OnSetupFile[];
6
8
  appDir: URL;
7
9
  baseUrl?: string | undefined;
8
- ssrFunctions?: SsrFunction[] | 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>>;
10
+ onRendered?: OnRenderedHook[] | undefined;
11
+ fastifyPlugin: FastifySsrPlugin | FastifyCsrPlugin;
12
+ vitrifyDir?: URL | undefined;
13
+ mode: string;
14
+ }) => 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,14 @@
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, styles, checkedComponents }: {
7
+ mods: Set<ModuleNode>;
8
+ styles?: Map<string, string> | undefined;
9
+ checkedComponents?: Set<unknown> | undefined;
10
+ }) => string;
11
+ /**
12
+ * Client listener to detect updated modules through HMR, and remove the initial styled attached to the head
13
+ */
14
+ export declare const removeCssHotReloaded: () => void;
@@ -1,23 +1,4 @@
1
1
  /// <reference types="node" />
2
2
  import type { Server } from 'net';
3
3
  import type { ResolvedConfig } from 'vite';
4
- export declare const clearConsole: () => void;
5
- export declare const log: (msg?: string | undefined) => void;
6
- export declare const warn: (msg?: string | undefined, pill?: string | undefined) => void;
7
- export declare const fatal: (msg?: string | undefined, pill?: string | undefined) => never;
8
- /**
9
- * Extended approach - Compilation status & pills
10
- */
11
- export declare const successPill: (msg?: string | undefined) => string;
12
- export declare const infoPill: (msg?: string | undefined) => string;
13
- export declare const errorPill: (msg?: string | undefined) => string;
14
- export declare const warningPill: (msg?: string | undefined) => string;
15
- export declare const success: (msg?: string | undefined, title?: string) => void;
16
- export declare const getSuccess: (msg?: string | undefined, title?: string | undefined) => string;
17
- export declare const info: (msg?: string | undefined, title?: string) => void;
18
- export declare const getInfo: (msg?: string | undefined, title?: string | undefined) => string;
19
- export declare const error: (msg?: string | undefined, title?: string) => void;
20
- export declare const getError: (msg?: string | undefined, title?: string) => string;
21
- export declare const warning: (msg?: string | undefined, title?: string) => void;
22
- export declare const getWarning: (msg?: string | undefined, title?: string) => string;
23
4
  export declare function printHttpServerUrls(server: Server, config: ResolvedConfig): 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[];
@@ -3,13 +3,15 @@ import type { BootFunction, VitrifyConfig } 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[];
6
- export declare const baseConfig: ({ ssr, appDir, publicDir, command, mode, framework, pwa }: {
7
- ssr?: "server" | "client" | "ssg" | undefined;
6
+ export declare const baseConfig: ({ ssr, appDir, publicDir, base, command, mode, framework, pwa }: {
7
+ ssr?: "server" | "client" | "ssg" | "fastify" | undefined;
8
8
  appDir?: URL | undefined;
9
9
  publicDir?: URL | undefined;
10
+ base?: string | undefined;
10
11
  command?: "build" | "dev" | "test" | undefined;
11
12
  mode?: "production" | "development" | undefined;
12
13
  framework?: "vue" | undefined;
13
14
  pwa?: boolean | undefined;
14
15
  }) => Promise<InlineConfig>;
16
+ export declare const vitrifyDir: URL;
15
17
  export type { VitrifyConfig, VitrifyPlugin, VitrifyContext, BootFunction };
@@ -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,5 +1,4 @@
1
- import type { FastifyInstance } from 'fastify';
2
- import type { UserConfig } from 'vite';
1
+ import type { Alias, UserConfig } from 'vite';
3
2
  import type { QuasarConf } from './plugins/quasar.js';
4
3
  import type { ComponentInternalInstance } from '@vue/runtime-core';
5
4
  export declare type BootFunction = ({ app, ssrContext, staticImports }: {
@@ -7,32 +6,43 @@ export declare type BootFunction = ({ app, ssrContext, staticImports }: {
7
6
  ssrContext: Record<string, unknown>;
8
7
  staticImports: Record<string, any>;
9
8
  }) => Promise<void> | void;
9
+ export declare type OnBootHook = ({ app, ssrContext, staticImports }: {
10
+ app: any;
11
+ ssrContext: Record<string, unknown>;
12
+ staticImports?: Record<string, any>;
13
+ }) => Promise<void> | void;
10
14
  export declare type OnMountedHook = (instance: ComponentInternalInstance) => Promise<void> | void;
11
15
  export declare type StaticImports = Record<string, string[]>;
12
16
  export declare type SsrFunction = (html: string, ssrContext: Record<string, any>) => string;
17
+ export declare type OnRenderedHook = (html: string, ssrContext: Record<string, any>) => string;
18
+ export declare type OnSetupFile = URL;
13
19
  export interface VitrifyConfig extends UserConfig {
14
20
  vitrify?: {
15
21
  /**
16
22
  * Global CSS imports
17
23
  */
18
24
  globalCss?: string[];
19
- /**
20
- * Functions which run after initializing the app
21
- */
22
- bootFunctions?: BootFunction[];
23
- /**
24
- * Functions which run on the server after rendering the app
25
- */
26
- ssrFunctions?: SsrFunction[];
27
25
  /**
28
26
  * Static imports in the app: packageName: [imports]
29
27
  */
30
28
  staticImports?: StaticImports;
31
29
  hooks?: {
30
+ /**
31
+ * setup() is called directly after instantiating fastify. Use it to register your own plugins, routes etc.
32
+ */
33
+ onSetup?: OnSetupFile[];
32
34
  /**
33
35
  * Functions which run in the onMounted hook of the app
34
36
  */
35
- onMounted: OnMountedHook[];
37
+ onMounted?: OnMountedHook[];
38
+ /**
39
+ * Functions which run after initializing the app
40
+ */
41
+ onBoot?: OnBootHook[];
42
+ /**
43
+ * Functions which run after rendering the app (SSR)
44
+ */
45
+ onRendered?: OnRenderedHook[];
36
46
  };
37
47
  /**
38
48
  * Global SASS variables
@@ -41,12 +51,6 @@ export interface VitrifyConfig extends UserConfig {
41
51
  variables?: Record<string, string>;
42
52
  additionalData?: string[];
43
53
  };
44
- fastify?: {
45
- /**
46
- * setup() is called directly after instantiating fastify. Use it to register your own plugins, routes etc.
47
- */
48
- setup: (fastify: FastifyInstance) => any;
49
- };
50
54
  /**
51
55
  * Product name of the application. Will be used for the HTML title tag
52
56
  */
@@ -61,6 +65,18 @@ export interface VitrifyConfig extends UserConfig {
61
65
  cwd?: URL;
62
66
  packages?: Record<string, URL>;
63
67
  };
68
+ /**
69
+ * SSR specific configuration
70
+ */
71
+ ssr?: {
72
+ serverModules?: string[];
73
+ };
74
+ /**
75
+ * Development only configuration
76
+ */
77
+ dev?: {
78
+ alias?: Alias[];
79
+ };
64
80
  };
65
81
  quasar?: QuasarConf;
66
82
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitrify",
3
- "version": "0.2.5",
3
+ "version": "0.5.0",
4
4
  "license": "MIT",
5
5
  "author": "Stefan van Herwijnen",
6
6
  "description": "Pre-configured Vite CLI for your framework",
@@ -49,53 +49,54 @@
49
49
  "homepage": "https://github.com/simsustech/vitrify/tree/main/#readme",
50
50
  "scripts": {
51
51
  "build": "tsc",
52
- "test": "echo \"Error: no test specified\" && exit 0"
52
+ "test": "vitest test/"
53
53
  },
54
54
  "dependencies": {
55
- "@quasar/extras": "^1.13.5",
56
- "@vitejs/plugin-vue": "^2.3.1",
57
- "@vue/compiler-sfc": "^3.2.33",
58
- "@vue/server-renderer": "^3.2.33",
59
- "builtin-modules": "^3.2.0",
55
+ "@fastify/middie": "^8.0.0",
56
+ "@fastify/static": "^6.4.0",
57
+ "@quasar/extras": "^1.14.0",
58
+ "@vitejs/plugin-vue": "^3.0.0-alpha.1",
59
+ "builtin-modules": "^3.3.0",
60
60
  "cac": "^6.7.12",
61
61
  "chalk": "^5.0.1",
62
62
  "cross-env": "^7.0.3",
63
- "fastify": "^3.28.0",
64
- "fastify-static": "^4.6.1",
65
- "glob": "^8.0.1",
66
- "happy-dom": "^2.55.0",
67
- "import-meta-resolve": "^1.1.1",
63
+ "esbuild": "^0.14.43",
64
+ "fastify": "^4.0.0",
65
+ "glob": "^8.0.3",
66
+ "happy-dom": "^5.2.0",
68
67
  "local-pkg": "^0.4.1",
69
- "magic-string": "^0.26.1",
68
+ "magic-string": "^0.26.2",
70
69
  "merge-deep": "^3.0.3",
71
- "middie": "^6.0.0",
72
70
  "readline": "^1.3.0",
73
- "sass": "1.50.0",
74
- "unplugin-vue-components": "^0.19.3",
75
- "vite": "^2.9.5",
76
- "vitest": "^0.9.3"
71
+ "sass": "1.52.3",
72
+ "ts-node": "^10.8.1",
73
+ "unplugin-vue-components": "^0.19.6",
74
+ "vite": "^3.0.0-alpha.11",
75
+ "vitest": "^0.14.1"
77
76
  },
78
77
  "devDependencies": {
78
+ "@types/connect": "^3.4.35",
79
79
  "@types/glob": "^7.2.0",
80
80
  "@types/merge-deep": "^3.0.0",
81
- "@types/node": "^17.0.24",
81
+ "@types/node": "^17.0.41",
82
82
  "@types/ws": "^8.5.3",
83
- "@vue/runtime-core": "^3.2.33",
84
- "quasar": "^2.6.6",
85
- "rollup": "^2.70.1",
86
- "typescript": "^4.6.3",
87
- "vite": "^2.9.5",
88
- "vue": "^3.2.33",
89
- "vue-router": "^4.0.14"
83
+ "@vue/runtime-core": "^3.2.37",
84
+ "import-meta-resolve": "^2.0.3",
85
+ "quasar": "^2.7.1",
86
+ "rollup": "^2.75.6",
87
+ "typescript": "^4.7.3",
88
+ "vite": "^3.0.0-alpha.11",
89
+ "vue": "^3.2.37",
90
+ "vue-router": "^4.0.15"
90
91
  },
91
92
  "peerDependencies": {
92
- "fastify": "^3.28.0",
93
+ "@fastify/static": "^6.4.0",
94
+ "fastify": "^4.0.0",
93
95
  "fastify-plugin": "^3.0.1",
94
- "fastify-sensible": "^3.1.2",
95
- "fastify-static": "^4.6.1",
96
- "quasar": "^2.6.6",
97
- "vue": "^3.2.33",
98
- "vue-router": "^4.0.14"
96
+ "quasar": "^2.7.1",
97
+ "vue": "^3.2.37",
98
+ "vue-router": "^4.0.15",
99
+ "import-meta-resolve": "^2.0.3"
99
100
  },
100
101
  "publishConfig": {
101
102
  "access": "public",
@@ -14,11 +14,10 @@ export const getCliDir = () => getPkgJsonDir(new URL('./', import.meta.url))
14
14
  export const getCliViteDir = (cliDir: URL) => new URL('src/vite/', cliDir)
15
15
  export const getSrcDir = (appDir: URL) => new URL('src/', appDir)
16
16
  export const getCwd = () => new URL(`file://${process.cwd()}/`)
17
- // export const quasarDir = getPkgJsonDir(new URL('./', await resolve('quasar', appDir.href)))
18
17
 
19
18
  export const parsePath = (path: string, basePath: URL) => {
20
19
  if (path) {
21
- if (path.slice(-1) !== '/') path += '/'
20
+ if (!path.includes('.') && path.slice(-1) !== '/') path += '/'
22
21
  if (path.startsWith('.')) {
23
22
  return new URL(path, basePath)
24
23
  } else if (path) {