vitrify 0.9.0 → 0.10.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 CHANGED
@@ -1,9 +1,10 @@
1
1
  # Vitrify
2
2
 
3
- > Pre-configured Vite CLI for your framework
3
+ > Vite as your Full Stack development tool
4
4
 
5
5
  - Use a simple configuration file to configure and integrate required Vite plugins into your project.
6
- - Client-Side Rendering (CSR), Server-Side Rendering (SSR) and Fastify server build and development modes.
6
+ - Client-Side Rendering (CSR), Server-Side Rendering (SSR), Static Site Generation (SSG) and Fastify server build and development modes.
7
+ - Run both your frontend- and backend code through Vite at development and build time.
7
8
 
8
9
  ## Features
9
10
 
@@ -73,14 +74,24 @@ Options:
73
74
  node/bin/cli.ts-->node/bin/dev.ts;
74
75
  node/bin/cli.ts-->node/bin/test.ts;
75
76
  node/bin/cli.ts-->node/bin/run.ts;
76
- node/bin/build.ts-->node/index.ts{Load baseConfig};
77
- node/bin/dev.ts-->node/index.ts{Load baseConfig};
78
- node/index.ts-->vitrify.config.js{Load vitrify.config.js};
77
+ node/bin/build.ts-->node/index.ts
78
+ node/bin/dev.ts-->node/index.ts
79
+ node/index.ts{Load baseConfig}-->vitrify.config.js{Load vitrify.config.js};
80
+ subgraph baseconfig
79
81
  vitrify.config.js-->node/plugins{Load plugins};
80
- node/plugins-->framework{Load framework entrypoints from vite/...};
81
- framework-->merge{Merge vitrify.config.js with Vitrify configuration};
82
- merge-->build{Build the application};
83
- merge-->dev{Spin up dev server};
82
+ node/plugins-->merge{Merge vitrify.config.js with Vitrify configuration};
83
+ end
84
+ merge-- mode: fastify -->frameworkFastify{Load framework entrypoints from fastify/...};
85
+ merge-- mode: csr/ssr/ssg -->framework{Load framework entrypoints from vite/...};
86
+ frameworkFastify-->fastifyBuild{Build the application};
87
+ frameworkFastify-->fastifyDev{Start Fastify dev server};
88
+ fastifySetup{onSetup / onRendered}-->fastifyDev
89
+ fastifySetup{onSetup / onRendered}-->fastifyBuild
90
+ framework-->build{Build the application};
91
+ build-- mode: ssg -->prerender{Run prerender.js}
92
+ framework-->dev{Start Vite dev server};
93
+ frameworkSetup{onBoot / onMounted}-->dev
94
+ frameworkSetup{onBoot / onMounted}-->build
84
95
  node/bin/test.ts-->test{Run a pre-configured Vitest instance};
85
96
  node/bin/run.ts-->run{Inject context into script and run script};
86
97
  ```
package/dist/bin/cli.js CHANGED
@@ -1,7 +1,7 @@
1
1
  #!/usr/bin/env node
2
2
  import cac from 'cac';
3
3
  import { getAppDir, parsePath } from '../app-urls.js';
4
- import { printHttpServerUrls } from '../helpers/logger.js';
4
+ import { printHttpServerUrls, exitLogs } from '../helpers/logger.js';
5
5
  const cli = cac('vitrify');
6
6
  cli
7
7
  .command('build')
@@ -135,6 +135,9 @@ cli
135
135
  }
136
136
  console.log('Dev server running at:');
137
137
  printHttpServerUrls(server, config);
138
+ for (const line of exitLogs) {
139
+ config.logger.warn(line);
140
+ }
138
141
  });
139
142
  cli.command('test').action(async (options) => {
140
143
  const { test } = await import('./test.js');
package/dist/bin/dev.js CHANGED
@@ -3,6 +3,7 @@ import { baseConfig } from '../index.js';
3
3
  import fastify from 'fastify';
4
4
  import { fastifySsrPlugin } from '../frameworks/vue/fastify-ssr-plugin.js';
5
5
  import isPortReachable from 'is-port-reachable';
6
+ import { exitLogs } from '../helpers/logger.js';
6
7
  const getFirstOpenPort = async (portNumber) => {
7
8
  if (!(await isPortReachable(portNumber, { host: 'localhost' }))) {
8
9
  return portNumber;
@@ -32,11 +33,17 @@ ssr, framework = 'vue', host, appDir, publicDir, base }) {
32
33
  base
33
34
  });
34
35
  config.logLevel = logLevel;
36
+ config.define = {
37
+ ...config.define,
38
+ __HOST__: `'${host}'`
39
+ };
40
+ const wsPort = await getFirstOpenPort(24678);
41
+ exitLogs.push(`[warning] HTTPS mode enabled. Visit https://{hostname}:${wsPort} to enable a security exception for HMR.`);
35
42
  config.server = {
36
43
  https: config.server?.https,
37
44
  hmr: {
38
45
  protocol: config.server?.https ? 'wss' : 'ws',
39
- port: await getFirstOpenPort(24678)
46
+ port: wsPort
40
47
  },
41
48
  port,
42
49
  // middlewareMode: mode === 'ssr' ? 'ssr' : undefined,
@@ -107,7 +114,8 @@ ssr, framework = 'vue', host, appDir, publicDir }) {
107
114
  await app.register(fastifySsrPlugin, {
108
115
  appDir,
109
116
  mode: 'development',
110
- onRendered
117
+ onRendered,
118
+ host
111
119
  });
112
120
  }
113
121
  await app.listen({
@@ -23,7 +23,8 @@ const fastifySsrPlugin = async (fastify, options, done) => {
23
23
  appDir: options.appDir,
24
24
  ssr: 'ssr',
25
25
  framework: 'vue',
26
- base: options.baseUrl
26
+ base: options.baseUrl,
27
+ host: options.host
27
28
  });
28
29
  // const { createServer, searchForWorkspaceRoot } = await import('vite')
29
30
  // const { baseConfig } = await import('vitrify')
@@ -91,11 +92,17 @@ const fastifySsrPlugin = async (fastify, options, done) => {
91
92
  mods: matchedModules
92
93
  });
93
94
  const [appHtml, preloadLinks] = await render(url, manifest, ssrContext);
95
+ if (!ssrContext.initialState)
96
+ ssrContext.initialState = {};
97
+ ssrContext.initialState.provide = provide;
94
98
  let html = template
95
99
  .replace(`<!--preload-links-->`, preloadLinks)
96
100
  .replace(`<!--app-html-->`, appHtml)
97
101
  .replace('<!--product-name-->', options.productName || 'Product name')
98
- .replace('<!--dev-ssr-css-->', css);
102
+ .replace('<!--dev-ssr-css-->', css)
103
+ .replace('<!--initial-state-->', `<script>
104
+ __INITIAL_STATE__ = '${JSON.stringify(ssrContext.initialState)}'
105
+ </script>`);
99
106
  if (options.onRendered?.length) {
100
107
  for (const ssrFunction of options.onRendered) {
101
108
  html = ssrFunction(html, ssrContext);
@@ -139,7 +146,10 @@ const fastifySsrPlugin = async (fastify, options, done) => {
139
146
  ssrContext.initialState.provide = provide;
140
147
  let html = template
141
148
  .replace(`<!--preload-links-->`, preloadLinks)
142
- .replace(`<!--app-html-->`, appHtml);
149
+ .replace(`<!--app-html-->`, appHtml)
150
+ .replace('<!--initial-state-->', `<script>
151
+ __INITIAL_STATE__ = '${JSON.stringify(ssrContext.initialState)}'
152
+ </script>`);
143
153
  if (options.onRendered?.length) {
144
154
  for (const ssrFunction of options.onRendered) {
145
155
  html = ssrFunction(html, ssrContext);
@@ -2,6 +2,7 @@
2
2
  import chalk from 'chalk';
3
3
  import os from 'os';
4
4
  import { resolveHostname } from '../helpers/utils.js';
5
+ export const exitLogs = [];
5
6
  export function printHttpServerUrls(server, config) {
6
7
  const address = server.address();
7
8
  const isAddressInfo = (x) => x?.address;
package/dist/index.js CHANGED
@@ -141,6 +141,8 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
141
141
  }
142
142
  catch (e) {
143
143
  console.log('No vitrify.config.(ts|js) file found, using defaults');
144
+ if (process.env.DEBUG)
145
+ console.error(e);
144
146
  vitrifyConfig = {};
145
147
  }
146
148
  const localPackages = ['vue', 'vue-router', '@vue/server-renderer'];
@@ -338,6 +340,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
338
340
  }
339
341
  }
340
342
  });
343
+ // @ts-ignore
341
344
  if (debug)
342
345
  plugins.push(visualizer());
343
346
  }
@@ -460,6 +463,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
460
463
  noExternal
461
464
  },
462
465
  define: {
466
+ __HOST__: 'localhost',
463
467
  __BASE_URL__: `'${base}'`
464
468
  }
465
469
  };
@@ -38,7 +38,6 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
38
38
  name: 'vite-plugin-quasar-transform',
39
39
  enforce: 'pre',
40
40
  transform: (code, id, options) => {
41
- const { ssr } = options || {};
42
41
  code = code
43
42
  .replaceAll('__QUASAR_SSR__', ssr ? 'true' : 'false')
44
43
  .replaceAll('__QUASAR_SSR_SERVER__', ssr ? '(import.meta.env.SSR === true)' : 'false')
@@ -49,5 +49,5 @@ export declare function createServer({ port, logLevel, ssr, framework, host, app
49
49
  worker: import("vite").ResolveWorkerOptions;
50
50
  appType: import("vite").AppType;
51
51
  experimental: import("vite").ExperimentalOptions;
52
- }>;
52
+ } & import("vite").PluginHookUtils>;
53
53
  }>;
@@ -3,7 +3,9 @@ import type { ViteDevServer } from 'vite';
3
3
  import type { OnRenderedHook } from 'src/node/vitrify-config.js';
4
4
  export interface FastifySsrOptions {
5
5
  baseUrl?: string;
6
- provide?: (req: FastifyRequest, res: FastifyReply) => Promise<Record<string, unknown>>;
6
+ provide?: (req: FastifyRequest, res: FastifyReply) => Promise<Record<string, unknown | {
7
+ value: unknown;
8
+ }>>;
7
9
  vitrifyDir?: URL;
8
10
  vite?: ViteDevServer;
9
11
  onRendered?: OnRenderedHook[];
@@ -11,6 +13,7 @@ export interface FastifySsrOptions {
11
13
  publicDir?: URL;
12
14
  productName?: string;
13
15
  mode?: string;
16
+ host?: string;
14
17
  }
15
18
  declare const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions>;
16
19
  export { fastifySsrPlugin };
@@ -11,4 +11,4 @@ export declare const createApp: ({ onSetup, appDir, baseUrl, fastifyPlugin, onRe
11
11
  onRendered: OnRenderedHook[];
12
12
  vitrifyDir?: URL | undefined;
13
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>>;
14
+ }) => FastifyInstance<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, any, import("fastify").FastifyTypeProviderDefault> & PromiseLike<FastifyInstance<import("http").Server<typeof import("http").IncomingMessage, typeof import("http").ServerResponse>, import("http").IncomingMessage, import("http").ServerResponse<import("http").IncomingMessage>, any, import("fastify").FastifyTypeProviderDefault>>;
@@ -1,4 +1,5 @@
1
1
  /// <reference types="node" />
2
2
  import type { Server } from 'net';
3
3
  import type { ResolvedConfig } from 'vite';
4
+ export declare const exitLogs: string[];
4
5
  export declare function printHttpServerUrls(server: Server, config: ResolvedConfig): void;
@@ -1,8 +1,8 @@
1
1
  import type { VitrifyPlugin } from './index.js';
2
2
  export interface QuasarConf {
3
- ctx: Record<string, any>;
4
- css: string[];
5
- boot: string[];
3
+ ctx?: Record<string, any>;
4
+ css?: string[];
5
+ boot?: string[];
6
6
  framework: {
7
7
  components?: string[];
8
8
  directives?: string[];
@@ -10,8 +10,7 @@ export interface QuasarConf {
10
10
  lang?: string;
11
11
  iconSet?: string;
12
12
  };
13
- animations: string[];
14
- extras: string[];
13
+ extras?: string[];
15
14
  }
16
15
  export declare const injectSsrContext: (html: string, ssrContext: Record<string, any>) => string;
17
16
  export declare const QuasarPlugin: VitrifyPlugin;
package/package.json CHANGED
@@ -1,9 +1,9 @@
1
1
  {
2
2
  "name": "vitrify",
3
- "version": "0.9.0",
3
+ "version": "0.10.0",
4
4
  "license": "MIT",
5
5
  "author": "Stefan van Herwijnen",
6
- "description": "Pre-configured Vite CLI for your framework",
6
+ "description": "Vite as your Full Stack development tool",
7
7
  "type": "module",
8
8
  "bin": {
9
9
  "vitrify": "./dist/bin/cli.js"
@@ -58,48 +58,48 @@
58
58
  "dependencies": {
59
59
  "@fastify/middie": "^8.0.0",
60
60
  "@fastify/static": "^6.5.0",
61
- "@quasar/extras": "^1.15.1",
62
- "@vitejs/plugin-vue": "^3.0.1",
61
+ "@quasar/extras": "^1.15.2",
62
+ "@vitejs/plugin-vue": "^3.1.0",
63
63
  "@vitrify/plugin-env": "^0.1.0",
64
64
  "builtin-modules": "^3.3.0",
65
- "cac": "^6.7.12",
65
+ "cac": "^6.7.14",
66
66
  "chalk": "^5.0.1",
67
67
  "critters": "^0.0.16",
68
68
  "cross-env": "^7.0.3",
69
- "esbuild": "^0.14.53",
70
- "fastify": "^4.3.0",
69
+ "esbuild": "^0.15.7",
70
+ "fastify": "^4.5.3",
71
71
  "glob": "^8.0.3",
72
72
  "happy-dom": "^6.0.4",
73
73
  "is-port-reachable": "^4.0.0",
74
- "magic-string": "^0.26.2",
74
+ "magic-string": "^0.26.3",
75
75
  "merge-deep": "^3.0.3",
76
76
  "readline": "^1.3.0",
77
- "rollup-plugin-visualizer": "^5.7.1",
78
- "sass": "1.54.2",
77
+ "rollup-plugin-visualizer": "^5.8.1",
78
+ "sass": "1.54.8",
79
79
  "ts-node": "^10.9.1",
80
- "unplugin-vue-components": "^0.22.0",
81
- "vite": "^3.0.4",
82
- "vitest": "^0.20.3"
80
+ "unplugin-vue-components": "^0.22.4",
81
+ "vite": "^3.1.0",
82
+ "vitest": "^0.23.1"
83
83
  },
84
84
  "devDependencies": {
85
85
  "@types/connect": "^3.4.35",
86
- "@types/glob": "^7.2.0",
86
+ "@types/glob": "^8.0.0",
87
87
  "@types/merge-deep": "^3.0.0",
88
- "@types/node": "^18.6.3",
88
+ "@types/node": "^18.7.15",
89
89
  "@types/ws": "^8.5.3",
90
- "@vue/runtime-core": "^3.2.37",
90
+ "@vue/runtime-core": "^3.2.38",
91
91
  "quasar": "^2.7.7",
92
- "rollup": "^2.77.2",
93
- "typescript": "^4.7.4",
94
- "vue": "^3.2.37",
95
- "vue-router": "^4.1.3"
92
+ "rollup": "^2.79.0",
93
+ "typescript": "^4.8.2",
94
+ "vue": "^3.2.38",
95
+ "vue-router": "^4.1.5"
96
96
  },
97
97
  "peerDependencies": {
98
98
  "@fastify/static": "^6.5.0",
99
- "fastify": "^4.3.0",
99
+ "fastify": "^4.5.3",
100
100
  "quasar": "^2.7.7",
101
- "vue": "^3.2.37",
102
- "vue-router": "^4.1.3"
101
+ "vue": "^3.2.38",
102
+ "vue-router": "^4.1.5"
103
103
  },
104
104
  "publishConfig": {
105
105
  "access": "public",
@@ -110,5 +110,10 @@
110
110
  "src",
111
111
  "!dist/**/*.test.js",
112
112
  "!dist/**/test.js"
113
+ ],
114
+ "keywords": [
115
+ "vite",
116
+ "full stack",
117
+ "fastify"
113
118
  ]
114
119
  }
@@ -1,14 +1,8 @@
1
1
  #!/usr/bin/env node
2
2
  import cac from 'cac'
3
3
  import { getAppDir, parsePath } from '../app-urls.js'
4
- import { printHttpServerUrls } from '../helpers/logger.js'
5
- import type {
6
- ConfigEnv,
7
- ResolvedConfig,
8
- UserConfig,
9
- UserConfigExport,
10
- ViteDevServer
11
- } from 'vite'
4
+ import { printHttpServerUrls, exitLogs } from '../helpers/logger.js'
5
+ import type { ResolvedConfig } from 'vite'
12
6
  import type { Server } from 'net'
13
7
 
14
8
  const cli = cac('vitrify')
@@ -157,6 +151,9 @@ cli
157
151
  }
158
152
  console.log('Dev server running at:')
159
153
  printHttpServerUrls(server, config)
154
+ for (const line of exitLogs) {
155
+ config.logger.warn(line)
156
+ }
160
157
  })
161
158
 
162
159
  cli.command('test').action(async (options) => {
@@ -7,6 +7,7 @@ import type { FastifyServerOptions } from 'fastify'
7
7
  import { fastifySsrPlugin } from '../frameworks/vue/fastify-ssr-plugin.js'
8
8
  import type { OnRenderedHook, VitrifyConfig } from '../vitrify-config.js'
9
9
  import isPortReachable from 'is-port-reachable'
10
+ import { exitLogs } from '../helpers/logger.js'
10
11
 
11
12
  const getFirstOpenPort = async (portNumber: number): Promise<number> => {
12
13
  if (!(await isPortReachable(portNumber, { host: 'localhost' }))) {
@@ -59,11 +60,21 @@ export async function createVitrifyDevServer({
59
60
 
60
61
  config.logLevel = logLevel
61
62
 
63
+ config.define = {
64
+ ...config.define,
65
+ __HOST__: `'${host}'`
66
+ }
67
+
68
+ const wsPort = await getFirstOpenPort(24678)
69
+ exitLogs.push(
70
+ `[warning] HTTPS mode enabled. Visit https://{hostname}:${wsPort} to enable a security exception for HMR.`
71
+ )
72
+
62
73
  config.server = {
63
74
  https: config.server?.https,
64
75
  hmr: {
65
76
  protocol: config.server?.https ? 'wss' : 'ws',
66
- port: await getFirstOpenPort(24678)
77
+ port: wsPort
67
78
  },
68
79
  port,
69
80
  // middlewareMode: mode === 'ssr' ? 'ssr' : undefined,
@@ -161,7 +172,8 @@ export async function createServer({
161
172
  await app.register(fastifySsrPlugin, {
162
173
  appDir,
163
174
  mode: 'development',
164
- onRendered
175
+ onRendered,
176
+ host
165
177
  })
166
178
  }
167
179
  await app.listen({
@@ -8,6 +8,7 @@ export async function test(opts: { appDir: URL }) {
8
8
  })
9
9
 
10
10
  await startVitest(
11
+ 'test',
11
12
  [],
12
13
  {
13
14
  root: opts.appDir.pathname,
@@ -8,13 +8,12 @@ import { readFileSync } from 'fs'
8
8
  import { componentsModules, collectCss } from '../../helpers/collect-css-ssr.js'
9
9
  import type { ViteDevServer } from 'vite'
10
10
  import type { OnRenderedHook } from 'src/node/vitrify-config.js'
11
-
12
11
  export interface FastifySsrOptions {
13
12
  baseUrl?: string
14
13
  provide?: (
15
14
  req: FastifyRequest,
16
15
  res: FastifyReply
17
- ) => Promise<Record<string, unknown>>
16
+ ) => Promise<Record<string, unknown | { value: unknown }>>
18
17
  vitrifyDir?: URL
19
18
  vite?: ViteDevServer
20
19
  // frameworkDir?: URL
@@ -23,6 +22,7 @@ export interface FastifySsrOptions {
23
22
  publicDir?: URL
24
23
  productName?: string
25
24
  mode?: string
25
+ host?: string
26
26
  }
27
27
 
28
28
  const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
@@ -55,7 +55,8 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
55
55
  appDir: options.appDir,
56
56
  ssr: 'ssr',
57
57
  framework: 'vue',
58
- base: options.baseUrl
58
+ base: options.baseUrl,
59
+ host: options.host
59
60
  })
60
61
  // const { createServer, searchForWorkspaceRoot } = await import('vite')
61
62
  // const { baseConfig } = await import('vitrify')
@@ -101,7 +102,7 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
101
102
  const url = req.raw.url?.replace(options.baseUrl!, '/')
102
103
  const provide = options.provide ? await options.provide(req, res) : {}
103
104
 
104
- const ssrContext = {
105
+ const ssrContext: Record<string, any> = {
105
106
  req,
106
107
  res,
107
108
  provide
@@ -133,11 +134,21 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
133
134
  })
134
135
 
135
136
  const [appHtml, preloadLinks] = await render(url, manifest, ssrContext)
137
+
138
+ if (!ssrContext.initialState) ssrContext.initialState = {}
139
+ ssrContext.initialState.provide = provide
140
+
136
141
  let html = template
137
142
  .replace(`<!--preload-links-->`, preloadLinks)
138
143
  .replace(`<!--app-html-->`, appHtml)
139
144
  .replace('<!--product-name-->', options.productName || 'Product name')
140
145
  .replace('<!--dev-ssr-css-->', css)
146
+ .replace(
147
+ '<!--initial-state-->',
148
+ `<script>
149
+ __INITIAL_STATE__ = '${JSON.stringify(ssrContext.initialState)}'
150
+ </script>`
151
+ )
141
152
 
142
153
  if (options.onRendered?.length) {
143
154
  for (const ssrFunction of options.onRendered) {
@@ -196,6 +207,12 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
196
207
  let html = template
197
208
  .replace(`<!--preload-links-->`, preloadLinks)
198
209
  .replace(`<!--app-html-->`, appHtml)
210
+ .replace(
211
+ '<!--initial-state-->',
212
+ `<script>
213
+ __INITIAL_STATE__ = '${JSON.stringify(ssrContext.initialState)}'
214
+ </script>`
215
+ )
199
216
 
200
217
  if (options.onRendered?.length) {
201
218
  for (const ssrFunction of options.onRendered) {
@@ -6,6 +6,8 @@ import os from 'os'
6
6
  import type { Hostname } from '../helpers/utils.js'
7
7
  import { resolveHostname } from '../helpers/utils.js'
8
8
 
9
+ export const exitLogs: string[] = []
10
+
9
11
  export function printHttpServerUrls(
10
12
  server: Server,
11
13
  config: ResolvedConfig
package/src/node/index.ts CHANGED
@@ -205,6 +205,7 @@ export const baseConfig = async ({
205
205
  vitrifyConfig = await vitrifyConfig({ mode, command })
206
206
  } catch (e) {
207
207
  console.log('No vitrify.config.(ts|js) file found, using defaults')
208
+ if (process.env.DEBUG) console.error(e)
208
209
  vitrifyConfig = {}
209
210
  }
210
211
 
@@ -409,6 +410,7 @@ export const baseConfig = async ({
409
410
  }
410
411
  })
411
412
 
413
+ // @ts-ignore
412
414
  if (debug) plugins.push(visualizer())
413
415
  }
414
416
 
@@ -539,6 +541,7 @@ export const baseConfig = async ({
539
541
  noExternal
540
542
  },
541
543
  define: {
544
+ __HOST__: 'localhost',
542
545
  __BASE_URL__: `'${base}'`
543
546
  }
544
547
  } as VitrifyConfig
@@ -9,9 +9,9 @@ import type {
9
9
  import { QuasarResolver } from 'unplugin-vue-components/resolvers'
10
10
  import type { VitrifyPlugin } from './index.js'
11
11
  export interface QuasarConf {
12
- ctx: Record<string, any>
13
- css: string[]
14
- boot: string[]
12
+ ctx?: Record<string, any>
13
+ css?: string[]
14
+ boot?: string[]
15
15
  framework: {
16
16
  components?: string[]
17
17
  directives?: string[]
@@ -19,8 +19,8 @@ export interface QuasarConf {
19
19
  lang?: string
20
20
  iconSet?: string
21
21
  }
22
- animations: string[]
23
- extras: string[]
22
+ // animations: string[]
23
+ extras?: string[]
24
24
  }
25
25
 
26
26
  export const injectSsrContext = (
@@ -85,7 +85,6 @@ export const QuasarPlugin: VitrifyPlugin = async ({
85
85
  name: 'vite-plugin-quasar-transform',
86
86
  enforce: 'pre',
87
87
  transform: (code, id, options) => {
88
- const { ssr } = options || {}
89
88
  code = code
90
89
  .replaceAll('__QUASAR_SSR__', ssr ? 'true' : 'false')
91
90
  .replaceAll(
@@ -2,7 +2,7 @@ import { createApp } from '../../../node/frameworks/vue/server.js'
2
2
  import { getAppDir } from '../../../node/app-urls.js'
3
3
  // import { setup } from 'virtual:fastify-setup'
4
4
  import { onSetup } from 'virtual:vitrify-hooks'
5
- import { fastifyCsrPlugin } from './fastify-csr-plugin.js'
5
+ import { fastifyCsrPlugin } from './fastify-csr-plugin'
6
6
  import type { ViteDevServer } from 'vite'
7
7
 
8
8
  // const appDir = getPkgJsonDir(import.meta.url)
@@ -1,3 +1,3 @@
1
- import { fastifyCsrPlugin } from '../../../node/frameworks/vue/fastify-csr-plugin.js'
1
+ import { fastifyCsrPlugin } from '../../../node/frameworks/vue/fastify-csr-plugin'
2
2
 
3
3
  export { fastifyCsrPlugin }
@@ -1,4 +1,4 @@
1
- import { setupApp } from './app.js'
1
+ import { setupApp } from './app'
2
2
 
3
3
  const app = await setupApp()
4
4
 
@@ -7,7 +7,8 @@ import {
7
7
  createApp as createVueApp,
8
8
  h,
9
9
  onMounted as onMountedVue,
10
- getCurrentInstance
10
+ getCurrentInstance,
11
+ ref
11
12
  } from 'vue'
12
13
  import { onBoot, onMounted } from 'virtual:vitrify-hooks'
13
14
  import routes from 'src/router/routes'
@@ -19,6 +20,10 @@ interface ssrContext {
19
20
  [key: string]: unknown
20
21
  }
21
22
 
23
+ function capitalizeFirstLetter(string) {
24
+ return string.charAt(0).toUpperCase() + string.slice(1)
25
+ }
26
+
22
27
  export async function createApp(
23
28
  ssr?: 'client' | 'server',
24
29
  ssrContext?: ssrContext
@@ -55,17 +60,31 @@ export async function createApp(
55
60
  next()
56
61
  })
57
62
 
58
- let provide: Record<string, unknown> = {}
63
+ let initialState: Record<string, any>
64
+ let provide: Record<string, any> = {}
59
65
  if (import.meta.env.SSR) {
60
66
  if (ssrContext?.provide) {
61
67
  provide = ssrContext?.provide
62
68
  }
63
69
  } else {
64
70
  // @ts-ignore
65
- provide = window.__INITIAL_STATE__?.provide
71
+ if (window.__INITIAL_STATE__) {
72
+ // @ts-ignore
73
+ initialState = JSON.parse(window.__INITIAL_STATE__)
74
+ provide = initialState.provide
75
+ }
66
76
  }
67
77
  for (let key in provide) {
68
- app.provide(key, provide[key])
78
+ if (provide[key].value) {
79
+ const refValue = ref(provide[key].value)
80
+ app.provide(key, refValue)
81
+ app.provide(
82
+ `update${capitalizeFirstLetter(key)}`,
83
+ (val: any) => (refValue.value = val)
84
+ )
85
+ } else {
86
+ app.provide(key, provide[key])
87
+ }
69
88
  }
70
89
 
71
90
  for (let fn of onBoot) {
@@ -1,4 +1,4 @@
1
- import { createApp } from '../main.js'
1
+ import { createApp } from '../main'
2
2
 
3
3
  // const { app, router } = createApp()
4
4
  createApp('client').then(({ app, router }) => {
@@ -1,4 +1,4 @@
1
- import { createApp } from '../main.js'
1
+ import { createApp } from '../main'
2
2
  // import { renderToString } from 'vue/server-renderer'
3
3
 
4
4
  // import { onRendered } from 'virtual:vitrify-hooks'
@@ -1,4 +1,4 @@
1
- import { setupApp } from './app.js'
1
+ import { setupApp } from './app'
2
2
 
3
3
  const app = await setupApp()
4
4