vitrify 0.21.0 → 0.23.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/dist/bin/cli.js +3 -3
- package/dist/bin/dev.js +26 -39
- package/dist/frameworks/vue/fastify-ssr-plugin.js +58 -19
- package/dist/frameworks/vue/prerender.js +4 -4
- package/dist/frameworks/vue/server.js +5 -1
- package/dist/hooks/index.js +1 -0
- package/dist/index.js +80 -94
- package/dist/plugins/index.js +2 -1
- package/dist/plugins/pinia/index.js +61 -0
- package/dist/plugins/quasar/index.js +226 -0
- package/dist/types/frameworks/vue/fastify-ssr-plugin.d.ts +6 -3
- package/dist/types/frameworks/vue/prerender.d.ts +3 -3
- package/dist/types/frameworks/vue/server.d.ts +4 -4
- package/dist/types/hooks/index.d.ts +2 -0
- package/dist/types/index.d.ts +2 -2
- package/dist/types/plugins/index.d.ts +13 -2
- package/dist/types/plugins/pinia/index.d.ts +5 -0
- package/dist/types/plugins/{quasar.d.ts → quasar/index.d.ts} +5 -5
- package/dist/types/vitrify-config.d.ts +87 -12
- package/package.json +37 -25
- package/src/node/bin/cli.ts +13 -7
- package/src/node/bin/dev.ts +30 -41
- package/src/node/frameworks/vue/fastify-ssr-plugin.ts +85 -28
- package/src/node/frameworks/vue/prerender.ts +6 -6
- package/src/node/frameworks/vue/server.ts +11 -2
- package/src/node/hooks/index.ts +19 -0
- package/src/node/index.ts +114 -130
- package/src/node/plugins/index.ts +20 -3
- package/src/node/plugins/pinia/index.ts +96 -0
- package/src/node/plugins/quasar/index.ts +318 -0
- package/src/node/vitrify-config.ts +120 -21
- package/src/vite/fastify/server.ts +3 -0
- package/src/vite/vue/RootComponent.vue +1 -1
- package/src/vite/vue/main.ts +52 -22
- package/src/vite/vue/ssr/app.ts +3 -2
- package/src/vite/vue/ssr/entry-server.ts +22 -41
- package/src/vite/vue/ssr/prerender.ts +2 -2
- package/dist/plugins/quasar.js +0 -217
- package/src/node/plugins/quasar.ts +0 -307
package/src/node/index.ts
CHANGED
|
@@ -1,5 +1,10 @@
|
|
|
1
1
|
import vuePlugin from '@vitejs/plugin-vue'
|
|
2
|
-
import type {
|
|
2
|
+
import type {
|
|
3
|
+
Alias,
|
|
4
|
+
InlineConfig,
|
|
5
|
+
Plugin,
|
|
6
|
+
UserConfig as ViteUserConfig
|
|
7
|
+
} from 'vite'
|
|
3
8
|
import { findDepPkgJsonPath } from 'vitefu'
|
|
4
9
|
import { mergeConfig } from 'vite'
|
|
5
10
|
import { build } from 'esbuild'
|
|
@@ -12,7 +17,6 @@ import { visualizer } from 'rollup-plugin-visualizer'
|
|
|
12
17
|
import { fileURLToPath } from 'url'
|
|
13
18
|
import type {
|
|
14
19
|
StaticImports,
|
|
15
|
-
BootFunction,
|
|
16
20
|
OnMountedHook,
|
|
17
21
|
VitrifyConfig,
|
|
18
22
|
VitrifyConfigAsync,
|
|
@@ -22,17 +26,19 @@ import type {
|
|
|
22
26
|
VitrifySSRModes,
|
|
23
27
|
OnRenderedHook,
|
|
24
28
|
OnBootHook,
|
|
25
|
-
OnSetupFile
|
|
29
|
+
OnSetupFile,
|
|
30
|
+
onAppCreatedHook,
|
|
31
|
+
OnTemplateRenderedHook
|
|
26
32
|
} from './vitrify-config.js'
|
|
27
33
|
import type { VitrifyContext } from './bin/run.js'
|
|
28
34
|
import type { VitrifyPlugin } from './plugins/index.js'
|
|
29
35
|
import { resolve } from './app-urls.js'
|
|
30
36
|
import type { ManualChunksOption, RollupOptions } from 'rollup'
|
|
31
37
|
import { addOrReplaceTitle, appendToBody } from './helpers/utils.js'
|
|
32
|
-
import type { ComponentResolver } from 'unplugin-vue-components'
|
|
33
38
|
import Components from 'unplugin-vue-components/vite'
|
|
34
39
|
import { VitePWA } from 'vite-plugin-pwa'
|
|
35
40
|
import UnoCSS from 'unocss/vite'
|
|
41
|
+
import { searchForWorkspaceRoot } from 'vite'
|
|
36
42
|
|
|
37
43
|
const internalServerModules = [
|
|
38
44
|
'util',
|
|
@@ -50,21 +56,6 @@ const internalServerModules = [
|
|
|
50
56
|
'abort-controller'
|
|
51
57
|
]
|
|
52
58
|
|
|
53
|
-
const configPluginMap: Record<string, () => Promise<VitrifyPlugin>> = {
|
|
54
|
-
quasar: () =>
|
|
55
|
-
import('./plugins/quasar.js').then((module) => module.QuasarPlugin)
|
|
56
|
-
}
|
|
57
|
-
|
|
58
|
-
const configResolverMap: Record<
|
|
59
|
-
string,
|
|
60
|
-
() => Promise<ComponentResolver | ComponentResolver[]>
|
|
61
|
-
> = {
|
|
62
|
-
quasar: () =>
|
|
63
|
-
import('unplugin-vue-components/resolvers').then((module) =>
|
|
64
|
-
module.QuasarResolver()
|
|
65
|
-
)
|
|
66
|
-
}
|
|
67
|
-
|
|
68
59
|
const manualChunkNames = [
|
|
69
60
|
'prerender',
|
|
70
61
|
'fastify-ssr-plugin',
|
|
@@ -73,7 +64,7 @@ const manualChunkNames = [
|
|
|
73
64
|
]
|
|
74
65
|
|
|
75
66
|
const moduleChunks = {
|
|
76
|
-
vue: ['vue', '@vue', 'vue-router'],
|
|
67
|
+
vue: ['vue', '@vue', 'vue-router', 'pinia', '@pinia/colada', '@vue/devtools'],
|
|
77
68
|
quasar: ['quasar'],
|
|
78
69
|
atQuasar: ['@quasar']
|
|
79
70
|
}
|
|
@@ -103,31 +94,6 @@ const manualChunksFn = (manualChunkList?: string[]): ManualChunksOption => {
|
|
|
103
94
|
}
|
|
104
95
|
}
|
|
105
96
|
|
|
106
|
-
// const manualChunks: ManualChunksOption = (
|
|
107
|
-
// id: string,
|
|
108
|
-
// manualChunkList?: string[]
|
|
109
|
-
// ) => {
|
|
110
|
-
// const matchedModule = Object.entries(moduleChunks).find(
|
|
111
|
-
// ([chunkName, moduleNames]) =>
|
|
112
|
-
// moduleNames.some((moduleName) => id.includes(moduleName + '/'))
|
|
113
|
-
// )
|
|
114
|
-
// if (id.includes('vitrify/src/')) {
|
|
115
|
-
// const name = id.split('/').at(-1)?.split('.').at(0)
|
|
116
|
-
// if (name && manualChunkNames.includes(name)) return name
|
|
117
|
-
// } else if (
|
|
118
|
-
// VIRTUAL_MODULES.some((virtualModule) => id.includes(virtualModule))
|
|
119
|
-
// ) {
|
|
120
|
-
// return VIRTUAL_MODULES.find((name) => id.includes(name))
|
|
121
|
-
// } else if (manualChunkList?.some((file) => id.includes(file))) {
|
|
122
|
-
// return manualChunkList.find((file) => id.includes(file))
|
|
123
|
-
// } else if (id.includes('node_modules')) {
|
|
124
|
-
// if (matchedModule) {
|
|
125
|
-
// return matchedModule[0]
|
|
126
|
-
// }
|
|
127
|
-
// return 'vendor'
|
|
128
|
-
// }
|
|
129
|
-
// }
|
|
130
|
-
|
|
131
97
|
export const VIRTUAL_MODULES = [
|
|
132
98
|
'virtual:vitrify-hooks',
|
|
133
99
|
'virtual:static-imports',
|
|
@@ -241,7 +207,6 @@ export const baseConfig = async ({
|
|
|
241
207
|
fs.writeFileSync(configPath + '.js', bundledConfig.code)
|
|
242
208
|
|
|
243
209
|
rawVitrifyConfig = (await import('file://' + configPath + '.js')).default
|
|
244
|
-
// vitrifyConfig = (await import(configPath + '.js')).default
|
|
245
210
|
fs.unlinkSync(configPath + '.js')
|
|
246
211
|
} else {
|
|
247
212
|
rawVitrifyConfig = (
|
|
@@ -258,9 +223,11 @@ export const baseConfig = async ({
|
|
|
258
223
|
throw e
|
|
259
224
|
}
|
|
260
225
|
|
|
261
|
-
const localPackages = [
|
|
262
|
-
|
|
263
|
-
|
|
226
|
+
const localPackages = []
|
|
227
|
+
if (framework === 'vue')
|
|
228
|
+
localPackages.push('vue', 'vue-router', '@vue/server-renderer')
|
|
229
|
+
|
|
230
|
+
const cliPackages: string[] = []
|
|
264
231
|
const packageUrls: Record<string, URL> =
|
|
265
232
|
vitrifyConfig.vitrify?.urls?.packages || {}
|
|
266
233
|
await (async () => {
|
|
@@ -269,14 +236,6 @@ export const baseConfig = async ({
|
|
|
269
236
|
if (pkgDir) packageUrls![val] = new URL(`file://${pkgDir}`)
|
|
270
237
|
}
|
|
271
238
|
})()
|
|
272
|
-
|
|
273
|
-
// await (async () => {
|
|
274
|
-
// for (const val of cliPackages)
|
|
275
|
-
// packageUrls[val] = getPkgJsonDir(
|
|
276
|
-
// new URL(await resolve(val, cliDir!.href))
|
|
277
|
-
// )
|
|
278
|
-
// })()
|
|
279
|
-
|
|
280
239
|
if (!productName) {
|
|
281
240
|
try {
|
|
282
241
|
;({ productName } = JSON.parse(
|
|
@@ -294,26 +253,36 @@ export const baseConfig = async ({
|
|
|
294
253
|
|
|
295
254
|
const isPwa = !!vitrifyConfig.vitrify?.pwa || false
|
|
296
255
|
|
|
297
|
-
const frameworkPlugins = []
|
|
298
|
-
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
302
|
-
|
|
303
|
-
|
|
304
|
-
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
)
|
|
310
|
-
|
|
256
|
+
const frameworkPlugins: Plugin[] = []
|
|
257
|
+
if (framework === 'vue') {
|
|
258
|
+
frameworkPlugins.push(vuePlugin())
|
|
259
|
+
}
|
|
260
|
+
|
|
261
|
+
const vitrifyPlugins: Plugin[] = []
|
|
262
|
+
if (vitrifyConfig.vitrify?.plugins) {
|
|
263
|
+
for (const vitrifyPluginConfig of vitrifyConfig.vitrify.plugins) {
|
|
264
|
+
const vitrifyPlugin = await vitrifyPluginConfig.plugin({
|
|
265
|
+
ssr,
|
|
266
|
+
pwa: isPwa,
|
|
267
|
+
options: vitrifyPluginConfig.options
|
|
268
|
+
})
|
|
269
|
+
if ('plugin' in vitrifyPlugin) {
|
|
270
|
+
vitrifyPlugins.push(vitrifyPlugin.plugin)
|
|
271
|
+
} else if ('plugins' in vitrifyPlugin) {
|
|
272
|
+
vitrifyPlugins.push(...vitrifyPlugin.plugins)
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
if (vitrifyPlugin.config) {
|
|
276
|
+
vitrifyConfig = mergeConfig(vitrifyConfig, vitrifyPlugin.config)
|
|
277
|
+
}
|
|
311
278
|
}
|
|
312
279
|
}
|
|
313
280
|
|
|
314
281
|
let onBootHooks: OnBootHook[]
|
|
315
282
|
let onRenderedHooks: OnRenderedHook[]
|
|
283
|
+
let onTemplateRenderedHooks: OnTemplateRenderedHook[]
|
|
316
284
|
let onMountedHooks: OnMountedHook[]
|
|
285
|
+
let onAppCreatedHooks: onAppCreatedHook[]
|
|
317
286
|
let onSetupFiles: OnSetupFile[]
|
|
318
287
|
let globalCss: string[] = []
|
|
319
288
|
let staticImports: StaticImports
|
|
@@ -378,21 +347,23 @@ export const baseConfig = async ({
|
|
|
378
347
|
/<style lang="sass">(.*?)<\/style>/,
|
|
379
348
|
'<style lang="sass">' + sass + '</style>'
|
|
380
349
|
)
|
|
381
|
-
// code = code.replace(/<\/style>/, sass + '</style>')
|
|
382
350
|
}
|
|
383
351
|
|
|
384
352
|
return code
|
|
385
353
|
}
|
|
386
354
|
},
|
|
387
|
-
vuePlugin(),
|
|
388
355
|
...frameworkPlugins,
|
|
356
|
+
...vitrifyPlugins,
|
|
389
357
|
{
|
|
390
358
|
name: 'vitrify-setup',
|
|
391
359
|
enforce: 'post',
|
|
392
360
|
config: (config: VitrifyConfig, env) => {
|
|
393
361
|
onBootHooks = config.vitrify?.hooks?.onBoot || []
|
|
394
362
|
onRenderedHooks = config.vitrify?.hooks?.onRendered || []
|
|
363
|
+
onTemplateRenderedHooks =
|
|
364
|
+
config.vitrify?.hooks?.onTemplateRendered || []
|
|
395
365
|
onMountedHooks = config.vitrify?.hooks?.onMounted || []
|
|
366
|
+
onAppCreatedHooks = config.vitrify?.hooks?.onAppCreated || []
|
|
396
367
|
onSetupFiles = config?.vitrify?.hooks?.onSetup || []
|
|
397
368
|
globalCss = config.vitrify?.globalCss || []
|
|
398
369
|
staticImports = config.vitrify?.staticImports || {}
|
|
@@ -430,6 +401,12 @@ export const baseConfig = async ({
|
|
|
430
401
|
export const onRendered = [${onRenderedHooks
|
|
431
402
|
.map((fn) => `${String(fn)}`)
|
|
432
403
|
.join(', ')}]
|
|
404
|
+
export const onTemplateRendered = [${onTemplateRenderedHooks
|
|
405
|
+
.map((fn) => `${String(fn)}`)
|
|
406
|
+
.join(', ')}]
|
|
407
|
+
export const onAppCreated = [${onAppCreatedHooks
|
|
408
|
+
.map((fn) => `${String(fn)}`)
|
|
409
|
+
.join(', ')}]
|
|
433
410
|
export const onSetup = []
|
|
434
411
|
${onSetupFiles
|
|
435
412
|
.map((url, index) => {
|
|
@@ -445,10 +422,6 @@ export const baseConfig = async ({
|
|
|
445
422
|
return `import ${varName} from '${
|
|
446
423
|
new URL(url, appDir).pathname
|
|
447
424
|
}'; onSetup.push(${varName})`
|
|
448
|
-
|
|
449
|
-
// return `import ${varName} from '${fileURLToPath(
|
|
450
|
-
// url
|
|
451
|
-
// )}'; onSetup.push(${varName})`
|
|
452
425
|
})
|
|
453
426
|
.join('\n')}`
|
|
454
427
|
} else if (id === 'virtual:static-imports') {
|
|
@@ -465,11 +438,7 @@ export const baseConfig = async ({
|
|
|
465
438
|
),
|
|
466
439
|
...globalSass.map((sass) => `@import '${sass}'`)
|
|
467
440
|
].join('\n')
|
|
468
|
-
}
|
|
469
|
-
// else if (id === 'vitrify.css') {
|
|
470
|
-
// return `${globalCss.map((css) => `@import '${css}'`).join('\n')}`
|
|
471
|
-
// }
|
|
472
|
-
else if (id === 'virtual:vitrify-config') {
|
|
441
|
+
} else if (id === 'virtual:vitrify-config') {
|
|
473
442
|
return `export default ${JSON.stringify(vitrifyConfig)}`
|
|
474
443
|
}
|
|
475
444
|
return null
|
|
@@ -499,14 +468,14 @@ export const baseConfig = async ({
|
|
|
499
468
|
}
|
|
500
469
|
},
|
|
501
470
|
Components({
|
|
471
|
+
...vitrifyConfig.vitrify?.unpluginVueComponents,
|
|
502
472
|
exclude: [
|
|
503
473
|
new RegExp(
|
|
504
474
|
`[\\/]node_modules[\\/].*[\\/]!(${serverModules.join('|')})`
|
|
505
475
|
),
|
|
506
476
|
/[\\/]\.git[\\/]/,
|
|
507
477
|
/[\\/]\.nuxt[\\/]/
|
|
508
|
-
]
|
|
509
|
-
resolvers
|
|
478
|
+
]
|
|
510
479
|
}),
|
|
511
480
|
UnoCSS({
|
|
512
481
|
...vitrifyConfig.vitrify?.unocss,
|
|
@@ -559,32 +528,13 @@ export const baseConfig = async ({
|
|
|
559
528
|
} else {
|
|
560
529
|
entryScript = `<script type="module" src="${entry}"></script>`
|
|
561
530
|
}
|
|
562
|
-
// html = html.replace('<!--entry-script-->', entryScript)
|
|
563
531
|
html = appendToBody(entryScript, html)
|
|
564
532
|
if (productName) html = addOrReplaceTitle(productName, html)
|
|
565
|
-
// html = html.replace('<!--product-name-->', productName)
|
|
566
533
|
return html
|
|
567
534
|
}
|
|
568
535
|
}
|
|
569
536
|
})
|
|
570
537
|
|
|
571
|
-
// plugins.unshift({
|
|
572
|
-
// name: 'product-name',
|
|
573
|
-
// enforce: 'post',
|
|
574
|
-
// config: (config: VitrifyConfig, env) => {
|
|
575
|
-
// if (config.vitrify?.productName)
|
|
576
|
-
// productName = config.vitrify?.productName
|
|
577
|
-
// return
|
|
578
|
-
// },
|
|
579
|
-
// transformIndexHtml: {
|
|
580
|
-
// enforce: 'post',
|
|
581
|
-
// transform: (html) => {
|
|
582
|
-
// html = html.replace('<!--product-name-->', productName)
|
|
583
|
-
// return html
|
|
584
|
-
// }
|
|
585
|
-
// }
|
|
586
|
-
// })
|
|
587
|
-
|
|
588
538
|
if (debug) plugins.push(visualizer())
|
|
589
539
|
}
|
|
590
540
|
|
|
@@ -599,19 +549,40 @@ export const baseConfig = async ({
|
|
|
599
549
|
]
|
|
600
550
|
|
|
601
551
|
const vuePkgAliases: Alias[] = []
|
|
602
|
-
|
|
603
|
-
const
|
|
604
|
-
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
|
|
552
|
+
if (packageUrls['vue']) {
|
|
553
|
+
for (const pkg of vueInternalPkgs) {
|
|
554
|
+
const specifier = pkg.split('/').at(-1)
|
|
555
|
+
const pkgJsonPath = await findDepPkgJsonPath(pkg, fileURLToPath(appDir!))
|
|
556
|
+
if (pkgJsonPath)
|
|
557
|
+
vuePkgAliases.push({
|
|
558
|
+
find: pkg,
|
|
559
|
+
replacement: fileURLToPath(
|
|
560
|
+
new URL(
|
|
561
|
+
`./dist/${specifier}.esm-bundler.js`,
|
|
562
|
+
`file://${pkgJsonPath}` || ''
|
|
563
|
+
)
|
|
612
564
|
)
|
|
613
|
-
)
|
|
614
|
-
|
|
565
|
+
})
|
|
566
|
+
|
|
567
|
+
vuePkgAliases.push(
|
|
568
|
+
{
|
|
569
|
+
find: new RegExp('^vue$'),
|
|
570
|
+
replacement: fileURLToPath(
|
|
571
|
+
new URL('./dist/vue.runtime.esm-bundler.js', packageUrls['vue'])
|
|
572
|
+
)
|
|
573
|
+
},
|
|
574
|
+
{
|
|
575
|
+
find: new RegExp('^vue-router$'),
|
|
576
|
+
replacement: fileURLToPath(
|
|
577
|
+
new URL(
|
|
578
|
+
'./dist/vue-router.esm-bundler.js',
|
|
579
|
+
packageUrls['vue-router']
|
|
580
|
+
)
|
|
581
|
+
)
|
|
582
|
+
},
|
|
583
|
+
...vuePkgAliases
|
|
584
|
+
)
|
|
585
|
+
}
|
|
615
586
|
}
|
|
616
587
|
|
|
617
588
|
const alias: Alias[] = [
|
|
@@ -619,21 +590,11 @@ export const baseConfig = async ({
|
|
|
619
590
|
{ find: 'app', replacement: fileURLToPath(appDir) },
|
|
620
591
|
{ find: 'cwd', replacement: fileURLToPath(cwd) },
|
|
621
592
|
{ find: 'boot', replacement: fileURLToPath(new URL('boot/', srcDir)) },
|
|
622
|
-
{ find: 'assets', replacement: fileURLToPath(new URL('assets/', srcDir)) }
|
|
623
|
-
{
|
|
624
|
-
find: new RegExp('^vue$'),
|
|
625
|
-
replacement: fileURLToPath(
|
|
626
|
-
new URL('./dist/vue.runtime.esm-bundler.js', packageUrls['vue'])
|
|
627
|
-
)
|
|
628
|
-
},
|
|
629
|
-
{
|
|
630
|
-
find: new RegExp('^vue-router$'),
|
|
631
|
-
replacement: fileURLToPath(
|
|
632
|
-
new URL('./dist/vue-router.esm-bundler.js', packageUrls['vue-router'])
|
|
633
|
-
)
|
|
634
|
-
},
|
|
635
|
-
...vuePkgAliases
|
|
593
|
+
{ find: 'assets', replacement: fileURLToPath(new URL('assets/', srcDir)) }
|
|
636
594
|
]
|
|
595
|
+
|
|
596
|
+
if (framework === 'vue') alias.push(...vuePkgAliases)
|
|
597
|
+
|
|
637
598
|
if (mode === 'development' && vitrifyConfig.vitrify?.dev?.alias)
|
|
638
599
|
alias.push(...vitrifyConfig.vitrify.dev.alias)
|
|
639
600
|
|
|
@@ -704,6 +665,7 @@ export const baseConfig = async ({
|
|
|
704
665
|
|
|
705
666
|
const config = {
|
|
706
667
|
root: fileURLToPath(appDir),
|
|
668
|
+
appType: ssr ? 'custom' : 'spa',
|
|
707
669
|
publicDir: fileURLToPath(publicDir),
|
|
708
670
|
base,
|
|
709
671
|
envDir: fileURLToPath(appDir),
|
|
@@ -740,6 +702,28 @@ export const baseConfig = async ({
|
|
|
740
702
|
__HOST__: `'localhost'`,
|
|
741
703
|
__BASE_URL__: `'${base}'`,
|
|
742
704
|
__IS_PWA__: `${isPwa}`
|
|
705
|
+
},
|
|
706
|
+
// environments: {
|
|
707
|
+
// },
|
|
708
|
+
server: {
|
|
709
|
+
https: vitrifyConfig.server?.https,
|
|
710
|
+
// middlewareMode: mode === 'ssr' ? 'ssr' : undefined,
|
|
711
|
+
middlewareMode: ssr ? true : false,
|
|
712
|
+
fs: {
|
|
713
|
+
strict: false, // https://github.com/vitejs/vite/issues/8175
|
|
714
|
+
allow: [
|
|
715
|
+
searchForWorkspaceRoot(process.cwd()),
|
|
716
|
+
searchForWorkspaceRoot(fileURLToPath(appDir)),
|
|
717
|
+
searchForWorkspaceRoot(fileURLToPath(cliDir)),
|
|
718
|
+
fileURLToPath(appDir)
|
|
719
|
+
]
|
|
720
|
+
},
|
|
721
|
+
watch: {
|
|
722
|
+
// During tests we edit the files too fast and sometimes chokidar
|
|
723
|
+
// misses change events, so enforce polling for consistency
|
|
724
|
+
usePolling: true,
|
|
725
|
+
interval: 100
|
|
726
|
+
}
|
|
743
727
|
}
|
|
744
728
|
} as VitrifyConfig
|
|
745
729
|
|
|
@@ -754,5 +738,5 @@ export type {
|
|
|
754
738
|
VitrifyConfigAsync,
|
|
755
739
|
VitrifyPlugin,
|
|
756
740
|
VitrifyContext,
|
|
757
|
-
|
|
741
|
+
OnBootHook
|
|
758
742
|
}
|
|
@@ -1,12 +1,29 @@
|
|
|
1
1
|
import type { Plugin } from 'vite'
|
|
2
|
+
import { VitrifyConfig } from '../vitrify-config.js'
|
|
2
3
|
|
|
3
|
-
|
|
4
|
+
type VitrifyPluginReturnType =
|
|
5
|
+
| {
|
|
6
|
+
plugin: Plugin
|
|
7
|
+
config?: Partial<VitrifyConfig>
|
|
8
|
+
}
|
|
9
|
+
| {
|
|
10
|
+
plugins: Plugin[]
|
|
11
|
+
config?: Partial<VitrifyConfig>
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export type VitrifyPlugin<Options> = ({
|
|
4
15
|
ssr,
|
|
16
|
+
pwa,
|
|
5
17
|
mode,
|
|
6
|
-
command
|
|
18
|
+
command,
|
|
19
|
+
options
|
|
7
20
|
}: {
|
|
8
21
|
ssr?: 'server' | 'client' | 'ssg' | 'fastify' | false
|
|
9
22
|
pwa?: boolean
|
|
10
23
|
mode?: 'production' | 'development'
|
|
11
24
|
command?: 'build' | 'dev' | 'test'
|
|
12
|
-
|
|
25
|
+
options: Options
|
|
26
|
+
}) => Promise<VitrifyPluginReturnType> | VitrifyPluginReturnType
|
|
27
|
+
|
|
28
|
+
export * from './quasar/index.js'
|
|
29
|
+
export * from './pinia/index.js'
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
import type { onAppCreatedHook, OnRenderedHook } from '../../vitrify-config.js'
|
|
2
|
+
import type { VitrifyPlugin } from '../index.js'
|
|
3
|
+
|
|
4
|
+
export type PiniaPluginOptions = {
|
|
5
|
+
// Initialize Pinia Colada
|
|
6
|
+
colada?: boolean
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
const piniaonAppCreated: onAppCreatedHook = async ({
|
|
10
|
+
app,
|
|
11
|
+
ctx,
|
|
12
|
+
initialState,
|
|
13
|
+
ssrContext
|
|
14
|
+
}) => {
|
|
15
|
+
const { createPinia } = await import('pinia')
|
|
16
|
+
const pinia = createPinia()
|
|
17
|
+
ctx.pinia = pinia
|
|
18
|
+
app.use(pinia)
|
|
19
|
+
|
|
20
|
+
// SSR Client
|
|
21
|
+
if (initialState?.pinia) pinia.state.value = initialState.pinia
|
|
22
|
+
// SSR Server
|
|
23
|
+
if (ssrContext) ssrContext.pinia = pinia
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
const piniaOnRenderedHook: OnRenderedHook = ({ app, ssrContext }) => {
|
|
27
|
+
// SSR Server
|
|
28
|
+
if (ssrContext?.initialState && ssrContext.pinia) {
|
|
29
|
+
ssrContext.initialState.pinia = ssrContext.pinia.state.value
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const piniaColadaonAppCreated: onAppCreatedHook = async ({
|
|
34
|
+
app,
|
|
35
|
+
ctx,
|
|
36
|
+
initialState
|
|
37
|
+
}) => {
|
|
38
|
+
if (ctx?.pinia) {
|
|
39
|
+
const { PiniaColada, useQueryCache, hydrateQueryCache } = await import(
|
|
40
|
+
'@pinia/colada'
|
|
41
|
+
)
|
|
42
|
+
|
|
43
|
+
app.use(PiniaColada)
|
|
44
|
+
|
|
45
|
+
// SSR Client
|
|
46
|
+
if (initialState?.piniaColada) {
|
|
47
|
+
hydrateQueryCache(useQueryCache(ctx.pinia), initialState.piniaColada)
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
const piniaColadaOnRenderedHook: OnRenderedHook = async ({
|
|
53
|
+
app,
|
|
54
|
+
ssrContext
|
|
55
|
+
}) => {
|
|
56
|
+
// SSR Server
|
|
57
|
+
if (ssrContext?.initialState && ssrContext.pinia) {
|
|
58
|
+
const { useQueryCache, serializeQueryCache } = await import('@pinia/colada')
|
|
59
|
+
|
|
60
|
+
// Delete to prevent Non-POJO error
|
|
61
|
+
if (ssrContext.initialState.pinia?._pc_query) {
|
|
62
|
+
delete ssrContext.initialState.pinia._pc_query
|
|
63
|
+
}
|
|
64
|
+
ssrContext.initialState.piniaColada = serializeQueryCache(
|
|
65
|
+
useQueryCache(ssrContext.pinia)
|
|
66
|
+
)
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
export const PiniaPlugin: VitrifyPlugin<PiniaPluginOptions> = async ({
|
|
71
|
+
ssr = false,
|
|
72
|
+
pwa = false,
|
|
73
|
+
options = {}
|
|
74
|
+
}) => {
|
|
75
|
+
const onAppCreated = [piniaonAppCreated]
|
|
76
|
+
const onRendered = [piniaOnRenderedHook]
|
|
77
|
+
if (options.colada) {
|
|
78
|
+
onAppCreated.push(piniaColadaonAppCreated)
|
|
79
|
+
onRendered.push(piniaColadaOnRenderedHook)
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
return {
|
|
83
|
+
plugins: [],
|
|
84
|
+
config: {
|
|
85
|
+
vitrify: {
|
|
86
|
+
ssr: {
|
|
87
|
+
serverModules: ['@pinia/colada']
|
|
88
|
+
},
|
|
89
|
+
hooks: {
|
|
90
|
+
onAppCreated,
|
|
91
|
+
onRendered
|
|
92
|
+
}
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
}
|
|
96
|
+
}
|