vitrify 0.6.10 → 0.6.13

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.
@@ -131,7 +131,7 @@ const fastifySsrPlugin = async (fastify, options, done) => {
131
131
  if (!ssrContext.initialState)
132
132
  ssrContext.initialState = {};
133
133
  ssrContext.initialState.provide = provide;
134
- let html = template
134
+ const html = template
135
135
  .replace(`<!--preload-links-->`, preloadLinks)
136
136
  .replace(`<!--app-html-->`, appHtml);
137
137
  res.code(200);
package/dist/index.js CHANGED
@@ -1,4 +1,5 @@
1
1
  import vuePlugin from '@vitejs/plugin-vue';
2
+ import { resolvePackageData } from 'vite';
2
3
  import { mergeConfig } from 'vite';
3
4
  import { build } from 'esbuild';
4
5
  import fs from 'fs';
@@ -8,7 +9,7 @@ import { readFileSync } from 'fs';
8
9
  import builtinModules from 'builtin-modules';
9
10
  // import { resolve } from 'import-meta-resolve'
10
11
  import { visualizer } from 'rollup-plugin-visualizer';
11
- import { getPkgJsonDir, resolve } from './app-urls.js';
12
+ import { resolve } from './app-urls.js';
12
13
  const internalServerModules = [
13
14
  'util',
14
15
  'vitrify',
@@ -31,23 +32,23 @@ const manualChunkNames = [
31
32
  'server'
32
33
  ];
33
34
  const moduleChunks = {
34
- vue: ['vue', '@vue', 'vue-router'],
35
- quasar: ['quasar']
35
+ vue: ['vue', 'vue-router'],
36
+ quasar: ['quasar', '@quasar']
36
37
  };
37
- const manualChunks = (id, api) => {
38
- if (id.includes('vitrify/src/')) {
38
+ const manualChunks = (id) => {
39
+ const matchedModule = Object.entries(moduleChunks).find(([chunkName, moduleNames]) => moduleNames.some((moduleName) => id.includes(moduleName + '/')));
40
+ if (id.includes('vitrify/src/vite/')) {
39
41
  const name = id.split('/').at(-1)?.split('.').at(0);
40
42
  if (name && manualChunkNames.includes(name))
41
43
  return name;
42
- return 'vitrify';
44
+ }
45
+ else if (matchedModule) {
46
+ return matchedModule[0];
43
47
  }
44
48
  else if (VIRTUAL_MODULES.some((virtualModule) => id.includes(virtualModule))) {
45
49
  return VIRTUAL_MODULES.find((name) => id.includes(name));
46
50
  }
47
51
  else if (id.includes('node_modules')) {
48
- const name = Object.entries(moduleChunks).find(([chunkName, moduleNames]) => moduleNames.some((name) => id.includes(`${name}/`)));
49
- if (name)
50
- return name[0];
51
52
  return 'vendor';
52
53
  }
53
54
  };
@@ -141,13 +142,16 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
141
142
  console.log('No vitrify.config.(ts|js) file found, using defaults');
142
143
  vitrifyConfig = {};
143
144
  }
144
- // const localPackages = ['vue', 'vue-router', '@vue/server-renderer']
145
- const localPackages = [];
145
+ const localPackages = ['vue', 'vue-router', '@vue/server-renderer'];
146
+ // const localPackages: string[] = []
146
147
  const cliPackages = [];
147
148
  const packageUrls = vitrifyConfig.vitrify?.urls?.packages || {};
148
149
  await (async () => {
149
- for (const val of localPackages)
150
- packageUrls[val] = getPkgJsonDir(new URL(resolve(val, appDir)));
150
+ for (const val of localPackages) {
151
+ const pkg = resolvePackageData(val, appDir.pathname);
152
+ if (pkg)
153
+ packageUrls[val] = new URL(`file://${pkg.dir}/`);
154
+ }
151
155
  })();
152
156
  // await (async () => {
153
157
  // for (const val of cliPackages)
@@ -377,15 +381,19 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
377
381
  ...Object.entries(packageUrls).map(([key, value]) => ({
378
382
  find: key,
379
383
  replacement: value.pathname
380
- })),
381
- {
382
- find: new RegExp('^vue$'),
383
- replacement: 'vue/dist/vue.runtime.esm-bundler.js'
384
- },
385
- {
386
- find: new RegExp('^vue-router$'),
387
- replacement: 'vue-router/dist/vue-router.esm-bundler.js'
388
- }
384
+ }))
385
+ // {
386
+ // find: new RegExp('^vue$'),
387
+ // replacement: 'vue/dist/vue.runtime.esm-bundler.js'
388
+ // },
389
+ // {
390
+ // find: new RegExp('^vue/server-renderer$'),
391
+ // replacement: 'vue/server-renderer/index.mjs'
392
+ // },
393
+ // {
394
+ // find: new RegExp('^vue-router$'),
395
+ // replacement: 'vue-router/dist/vue-router.esm-bundler.js'
396
+ // }
389
397
  // { find: 'vue', replacement: packageUrls['vue'].pathname },
390
398
  // { find: 'vue-router', replacement: packageUrls['vue-router'].pathname },
391
399
  // { find: 'vitrify', replacement: cliDir.pathname }
@@ -494,16 +502,10 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
494
502
  },
495
503
  plugins,
496
504
  optimizeDeps: {
497
- exclude: [
498
- 'vue',
499
- 'vue-router',
500
- 'vue/server-renderer',
501
- ...serverModules,
502
- ...builtinModules
503
- ]
505
+ exclude: ['vue', 'vue-router', ...serverModules, ...builtinModules]
504
506
  },
505
507
  resolve: {
506
- dedupe: ['vue', '@vue/server-renderer', 'vue-router'],
508
+ dedupe: ['vue', 'vue-router'],
507
509
  alias
508
510
  },
509
511
  build: {
@@ -1,8 +1,8 @@
1
+ import { resolvePackageData } from 'vite';
1
2
  import Components from 'unplugin-vue-components/vite';
2
3
  // import { quasarDir as defaultQuasarDir } from '../app-urls.js'
3
4
  // import { QuasarResolver } from '../resolver.js';
4
5
  import { QuasarResolver } from 'unplugin-vue-components/resolvers';
5
- import { getPkgJsonDir, resolve } from '../app-urls.js';
6
6
  export const injectSsrContext = (html, ssrContext) => html
7
7
  .replace(/(<html[^>]*)(>)/i, (found, start, end) => {
8
8
  let matches;
@@ -54,11 +54,14 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
54
54
  config: async (config, env) => {
55
55
  const { vitrify: { urls } = {}, quasar } = config;
56
56
  const globalCss = quasar?.extras.map((extra) => `@quasar/extras/${extra}/${extra}.css`);
57
- // const localPackages = ['@quasar/extras', 'quasar']
58
- const localPackages = [];
57
+ const localPackages = ['@quasar/extras', 'quasar'];
58
+ // const localPackages: string[] = []
59
59
  await (async () => {
60
- for (const val of localPackages)
61
- urls.packages[val] = getPkgJsonDir(new URL(await resolve(val, urls.app)));
60
+ for (const val of localPackages) {
61
+ const pkg = resolvePackageData(val, config.vitrify.urls.app.pathname);
62
+ if (pkg)
63
+ urls.packages[val] = new URL(`file://${pkg.dir}/`);
64
+ }
62
65
  })();
63
66
  const onMountedHooks = [
64
67
  async (instance) => {
@@ -140,68 +143,65 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
140
143
  resolve: {
141
144
  // dedupe: ['quasar', '@quasar/extras'],
142
145
  alias: [
143
- // {
144
- // find: 'quasar/wrappers',
145
- // replacement: new URL('quasar-wrappers.ts', urls?.cli).pathname
146
- // },
147
- // {
148
- // find: 'quasar/vue-plugin',
149
- // replacement: new URL(
150
- // 'src/vue-plugin.js',
151
- // urls?.packages?.quasar
152
- // ).pathname
153
- // },
154
- // {
155
- // find: 'quasar/plugins',
156
- // replacement: new URL('src/plugins.js', urls?.packages?.quasar)
157
- // .pathname
158
- // },
159
- // {
160
- // find: 'quasar/components',
161
- // replacement: new URL(
162
- // 'src/components.js',
163
- // urls?.packages?.quasar
164
- // ).pathname
165
- // },
166
- // {
167
- // find: 'quasar/composables',
168
- // replacement: new URL(
169
- // 'src/composables.js',
170
- // urls?.packages?.quasar
171
- // ).pathname
172
- // },
173
- // {
174
- // find: 'quasar/directives',
175
- // replacement: new URL(
176
- // 'src/directives.js',
177
- // urls?.packages?.quasar
178
- // ).pathname
179
- // },
180
- // {
181
- // find: 'quasar/src/',
182
- // replacement: new URL(
183
- // 'node_modules/quasar/src/',
184
- // config.vitrify?.urls?.app
185
- // ).pathname
186
- // }
187
- // {
188
- // find: 'quasar',
189
- // replacement: new URL(
190
- // 'node_modules/quasar',
191
- // config.vitrify?.urls?.app
192
- // )
193
- // }
194
- // {
195
- // find: new RegExp('^quasar$'),
196
- // replacement: new URL('src/index.all.js', urls?.packages?.quasar)
197
- // .pathname
198
- // },
199
- // {
200
- // find: `@quasar/extras`,
201
- // replacement: new URL('.', urls?.packages?.['@quasar/extras'])
202
- // .pathname
203
- // }
204
- // { find: new RegExp('^quasar$'), replacement: 'virtual:quasar' }
146
+ // {
147
+ // find: 'quasar/wrappers',
148
+ // replacement: new URL('quasar-wrappers.ts', urls?.cli).pathname
149
+ // },
150
+ // {
151
+ // find: 'quasar/vue-plugin',
152
+ // replacement: new URL(
153
+ // 'src/vue-plugin.js',
154
+ // urls?.packages?.quasar
155
+ // ).pathname
156
+ // },
157
+ // {
158
+ // find: 'quasar/plugins',
159
+ // replacement: new URL('src/plugins.js', urls?.packages?.quasar)
160
+ // .pathname
161
+ // },
162
+ // {
163
+ // find: 'quasar/components',
164
+ // replacement: new URL(
165
+ // 'src/components.js',
166
+ // urls?.packages?.quasar
167
+ // ).pathname
168
+ // },
169
+ // {
170
+ // find: 'quasar/composables',
171
+ // replacement: new URL(
172
+ // 'src/composables.js',
173
+ // urls?.packages?.quasar
174
+ // ).pathname
175
+ // },
176
+ // {
177
+ // find: 'quasar/directives',
178
+ // replacement: new URL(
179
+ // 'src/directives.js',
180
+ // urls?.packages?.quasar
181
+ // ).pathname
182
+ // },
183
+ {
184
+ find: 'quasar/src',
185
+ replacement: new URL('./src', config.vitrify.urls.packages.quasar).pathname
186
+ }
187
+ // {
188
+ // find: 'quasar',
189
+ // replacement: new URL(
190
+ // 'node_modules/quasar',
191
+ // config.vitrify?.urls?.app
192
+ // )
193
+ // }
194
+ // {
195
+ // find: new RegExp('^quasar$'),
196
+ // replacement: new URL('src/index.all.js', urls?.packages?.quasar)
197
+ // .pathname
198
+ // },
199
+ // {
200
+ // find: `@quasar/extras`,
201
+ // replacement: new URL('.', urls?.packages?.['@quasar/extras'])
202
+ // .pathname
203
+ // }
204
+ // { find: new RegExp('^quasar$'), replacement: 'virtual:quasar' }
205
205
  ]
206
206
  },
207
207
  optimizeDeps: {
@@ -42,7 +42,7 @@ export declare function createServer({ port, logLevel, ssr, framework, host, app
42
42
  server: import("vite").ResolvedServerOptions;
43
43
  build: Required<import("vite").BuildOptions>;
44
44
  preview: import("vite").ResolvedPreviewOptions;
45
- ssr: import("vite").ResolvedSSROptions | undefined;
45
+ ssr: import("vite").ResolvedSSROptions;
46
46
  assetsInclude: (file: string) => boolean;
47
47
  logger: import("vite").Logger;
48
48
  createResolver: (options?: Partial<import("vite").InternalResolveOptions> | undefined) => import("vite").ResolveFn;
@@ -1,2 +1,2 @@
1
- import type { RouteRecord } from 'vue-router';
2
- export declare const routesToPaths: (routes?: RouteRecord[]) => string[];
1
+ import type { RouteRecordRaw } from 'vue-router';
2
+ export declare const routesToPaths: (routes?: RouteRecordRaw[]) => string[];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vitrify",
3
- "version": "0.6.10",
3
+ "version": "0.6.13",
4
4
  "license": "MIT",
5
5
  "author": "Stefan van Herwijnen",
6
6
  "description": "Pre-configured Vite CLI for your framework",
@@ -60,7 +60,6 @@
60
60
  "@fastify/static": "^6.4.0",
61
61
  "@quasar/extras": "^1.14.2",
62
62
  "@vitejs/plugin-vue": "^3.0.0-alpha.1",
63
- "@vue/server-renderer": "^3.2.37",
64
63
  "builtin-modules": "^3.3.0",
65
64
  "cac": "^6.7.12",
66
65
  "chalk": "^5.0.1",
@@ -183,7 +183,7 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
183
183
  if (!ssrContext.initialState) ssrContext.initialState = {}
184
184
  ssrContext.initialState.provide = provide
185
185
 
186
- let html = template
186
+ const html = template
187
187
  .replace(`<!--preload-links-->`, preloadLinks)
188
188
  .replace(`<!--app-html-->`, appHtml)
189
189
 
@@ -1,12 +1,12 @@
1
1
  // https://github.com/antfu/vite-ssg/blob/462722203dade87365a519d847fcd881ee16a7f4/src/node/utils.ts#L13
2
- import type { RouteRecord } from 'vue-router'
2
+ import type { RouteRecordRaw } from 'vue-router'
3
3
 
4
- export const routesToPaths = (routes?: RouteRecord[]) => {
4
+ export const routesToPaths = (routes?: RouteRecordRaw[]) => {
5
5
  if (!routes) return ['/']
6
6
 
7
7
  const paths: Set<string> = new Set()
8
8
 
9
- const getPaths = (routes: RouteRecord[], prefix = '') => {
9
+ const getPaths = (routes: RouteRecordRaw[], prefix = '') => {
10
10
  // remove trailing slash
11
11
  prefix = prefix.replace(/\/$/g, '')
12
12
  for (const route of routes) {
package/src/node/index.ts CHANGED
@@ -1,6 +1,6 @@
1
1
  import vuePlugin from '@vitejs/plugin-vue'
2
2
  import type { Alias, InlineConfig, UserConfig } from 'vite'
3
- import { resolveConfig } from 'vite'
3
+ import { resolvePackageData } from 'vite'
4
4
  import { mergeConfig } from 'vite'
5
5
  import { build } from 'esbuild'
6
6
  import fs from 'fs'
@@ -50,23 +50,24 @@ const manualChunkNames = [
50
50
  ]
51
51
 
52
52
  const moduleChunks = {
53
- vue: ['vue', '@vue', 'vue-router'],
54
- quasar: ['quasar']
53
+ vue: ['vue', 'vue-router'],
54
+ quasar: ['quasar', '@quasar']
55
55
  }
56
- const manualChunks: ManualChunksOption = (id, api) => {
57
- if (id.includes('vitrify/src/')) {
56
+ const manualChunks: ManualChunksOption = (id: string) => {
57
+ const matchedModule = Object.entries(moduleChunks).find(
58
+ ([chunkName, moduleNames]) =>
59
+ moduleNames.some((moduleName) => id.includes(moduleName + '/'))
60
+ )
61
+ if (id.includes('vitrify/src/vite/')) {
58
62
  const name = id.split('/').at(-1)?.split('.').at(0)
59
63
  if (name && manualChunkNames.includes(name)) return name
60
- return 'vitrify'
64
+ } else if (matchedModule) {
65
+ return matchedModule[0]
61
66
  } else if (
62
67
  VIRTUAL_MODULES.some((virtualModule) => id.includes(virtualModule))
63
68
  ) {
64
69
  return VIRTUAL_MODULES.find((name) => id.includes(name))
65
70
  } else if (id.includes('node_modules')) {
66
- const name = Object.entries(moduleChunks).find(([chunkName, moduleNames]) =>
67
- moduleNames.some((name) => id.includes(`${name}/`))
68
- )
69
- if (name) return name[0]
70
71
  return 'vendor'
71
72
  }
72
73
  }
@@ -205,14 +206,16 @@ export const baseConfig = async ({
205
206
  vitrifyConfig = {}
206
207
  }
207
208
 
208
- // const localPackages = ['vue', 'vue-router', '@vue/server-renderer']
209
- const localPackages: string[] = []
209
+ const localPackages = ['vue', 'vue-router', '@vue/server-renderer']
210
+ // const localPackages: string[] = []
210
211
  const cliPackages = []
211
212
  const packageUrls: Record<string, URL> =
212
213
  vitrifyConfig.vitrify?.urls?.packages || {}
213
214
  await (async () => {
214
- for (const val of localPackages)
215
- packageUrls[val] = getPkgJsonDir(new URL(resolve(val, appDir)))
215
+ for (const val of localPackages) {
216
+ const pkg = resolvePackageData(val, appDir.pathname)
217
+ if (pkg) packageUrls![val] = new URL(`file://${pkg.dir}/`)
218
+ }
216
219
  })()
217
220
 
218
221
  // await (async () => {
@@ -459,15 +462,19 @@ export const baseConfig = async ({
459
462
  ...Object.entries(packageUrls).map(([key, value]) => ({
460
463
  find: key,
461
464
  replacement: value.pathname
462
- })),
463
- {
464
- find: new RegExp('^vue$'),
465
- replacement: 'vue/dist/vue.runtime.esm-bundler.js'
466
- },
467
- {
468
- find: new RegExp('^vue-router$'),
469
- replacement: 'vue-router/dist/vue-router.esm-bundler.js'
470
- }
465
+ }))
466
+ // {
467
+ // find: new RegExp('^vue$'),
468
+ // replacement: 'vue/dist/vue.runtime.esm-bundler.js'
469
+ // },
470
+ // {
471
+ // find: new RegExp('^vue/server-renderer$'),
472
+ // replacement: 'vue/server-renderer/index.mjs'
473
+ // },
474
+ // {
475
+ // find: new RegExp('^vue-router$'),
476
+ // replacement: 'vue-router/dist/vue-router.esm-bundler.js'
477
+ // }
471
478
  // { find: 'vue', replacement: packageUrls['vue'].pathname },
472
479
  // { find: 'vue-router', replacement: packageUrls['vue-router'].pathname },
473
480
  // { find: 'vitrify', replacement: cliDir.pathname }
@@ -578,16 +585,10 @@ export const baseConfig = async ({
578
585
  },
579
586
  plugins,
580
587
  optimizeDeps: {
581
- exclude: [
582
- 'vue',
583
- 'vue-router',
584
- 'vue/server-renderer',
585
- ...serverModules,
586
- ...builtinModules
587
- ]
588
+ exclude: ['vue', 'vue-router', ...serverModules, ...builtinModules]
588
589
  },
589
590
  resolve: {
590
- dedupe: ['vue', '@vue/server-renderer', 'vue-router'],
591
+ dedupe: ['vue', 'vue-router'],
591
592
  alias
592
593
  },
593
594
  build: {
@@ -1,5 +1,6 @@
1
1
  import { readFileSync } from 'fs'
2
2
  import type { Plugin } from 'vite'
3
+ import { resolvePackageData } from 'vite'
3
4
  import Components from 'unplugin-vue-components/vite'
4
5
  // import { prepareQuasarConf } from './quasar-conf-file.js'
5
6
  import type {
@@ -119,13 +120,16 @@ export const QuasarPlugin: VitrifyPlugin = async ({
119
120
  (extra) => `@quasar/extras/${extra}/${extra}.css`
120
121
  )
121
122
 
122
- // const localPackages = ['@quasar/extras', 'quasar']
123
- const localPackages: string[] = []
123
+ const localPackages = ['@quasar/extras', 'quasar']
124
+ // const localPackages: string[] = []
124
125
  await (async () => {
125
- for (const val of localPackages)
126
- urls!.packages![val] = getPkgJsonDir(
127
- new URL(await resolve(val, urls!.app!))
126
+ for (const val of localPackages) {
127
+ const pkg = resolvePackageData(
128
+ val,
129
+ config.vitrify!.urls!.app!.pathname
128
130
  )
131
+ if (pkg) urls!.packages![val] = new URL(`file://${pkg.dir}/`)
132
+ }
129
133
  })()
130
134
 
131
135
  const onMountedHooks: OnMountedHook[] = [
@@ -256,13 +260,13 @@ export const QuasarPlugin: VitrifyPlugin = async ({
256
260
  // urls?.packages?.quasar
257
261
  // ).pathname
258
262
  // },
259
- // {
260
- // find: 'quasar/src/',
261
- // replacement: new URL(
262
- // 'node_modules/quasar/src/',
263
- // config.vitrify?.urls?.app
264
- // ).pathname
265
- // }
263
+ {
264
+ find: 'quasar/src',
265
+ replacement: new URL(
266
+ './src',
267
+ config.vitrify!.urls!.packages!.quasar
268
+ ).pathname
269
+ }
266
270
  // {
267
271
  // find: 'quasar',
268
272
  // replacement: new URL(
@@ -1,5 +1,5 @@
1
1
  import { createApp } from '../main.js'
2
- import { renderToString } from 'vue/server-renderer'
2
+ // import { renderToString } from 'vue/server-renderer'
3
3
 
4
4
  import { onRendered } from 'virtual:vitrify-hooks'
5
5
 
@@ -37,7 +37,9 @@ export const getRoutes = async () =>
37
37
  })
38
38
  ).routes
39
39
 
40
- export async function render(url, manifest, ssrContext) {
40
+ export async function render(url, manifest, ssrContext, renderToString) {
41
+ if (!renderToString)
42
+ renderToString = (await import('vue/server-renderer')).renderToString
41
43
  const { app, router } = await initializeApp(url, ssrContext)
42
44
 
43
45
  const ctx = {