vitrify 0.3.0 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/app-urls.js +1 -1
- package/dist/bin/cli.js +26 -4
- package/dist/bin/dev.js +59 -27
- package/dist/frameworks/vue/fastify-ssr-plugin.js +67 -16
- package/dist/frameworks/vue/server.js +9 -4
- package/dist/helpers/collect-css-ssr.js +57 -0
- package/dist/index.js +255 -69
- package/dist/plugins/quasar.js +9 -4
- package/dist/types/bin/build.d.ts +2 -2
- package/dist/types/bin/dev.d.ts +39 -3
- package/dist/types/frameworks/vue/fastify-ssr-plugin.d.ts +6 -3
- package/dist/types/frameworks/vue/server.d.ts +9 -5
- package/dist/types/helpers/collect-css-ssr.d.ts +10 -0
- package/dist/types/helpers/routes.d.ts +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/plugins/index.d.ts +1 -1
- package/dist/types/vitrify-config.d.ts +3 -4
- package/package.json +32 -32
- package/src/node/app-urls.ts +1 -1
- package/src/node/bin/build.ts +2 -2
- package/src/node/bin/cli.ts +33 -5
- package/src/node/bin/dev.ts +92 -34
- package/src/node/frameworks/vue/fastify-ssr-plugin.ts +80 -18
- package/src/node/frameworks/vue/server.ts +22 -8
- package/src/node/helpers/collect-css-ssr.ts +77 -0
- package/src/node/index.ts +285 -81
- package/src/node/plugins/index.ts +1 -1
- package/src/node/plugins/quasar.ts +9 -4
- package/src/node/vitrify-config.ts +7 -4
- package/src/vite/fastify/entry.ts +11 -0
- package/src/vite/fastify/server.ts +10 -0
- package/src/vite/vue/index.html +1 -0
- package/src/vite/vue/main.ts +0 -1
- package/src/vite/vue/ssr/app.ts +25 -0
- package/src/vite/vue/ssr/entry-server.ts +13 -1
- package/src/vite/vue/ssr/server.ts +23 -14
package/src/node/index.ts
CHANGED
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
import vuePlugin from '@vitejs/plugin-vue'
|
|
2
2
|
import type { InlineConfig, UserConfig } from 'vite'
|
|
3
|
+
import { resolveConfig } from 'vite'
|
|
3
4
|
import { mergeConfig } from 'vite'
|
|
5
|
+
import { build } from 'esbuild'
|
|
6
|
+
import fs from 'fs'
|
|
7
|
+
import path from 'path'
|
|
8
|
+
import { pathToFileURL } from 'url'
|
|
4
9
|
import { readFileSync } from 'fs'
|
|
5
10
|
import builtinModules from 'builtin-modules'
|
|
6
11
|
import { resolve } from 'import-meta-resolve'
|
|
@@ -11,13 +16,39 @@ import type {
|
|
|
11
16
|
VitrifyConfig,
|
|
12
17
|
OnRenderedHook,
|
|
13
18
|
OnBootHook,
|
|
14
|
-
|
|
19
|
+
OnSetupFile
|
|
15
20
|
} from './vitrify-config.js'
|
|
16
21
|
import type { VitrifyContext } from './bin/run.js'
|
|
17
22
|
import type { VitrifyPlugin } from './plugins/index.js'
|
|
18
23
|
import { getPkgJsonDir } from './app-urls.js'
|
|
24
|
+
import type { RollupOptions } from 'rollup'
|
|
19
25
|
|
|
20
|
-
const serverModules = [
|
|
26
|
+
const serverModules = [
|
|
27
|
+
// 'fs',
|
|
28
|
+
// 'path',
|
|
29
|
+
// 'url',
|
|
30
|
+
// 'module',
|
|
31
|
+
// 'crypto',
|
|
32
|
+
// 'node:fs',
|
|
33
|
+
'util',
|
|
34
|
+
'node:url',
|
|
35
|
+
'node:util',
|
|
36
|
+
'node:fs',
|
|
37
|
+
'vitrify',
|
|
38
|
+
'vite',
|
|
39
|
+
'fastify',
|
|
40
|
+
'middie',
|
|
41
|
+
'knex',
|
|
42
|
+
'bcrypt',
|
|
43
|
+
'objection',
|
|
44
|
+
'@fastify/formbody',
|
|
45
|
+
'@fastify/static',
|
|
46
|
+
'@fastify/cors',
|
|
47
|
+
'@fastify/cookie',
|
|
48
|
+
'mercurius',
|
|
49
|
+
'jose',
|
|
50
|
+
'oidc-provider'
|
|
51
|
+
]
|
|
21
52
|
|
|
22
53
|
const configPluginMap: Record<string, () => Promise<VitrifyPlugin>> = {
|
|
23
54
|
quasar: () =>
|
|
@@ -32,6 +63,64 @@ export const VIRTUAL_MODULES = [
|
|
|
32
63
|
'virtual:static-imports'
|
|
33
64
|
]
|
|
34
65
|
|
|
66
|
+
async function bundleConfigFile(
|
|
67
|
+
fileName: string,
|
|
68
|
+
isESM = false
|
|
69
|
+
): Promise<{ code: string; dependencies: string[] }> {
|
|
70
|
+
const result = await build({
|
|
71
|
+
absWorkingDir: process.cwd(),
|
|
72
|
+
entryPoints: [fileName],
|
|
73
|
+
outfile: 'out.js',
|
|
74
|
+
write: false,
|
|
75
|
+
platform: 'node',
|
|
76
|
+
bundle: true,
|
|
77
|
+
format: 'esm',
|
|
78
|
+
sourcemap: 'inline',
|
|
79
|
+
metafile: true,
|
|
80
|
+
plugins: [
|
|
81
|
+
{
|
|
82
|
+
name: 'externalize-deps',
|
|
83
|
+
setup(build) {
|
|
84
|
+
build.onResolve({ filter: /.*/ }, (args) => {
|
|
85
|
+
const id = args.path
|
|
86
|
+
if (id[0] !== '.' && !path.isAbsolute(id)) {
|
|
87
|
+
return {
|
|
88
|
+
external: true
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
})
|
|
92
|
+
}
|
|
93
|
+
},
|
|
94
|
+
{
|
|
95
|
+
name: 'replace-import-meta',
|
|
96
|
+
setup(build) {
|
|
97
|
+
build.onLoad({ filter: /\.[jt]s$/ }, async (args) => {
|
|
98
|
+
const contents = await fs.promises.readFile(args.path, 'utf8')
|
|
99
|
+
return {
|
|
100
|
+
loader: args.path.endsWith('.ts') ? 'ts' : 'js',
|
|
101
|
+
contents: contents
|
|
102
|
+
.replace(
|
|
103
|
+
/\bimport\.meta\.url\b/g,
|
|
104
|
+
JSON.stringify(pathToFileURL(args.path).href)
|
|
105
|
+
)
|
|
106
|
+
.replace(
|
|
107
|
+
/\b__dirname\b/g,
|
|
108
|
+
JSON.stringify(path.dirname(args.path))
|
|
109
|
+
)
|
|
110
|
+
.replace(/\b__filename\b/g, JSON.stringify(args.path))
|
|
111
|
+
}
|
|
112
|
+
})
|
|
113
|
+
}
|
|
114
|
+
}
|
|
115
|
+
]
|
|
116
|
+
})
|
|
117
|
+
const { text } = result.outputFiles[0]
|
|
118
|
+
return {
|
|
119
|
+
code: text,
|
|
120
|
+
dependencies: result.metafile ? Object.keys(result.metafile.inputs) : []
|
|
121
|
+
}
|
|
122
|
+
}
|
|
123
|
+
|
|
35
124
|
export const baseConfig = async ({
|
|
36
125
|
ssr,
|
|
37
126
|
appDir,
|
|
@@ -41,7 +130,7 @@ export const baseConfig = async ({
|
|
|
41
130
|
framework = 'vue',
|
|
42
131
|
pwa = false
|
|
43
132
|
}: {
|
|
44
|
-
ssr?: 'client' | 'server' | 'ssg'
|
|
133
|
+
ssr?: 'client' | 'server' | 'ssg' | 'fastify'
|
|
45
134
|
appDir?: URL
|
|
46
135
|
publicDir?: URL
|
|
47
136
|
command?: 'build' | 'dev' | 'test'
|
|
@@ -59,22 +148,7 @@ export const baseConfig = async ({
|
|
|
59
148
|
const cliDir = getCliDir()
|
|
60
149
|
const cliViteDir = getCliViteDir(cliDir)
|
|
61
150
|
const frameworkDir = new URL(`${framework}/`, cliViteDir)
|
|
62
|
-
|
|
63
|
-
const localPackages = ['vue', 'vue-router']
|
|
64
|
-
const cliPackages = ['vitest']
|
|
65
|
-
const packageUrls: Record<string, URL> = {}
|
|
66
|
-
await (async () => {
|
|
67
|
-
for (const val of localPackages)
|
|
68
|
-
packageUrls[val] = getPkgJsonDir(
|
|
69
|
-
new URL(await resolve(val, appDir!.href))
|
|
70
|
-
)
|
|
71
|
-
})()
|
|
72
|
-
await (async () => {
|
|
73
|
-
for (const val of cliPackages)
|
|
74
|
-
packageUrls[val] = getPkgJsonDir(
|
|
75
|
-
new URL(await resolve(val, cliDir!.href))
|
|
76
|
-
)
|
|
77
|
-
})()
|
|
151
|
+
const fastifyDir = new URL('fastify/', cliViteDir)
|
|
78
152
|
|
|
79
153
|
if (!publicDir) publicDir = new URL('public/', appDir)
|
|
80
154
|
/**
|
|
@@ -82,24 +156,62 @@ export const baseConfig = async ({
|
|
|
82
156
|
*/
|
|
83
157
|
let vitrifyConfig:
|
|
84
158
|
| VitrifyConfig
|
|
85
|
-
| (({
|
|
159
|
+
| (({
|
|
160
|
+
mode,
|
|
161
|
+
command
|
|
162
|
+
}: {
|
|
163
|
+
mode: string
|
|
164
|
+
command: string
|
|
165
|
+
}) => Promise<VitrifyConfig> | VitrifyConfig)
|
|
86
166
|
|
|
87
167
|
try {
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
168
|
+
if (fs.existsSync(new URL('vitrify.config.ts', appDir).pathname)) {
|
|
169
|
+
const configPath = new URL('vitrify.config.ts', appDir).pathname
|
|
170
|
+
const bundledConfig = await bundleConfigFile(
|
|
171
|
+
new URL('vitrify.config.ts', appDir).pathname
|
|
172
|
+
)
|
|
173
|
+
fs.writeFileSync(configPath + '.js', bundledConfig.code)
|
|
174
|
+
vitrifyConfig = (await import(configPath + '.js')).default
|
|
175
|
+
// fs.unlinkSync(configPath + '.js')
|
|
176
|
+
} else {
|
|
177
|
+
vitrifyConfig = (
|
|
178
|
+
await import(new URL('vitrify.config.js', appDir).pathname)
|
|
179
|
+
).default
|
|
180
|
+
}
|
|
91
181
|
if (typeof vitrifyConfig === 'function')
|
|
92
|
-
vitrifyConfig = vitrifyConfig({ mode, command })
|
|
182
|
+
vitrifyConfig = await vitrifyConfig({ mode, command })
|
|
93
183
|
} catch (e) {
|
|
94
|
-
console.
|
|
95
|
-
console.log('No vitrify.config.js file found, using defaults')
|
|
184
|
+
console.log('No vitrify.config.(ts|js) file found, using defaults')
|
|
96
185
|
vitrifyConfig = {}
|
|
97
186
|
}
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
187
|
+
|
|
188
|
+
const localPackages = ['vue', 'vue-router']
|
|
189
|
+
const cliPackages = []
|
|
190
|
+
const packageUrls: Record<string, URL> =
|
|
191
|
+
vitrifyConfig.vitrify?.urls?.packages || {}
|
|
192
|
+
await (async () => {
|
|
193
|
+
for (const val of localPackages)
|
|
194
|
+
packageUrls[val] = getPkgJsonDir(
|
|
195
|
+
new URL(await resolve(val, appDir!.href))
|
|
196
|
+
)
|
|
197
|
+
})()
|
|
198
|
+
// await (async () => {
|
|
199
|
+
// for (const val of cliPackages)
|
|
200
|
+
// packageUrls[val] = getPkgJsonDir(
|
|
201
|
+
// new URL(await resolve(val, cliDir!.href))
|
|
202
|
+
// )
|
|
203
|
+
// })()
|
|
204
|
+
|
|
205
|
+
let productName = 'Product name'
|
|
206
|
+
try {
|
|
207
|
+
;({ productName } = JSON.parse(
|
|
208
|
+
readFileSync(new URL('package.json', appDir).pathname, {
|
|
209
|
+
encoding: 'utf-8'
|
|
210
|
+
})
|
|
211
|
+
))
|
|
212
|
+
} catch (e) {
|
|
213
|
+
console.error('package.json not found')
|
|
214
|
+
}
|
|
103
215
|
|
|
104
216
|
const ssrTransformCustomDir = () => {
|
|
105
217
|
return {
|
|
@@ -124,7 +236,7 @@ export const baseConfig = async ({
|
|
|
124
236
|
let onBootHooks: OnBootHook[]
|
|
125
237
|
let onRenderedHooks: OnRenderedHook[]
|
|
126
238
|
let onMountedHooks: OnMountedHook[]
|
|
127
|
-
let
|
|
239
|
+
let onSetupFiles: OnSetupFile[]
|
|
128
240
|
let globalCss: string[]
|
|
129
241
|
let staticImports: StaticImports
|
|
130
242
|
let sassVariables: Record<string, string>
|
|
@@ -132,6 +244,7 @@ export const baseConfig = async ({
|
|
|
132
244
|
|
|
133
245
|
const plugins: UserConfig['plugins'] = [
|
|
134
246
|
vuePlugin({
|
|
247
|
+
compiler: await import('vue/compiler-sfc'),
|
|
135
248
|
template: {
|
|
136
249
|
ssr: !!ssr,
|
|
137
250
|
compilerOptions: {
|
|
@@ -159,7 +272,7 @@ export const baseConfig = async ({
|
|
|
159
272
|
onBootHooks = config.vitrify?.hooks?.onBoot || []
|
|
160
273
|
onRenderedHooks = config.vitrify?.hooks?.onRendered || []
|
|
161
274
|
onMountedHooks = config.vitrify?.hooks?.onMounted || []
|
|
162
|
-
|
|
275
|
+
onSetupFiles = config?.vitrify?.hooks?.onSetup || []
|
|
163
276
|
globalCss = config.vitrify?.globalCss || []
|
|
164
277
|
staticImports = config.vitrify?.staticImports || {}
|
|
165
278
|
sassVariables = config.vitrify?.sass?.variables || {}
|
|
@@ -188,9 +301,17 @@ export const baseConfig = async ({
|
|
|
188
301
|
}
|
|
189
302
|
},
|
|
190
303
|
resolveId(id) {
|
|
191
|
-
if (VIRTUAL_MODULES.includes(id))
|
|
304
|
+
if (VIRTUAL_MODULES.includes(id))
|
|
305
|
+
return { id, moduleSideEffects: false }
|
|
192
306
|
return
|
|
193
307
|
},
|
|
308
|
+
transform: (code, id) => {
|
|
309
|
+
if (id.endsWith('main.ts') && id.includes('vitrify')) {
|
|
310
|
+
code =
|
|
311
|
+
`${globalCss.map((css) => `import '${css}'`).join('\n')}\n` + code
|
|
312
|
+
}
|
|
313
|
+
return code
|
|
314
|
+
},
|
|
194
315
|
load(id) {
|
|
195
316
|
if (id === 'virtual:vitrify-hooks') {
|
|
196
317
|
return `export const onBoot = [${onBootHooks
|
|
@@ -202,11 +323,27 @@ export const baseConfig = async ({
|
|
|
202
323
|
export const onRendered = [${onRenderedHooks
|
|
203
324
|
.map((fn) => `${String(fn)}`)
|
|
204
325
|
.join(', ')}]
|
|
205
|
-
export const onSetup = [
|
|
206
|
-
|
|
207
|
-
.
|
|
208
|
-
|
|
209
|
-
|
|
326
|
+
export const onSetup = []
|
|
327
|
+
${onSetupFiles
|
|
328
|
+
.map(
|
|
329
|
+
(url, index) =>
|
|
330
|
+
`import ${url.pathname
|
|
331
|
+
.replaceAll('/', '')
|
|
332
|
+
.replaceAll('.', '')} from '${
|
|
333
|
+
url.pathname
|
|
334
|
+
}'; onSetup.push(${url.pathname
|
|
335
|
+
.replaceAll('/', '')
|
|
336
|
+
.replaceAll('.', '')})`
|
|
337
|
+
)
|
|
338
|
+
.join('\n')}`
|
|
339
|
+
// export const onSetup = [${onSetupHooks
|
|
340
|
+
// .map((fn) => `${String(fn)}`)
|
|
341
|
+
// .join(', ')}]`
|
|
342
|
+
/**
|
|
343
|
+
* CSS imports in virtual files do not seem to work. Using transform() instead
|
|
344
|
+
*/
|
|
345
|
+
// } else if (id === 'virtual:global-css') {
|
|
346
|
+
// return `${globalCss.map((css) => `import '${css}'`).join('\n')}`
|
|
210
347
|
} else if (id === 'virtual:static-imports') {
|
|
211
348
|
return `${Object.entries(staticImports)
|
|
212
349
|
.map(
|
|
@@ -242,6 +379,9 @@ export const baseConfig = async ({
|
|
|
242
379
|
case 'client':
|
|
243
380
|
entry = new URL('ssr/entry-client.ts', frameworkDir).pathname
|
|
244
381
|
break
|
|
382
|
+
case 'fastify':
|
|
383
|
+
entry = new URL('entry.ts', fastifyDir).pathname
|
|
384
|
+
break
|
|
245
385
|
default:
|
|
246
386
|
entry = new URL('csr/entry.ts', frameworkDir).pathname
|
|
247
387
|
}
|
|
@@ -277,19 +417,87 @@ export const baseConfig = async ({
|
|
|
277
417
|
{ find: 'cwd', replacement: cwd.pathname },
|
|
278
418
|
{ find: 'boot', replacement: new URL('boot/', srcDir).pathname },
|
|
279
419
|
{ find: 'assets', replacement: new URL('assets/', srcDir).pathname },
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
420
|
+
...Object.entries(packageUrls).map(([key, value]) => ({
|
|
421
|
+
find: key,
|
|
422
|
+
replacement: value.pathname
|
|
423
|
+
}))
|
|
424
|
+
// { find: 'vue', replacement: packageUrls['vue'].pathname },
|
|
425
|
+
// { find: 'vue-router', replacement: packageUrls['vue-router'].pathname },
|
|
426
|
+
// { find: 'vitrify', replacement: cliDir.pathname }
|
|
283
427
|
]
|
|
284
428
|
if (command === 'test')
|
|
285
429
|
alias.push({
|
|
286
430
|
find: 'vitest',
|
|
287
|
-
replacement:
|
|
431
|
+
replacement: new URL(await resolve('vitest', cliDir!.href)).pathname
|
|
288
432
|
})
|
|
289
433
|
|
|
434
|
+
let rollupOptions: RollupOptions
|
|
435
|
+
let noExternal: RegExp[] | string[] = []
|
|
436
|
+
const external = [...builtinModules, ...serverModules]
|
|
437
|
+
if (ssr === 'server') {
|
|
438
|
+
rollupOptions = {
|
|
439
|
+
input: [
|
|
440
|
+
new URL('ssr/entry-server.ts', frameworkDir).pathname,
|
|
441
|
+
new URL('ssr/prerender.ts', frameworkDir).pathname,
|
|
442
|
+
new URL('ssr/server.ts', frameworkDir).pathname
|
|
443
|
+
],
|
|
444
|
+
external,
|
|
445
|
+
output: {
|
|
446
|
+
minifyInternalExports: false,
|
|
447
|
+
entryFileNames: '[name].mjs',
|
|
448
|
+
chunkFileNames: '[name].mjs',
|
|
449
|
+
// format: 'es',
|
|
450
|
+
manualChunks: (id) => {
|
|
451
|
+
if (id.includes('vitrify/src/vite/')) {
|
|
452
|
+
const name = id.split('/').at(-1)?.split('.').at(0)
|
|
453
|
+
if (name && manualChunks.includes(name)) return name
|
|
454
|
+
} else if (id.includes('node_modules')) {
|
|
455
|
+
return 'vendor'
|
|
456
|
+
}
|
|
457
|
+
}
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
// Create a SSR bundle
|
|
461
|
+
noExternal = [
|
|
462
|
+
new RegExp(`^(?!(${[...builtinModules, ...serverModules].join('|')}))`)
|
|
463
|
+
// new RegExp(`^(?!.*(${[...builtinModules, ...serverModules].join('|')}))`)
|
|
464
|
+
]
|
|
465
|
+
} else if (ssr === 'fastify') {
|
|
466
|
+
rollupOptions = {
|
|
467
|
+
input: [new URL('server.ts', fastifyDir).pathname],
|
|
468
|
+
external,
|
|
469
|
+
output: {
|
|
470
|
+
minifyInternalExports: false,
|
|
471
|
+
entryFileNames: '[name].mjs',
|
|
472
|
+
chunkFileNames: '[name].mjs',
|
|
473
|
+
// format: 'es',
|
|
474
|
+
manualChunks: (id) => {
|
|
475
|
+
if (id.includes('vitrify/src/vite/')) {
|
|
476
|
+
const name = id.split('/').at(-1)?.split('.').at(0)
|
|
477
|
+
if (name && manualChunks.includes(name)) return name
|
|
478
|
+
} else if (id.includes('node_modules')) {
|
|
479
|
+
return 'vendor'
|
|
480
|
+
}
|
|
481
|
+
}
|
|
482
|
+
}
|
|
483
|
+
}
|
|
484
|
+
// Create a SSR bundle
|
|
485
|
+
noExternal = [
|
|
486
|
+
new RegExp(`^(?!(${[...builtinModules, ...serverModules].join('|')}))`)
|
|
487
|
+
]
|
|
488
|
+
} else {
|
|
489
|
+
rollupOptions = {
|
|
490
|
+
// input: [new URL('index.html', frameworkDir).pathname],
|
|
491
|
+
// output: {
|
|
492
|
+
// format: 'es'
|
|
493
|
+
// }
|
|
494
|
+
}
|
|
495
|
+
}
|
|
496
|
+
|
|
290
497
|
const config = {
|
|
291
|
-
root: frameworkDir.pathname,
|
|
498
|
+
root: ssr === 'fastify' ? appDir.pathname : frameworkDir.pathname,
|
|
292
499
|
publicDir: publicDir.pathname,
|
|
500
|
+
envDir: appDir.pathname,
|
|
293
501
|
vitrify: {
|
|
294
502
|
productName,
|
|
295
503
|
urls: {
|
|
@@ -302,7 +510,7 @@ export const baseConfig = async ({
|
|
|
302
510
|
},
|
|
303
511
|
plugins,
|
|
304
512
|
optimizeDeps: {
|
|
305
|
-
exclude: ['vue']
|
|
513
|
+
exclude: ['vue', ...serverModules, ...builtinModules]
|
|
306
514
|
},
|
|
307
515
|
resolve: {
|
|
308
516
|
// Dedupe uses require which breaks ESM SSR builds
|
|
@@ -313,46 +521,42 @@ export const baseConfig = async ({
|
|
|
313
521
|
alias
|
|
314
522
|
},
|
|
315
523
|
build: {
|
|
316
|
-
target: ssr === 'server' ? 'esnext' : 'modules',
|
|
317
|
-
ssr: ssr === 'server' ? true : false,
|
|
524
|
+
target: ssr === 'server' || ssr === 'fastify' ? 'esnext' : 'modules',
|
|
525
|
+
ssr: ssr === 'server' || ssr === 'fastify' ? true : false,
|
|
318
526
|
ssrManifest: ssr === 'client' || ssr === 'ssg',
|
|
319
|
-
rollupOptions
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
}
|
|
527
|
+
rollupOptions
|
|
528
|
+
// ssr === 'server'
|
|
529
|
+
// ? {
|
|
530
|
+
// input: [
|
|
531
|
+
// new URL('ssr/entry-server.ts', frameworkDir).pathname,
|
|
532
|
+
// new URL('ssr/prerender.ts', frameworkDir).pathname,
|
|
533
|
+
// new URL('ssr/server.ts', frameworkDir).pathname
|
|
534
|
+
// ],
|
|
535
|
+
// output: {
|
|
536
|
+
// minifyInternalExports: false,
|
|
537
|
+
// entryFileNames: '[name].mjs',
|
|
538
|
+
// chunkFileNames: '[name].mjs',
|
|
539
|
+
// format: 'es',
|
|
540
|
+
// manualChunks: (id) => {
|
|
541
|
+
// if (id.includes('vitrify/src/vite/')) {
|
|
542
|
+
// const name = id.split('/').at(-1)?.split('.').at(0)
|
|
543
|
+
// if (name && manualChunks.includes(name)) return name
|
|
544
|
+
// } else if (id.includes('node_modules')) {
|
|
545
|
+
// return 'vendor'
|
|
546
|
+
// }
|
|
547
|
+
// }
|
|
548
|
+
// }
|
|
549
|
+
// }
|
|
550
|
+
// : {
|
|
551
|
+
// output: {
|
|
552
|
+
// format: 'es'
|
|
553
|
+
// }
|
|
554
|
+
// }
|
|
348
555
|
},
|
|
349
556
|
ssr: {
|
|
350
557
|
// Create a SSR bundle
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
`^(?!.*(${[...builtinModules, ...serverModules].join('|')}))`
|
|
354
|
-
)
|
|
355
|
-
]
|
|
558
|
+
external,
|
|
559
|
+
noExternal
|
|
356
560
|
},
|
|
357
561
|
define: {
|
|
358
562
|
__BASE_URL__: `'/'`
|
|
@@ -121,7 +121,7 @@ export const QuasarPlugin: VitrifyPlugin = async ({
|
|
|
121
121
|
const directives = await import('quasar/src/directives.js')
|
|
122
122
|
|
|
123
123
|
app.use(
|
|
124
|
-
staticImports
|
|
124
|
+
staticImports?.Quasar,
|
|
125
125
|
{
|
|
126
126
|
plugins: quasarPlugins,
|
|
127
127
|
directives
|
|
@@ -221,9 +221,14 @@ export const QuasarPlugin: VitrifyPlugin = async ({
|
|
|
221
221
|
replacement: new URL('src/', urls?.packages?.quasar).pathname
|
|
222
222
|
},
|
|
223
223
|
{
|
|
224
|
-
find: 'quasar',
|
|
225
|
-
replacement: new URL('src/', urls?.packages?.quasar)
|
|
224
|
+
find: new RegExp('^quasar$'),
|
|
225
|
+
replacement: new URL('src/index.all.js', urls?.packages?.quasar)
|
|
226
|
+
.pathname
|
|
226
227
|
},
|
|
228
|
+
// {
|
|
229
|
+
// find: 'quasar',
|
|
230
|
+
// replacement: new URL('src/index.all.js', urls?.packages?.quasar).pathname
|
|
231
|
+
// },
|
|
227
232
|
{
|
|
228
233
|
find: `@quasar/extras`,
|
|
229
234
|
replacement: new URL('.', urls?.packages?.['@quasar/extras'])
|
|
@@ -251,7 +256,7 @@ export const QuasarPlugin: VitrifyPlugin = async ({
|
|
|
251
256
|
config: async (config, env) => ({
|
|
252
257
|
resolve: {
|
|
253
258
|
alias: [
|
|
254
|
-
{ find: new RegExp('^quasar$'), replacement: 'virtual:quasar' }
|
|
259
|
+
// { find: new RegExp('^quasar$'), replacement: 'virtual:quasar' }
|
|
255
260
|
]
|
|
256
261
|
}
|
|
257
262
|
}),
|
|
@@ -19,7 +19,7 @@ export type OnBootHook = ({
|
|
|
19
19
|
}: {
|
|
20
20
|
app: any
|
|
21
21
|
ssrContext: Record<string, unknown>
|
|
22
|
-
staticImports
|
|
22
|
+
staticImports?: Record<string, any>
|
|
23
23
|
}) => Promise<void> | void
|
|
24
24
|
export type OnMountedHook = (
|
|
25
25
|
instance: ComponentInternalInstance
|
|
@@ -33,8 +33,11 @@ export type OnRenderedHook = (
|
|
|
33
33
|
html: string,
|
|
34
34
|
ssrContext: Record<string, any>
|
|
35
35
|
) => string
|
|
36
|
-
export type OnSetupHook = (
|
|
37
|
-
|
|
36
|
+
// export type OnSetupHook = (
|
|
37
|
+
// fastify: FastifyInstance,
|
|
38
|
+
// staticImports?: Record<string, any>
|
|
39
|
+
// ) => any
|
|
40
|
+
export type OnSetupFile = URL
|
|
38
41
|
export interface VitrifyConfig extends UserConfig {
|
|
39
42
|
vitrify?: {
|
|
40
43
|
/**
|
|
@@ -49,7 +52,7 @@ export interface VitrifyConfig extends UserConfig {
|
|
|
49
52
|
/**
|
|
50
53
|
* setup() is called directly after instantiating fastify. Use it to register your own plugins, routes etc.
|
|
51
54
|
*/
|
|
52
|
-
onSetup?:
|
|
55
|
+
onSetup?: OnSetupFile[]
|
|
53
56
|
/**
|
|
54
57
|
* Functions which run in the onMounted hook of the app
|
|
55
58
|
*/
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FastifyInstance } from 'fastify'
|
|
2
|
+
import { onSetup } from 'virtual:vitrify-hooks'
|
|
3
|
+
|
|
4
|
+
export const setup = async ({ fastify }: { fastify: FastifyInstance }) => {
|
|
5
|
+
if (onSetup?.length) {
|
|
6
|
+
for (const setup of onSetup) {
|
|
7
|
+
await setup(fastify)
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
return fastify
|
|
11
|
+
}
|
package/src/vite/vue/index.html
CHANGED
package/src/vite/vue/main.ts
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
1
|
+
import { createApp } from '../../../node/frameworks/vue/server.js'
|
|
2
|
+
import { getAppDir } from '../../../node/app-urls.js'
|
|
3
|
+
// import { setup } from 'virtual:fastify-setup'
|
|
4
|
+
import { onRendered, onSetup } from 'virtual:vitrify-hooks'
|
|
5
|
+
import { fastifySsrPlugin } from './fastify-ssr-plugin.js'
|
|
6
|
+
import type { ViteDevServer } from 'vite'
|
|
7
|
+
import * as imr from 'import-meta-resolve'
|
|
8
|
+
const { resolve } = imr
|
|
9
|
+
// const appDir = getPkgJsonDir(import.meta.url)
|
|
10
|
+
const getString = (str?: string) => str
|
|
11
|
+
let baseUrl = getString(__BASE_URL__)
|
|
12
|
+
const appDir = getAppDir()
|
|
13
|
+
|
|
14
|
+
export const setupApp = async () => {
|
|
15
|
+
const vitrifyDir = new URL('../', await resolve('vitrify', import.meta.url))
|
|
16
|
+
return createApp({
|
|
17
|
+
onSetup,
|
|
18
|
+
appDir,
|
|
19
|
+
baseUrl,
|
|
20
|
+
onRendered,
|
|
21
|
+
fastifySsrPlugin,
|
|
22
|
+
vitrifyDir,
|
|
23
|
+
mode: import.meta.env.MODE
|
|
24
|
+
})
|
|
25
|
+
}
|
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import { createApp } from '../main.js'
|
|
2
|
-
import { renderToString } from '
|
|
2
|
+
import { renderToString } from 'vue/server-renderer'
|
|
3
|
+
import type { FastifyInstance } from 'fastify'
|
|
3
4
|
// import * as ApolloSSR from '@vue/apollo-ssr'
|
|
4
5
|
// import { ApolloClients } from '@vue/apollo-composable'
|
|
5
6
|
// import serialize from 'serialize-javascript'
|
|
6
7
|
|
|
8
|
+
import { onSetup } from 'virtual:vitrify-hooks'
|
|
9
|
+
|
|
10
|
+
export const setup = async ({ fastify }: { fastify: FastifyInstance }) => {
|
|
11
|
+
if (onSetup?.length) {
|
|
12
|
+
for (const setup of onSetup) {
|
|
13
|
+
await setup(fastify)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return fastify
|
|
17
|
+
}
|
|
18
|
+
|
|
7
19
|
const initializeApp = async (url, ssrContext) => {
|
|
8
20
|
const onRenderedList = []
|
|
9
21
|
Object.assign(ssrContext, {
|