vitrify 0.11.2 → 0.11.4
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/frameworks/vue/fastify-csr-plugin.js +1 -0
- package/dist/frameworks/vue/fastify-ssr-plugin.js +1 -0
- package/dist/index.js +52 -21
- package/dist/types/frameworks/vue/fastify-csr-plugin.d.ts +1 -1
- package/dist/types/frameworks/vue/fastify-ssr-plugin.d.ts +1 -1
- package/dist/types/plugins/index.d.ts +1 -1
- package/dist/types/vitrify-config.d.ts +12 -8
- package/package.json +1 -2
- package/src/node/frameworks/vue/fastify-csr-plugin.ts +1 -0
- package/src/node/frameworks/vue/fastify-ssr-plugin.ts +1 -0
- package/src/node/index.ts +51 -21
- package/src/node/vitrify-config.ts +4 -0
|
@@ -20,6 +20,7 @@ const fastifyCsrPlugin = async (fastify, options, done) => {
|
|
|
20
20
|
console.log('Dev mode');
|
|
21
21
|
if (!('use' in fastify)) {
|
|
22
22
|
const middie = (await import('@fastify/middie')).default;
|
|
23
|
+
// @ts-ignore
|
|
23
24
|
await fastify.register(middie);
|
|
24
25
|
}
|
|
25
26
|
fastify.use(vite.middlewares);
|
package/dist/index.js
CHANGED
|
@@ -9,7 +9,6 @@ import { readFileSync } from 'fs';
|
|
|
9
9
|
import builtinModules from 'builtin-modules';
|
|
10
10
|
import { visualizer } from 'rollup-plugin-visualizer';
|
|
11
11
|
import { resolve } from './app-urls.js';
|
|
12
|
-
import envPlugin from '@vitrify/plugin-env';
|
|
13
12
|
import { addOrReplaceTitle, appendToBody } from './helpers/utils.js';
|
|
14
13
|
import Components from 'unplugin-vue-components/vite';
|
|
15
14
|
const internalServerModules = [
|
|
@@ -43,23 +42,52 @@ const moduleChunks = {
|
|
|
43
42
|
vue: ['vue', '@vue', 'vue-router'],
|
|
44
43
|
quasar: ['quasar', '@quasar']
|
|
45
44
|
};
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
else if (VIRTUAL_MODULES.some((virtualModule) => id.includes(virtualModule))) {
|
|
54
|
-
return VIRTUAL_MODULES.find((name) => id.includes(name));
|
|
55
|
-
}
|
|
56
|
-
else if (id.includes('node_modules')) {
|
|
57
|
-
if (matchedModule) {
|
|
58
|
-
return matchedModule[0];
|
|
45
|
+
const manualChunksFn = (manualChunkList) => {
|
|
46
|
+
return (id) => {
|
|
47
|
+
const matchedModule = Object.entries(moduleChunks).find(([chunkName, moduleNames]) => moduleNames.some((moduleName) => id.includes(moduleName + '/')));
|
|
48
|
+
if (id.includes('vitrify/src/')) {
|
|
49
|
+
const name = id.split('/').at(-1)?.split('.').at(0);
|
|
50
|
+
if (name && manualChunkNames.includes(name))
|
|
51
|
+
return name;
|
|
59
52
|
}
|
|
60
|
-
|
|
61
|
-
|
|
53
|
+
else if (VIRTUAL_MODULES.some((virtualModule) => id.includes(virtualModule))) {
|
|
54
|
+
return VIRTUAL_MODULES.find((name) => id.includes(name));
|
|
55
|
+
}
|
|
56
|
+
else if (manualChunkList?.some((file) => id.includes(file))) {
|
|
57
|
+
return manualChunkList.find((file) => id.includes(file));
|
|
58
|
+
}
|
|
59
|
+
else if (id.includes('node_modules')) {
|
|
60
|
+
if (matchedModule) {
|
|
61
|
+
return matchedModule[0];
|
|
62
|
+
}
|
|
63
|
+
return 'vendor';
|
|
64
|
+
}
|
|
65
|
+
};
|
|
62
66
|
};
|
|
67
|
+
// const manualChunks: ManualChunksOption = (
|
|
68
|
+
// id: string,
|
|
69
|
+
// manualChunkList?: string[]
|
|
70
|
+
// ) => {
|
|
71
|
+
// const matchedModule = Object.entries(moduleChunks).find(
|
|
72
|
+
// ([chunkName, moduleNames]) =>
|
|
73
|
+
// moduleNames.some((moduleName) => id.includes(moduleName + '/'))
|
|
74
|
+
// )
|
|
75
|
+
// if (id.includes('vitrify/src/')) {
|
|
76
|
+
// const name = id.split('/').at(-1)?.split('.').at(0)
|
|
77
|
+
// if (name && manualChunkNames.includes(name)) return name
|
|
78
|
+
// } else if (
|
|
79
|
+
// VIRTUAL_MODULES.some((virtualModule) => id.includes(virtualModule))
|
|
80
|
+
// ) {
|
|
81
|
+
// return VIRTUAL_MODULES.find((name) => id.includes(name))
|
|
82
|
+
// } else if (manualChunkList?.some((file) => id.includes(file))) {
|
|
83
|
+
// return manualChunkList.find((file) => id.includes(file))
|
|
84
|
+
// } else if (id.includes('node_modules')) {
|
|
85
|
+
// if (matchedModule) {
|
|
86
|
+
// return matchedModule[0]
|
|
87
|
+
// }
|
|
88
|
+
// return 'vendor'
|
|
89
|
+
// }
|
|
90
|
+
// }
|
|
63
91
|
export const VIRTUAL_MODULES = [
|
|
64
92
|
'virtual:vitrify-hooks',
|
|
65
93
|
'virtual:static-imports',
|
|
@@ -175,6 +203,8 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
175
203
|
({ productName } = JSON.parse(readFileSync(new URL('package.json', appDir).pathname, {
|
|
176
204
|
encoding: 'utf-8'
|
|
177
205
|
})));
|
|
206
|
+
if (!productName)
|
|
207
|
+
productName = vitrifyConfig.vitrify?.productName;
|
|
178
208
|
}
|
|
179
209
|
catch (e) {
|
|
180
210
|
console.error('package.json not found');
|
|
@@ -237,7 +267,6 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
237
267
|
}
|
|
238
268
|
},
|
|
239
269
|
vuePlugin(),
|
|
240
|
-
envPlugin(),
|
|
241
270
|
...frameworkPlugins,
|
|
242
271
|
{
|
|
243
272
|
name: 'vitrify-setup',
|
|
@@ -306,7 +335,9 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
306
335
|
const varName = url.pathname
|
|
307
336
|
.replaceAll('/', '')
|
|
308
337
|
.replaceAll('.', '')
|
|
309
|
-
.replaceAll('-', '')
|
|
338
|
+
.replaceAll('-', '')
|
|
339
|
+
.replaceAll('_', '')
|
|
340
|
+
.replaceAll('+', '');
|
|
310
341
|
return `import ${varName} from '${url.pathname}'; onSetup.push(${varName})`;
|
|
311
342
|
})
|
|
312
343
|
.join('\n')}`;
|
|
@@ -448,7 +479,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
448
479
|
entryFileNames: '[name].mjs',
|
|
449
480
|
chunkFileNames: '[name].mjs',
|
|
450
481
|
format: 'es',
|
|
451
|
-
manualChunks
|
|
482
|
+
manualChunks: manualChunksFn(vitrifyConfig?.vitrify?.manualChunks)
|
|
452
483
|
}
|
|
453
484
|
};
|
|
454
485
|
// Create a SSR bundle
|
|
@@ -466,7 +497,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
466
497
|
entryFileNames: '[name].mjs',
|
|
467
498
|
chunkFileNames: '[name].mjs',
|
|
468
499
|
format: 'es',
|
|
469
|
-
manualChunks
|
|
500
|
+
manualChunks: manualChunksFn(vitrifyConfig?.vitrify?.manualChunks)
|
|
470
501
|
}
|
|
471
502
|
};
|
|
472
503
|
// Create a SSR bundle
|
|
@@ -483,7 +514,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command =
|
|
|
483
514
|
entryFileNames: '[name].mjs',
|
|
484
515
|
chunkFileNames: '[name].mjs',
|
|
485
516
|
format: 'es',
|
|
486
|
-
manualChunks
|
|
517
|
+
manualChunks: manualChunksFn(vitrifyConfig?.vitrify?.manualChunks)
|
|
487
518
|
}
|
|
488
519
|
};
|
|
489
520
|
}
|
|
@@ -12,4 +12,4 @@ export interface FastifySsrOptions {
|
|
|
12
12
|
}
|
|
13
13
|
declare const fastifyCsrPlugin: FastifyPluginCallback<FastifySsrOptions>;
|
|
14
14
|
export { fastifyCsrPlugin };
|
|
15
|
-
export
|
|
15
|
+
export type FastifyCsrPlugin = typeof fastifyCsrPlugin;
|
|
@@ -16,4 +16,4 @@ export interface FastifySsrOptions {
|
|
|
16
16
|
}
|
|
17
17
|
declare const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions>;
|
|
18
18
|
export { fastifySsrPlugin };
|
|
19
|
-
export
|
|
19
|
+
export type FastifySsrPlugin = typeof fastifySsrPlugin;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Plugin } from 'vite';
|
|
2
|
-
export
|
|
2
|
+
export type VitrifyPlugin = ({ ssr, mode, command }: {
|
|
3
3
|
ssr?: 'server' | 'client' | 'ssg' | 'fastify' | false;
|
|
4
4
|
pwa?: boolean;
|
|
5
5
|
mode?: 'production' | 'development';
|
|
@@ -2,21 +2,21 @@ import type { Alias, UserConfig } from 'vite';
|
|
|
2
2
|
import type { QuasarConf } from './plugins/quasar.js';
|
|
3
3
|
import type { ComponentInternalInstance } from '@vue/runtime-core';
|
|
4
4
|
import type { FastifyServerOptions } from 'fastify';
|
|
5
|
-
export
|
|
5
|
+
export type BootFunction = ({ app, ssrContext, staticImports }: {
|
|
6
6
|
app: any;
|
|
7
7
|
ssrContext: Record<string, unknown>;
|
|
8
8
|
staticImports: Record<string, any>;
|
|
9
9
|
}) => Promise<void> | void;
|
|
10
|
-
export
|
|
10
|
+
export type OnBootHook = ({ app, ssrContext, staticImports }: {
|
|
11
11
|
app: any;
|
|
12
12
|
ssrContext: Record<string, unknown>;
|
|
13
13
|
staticImports?: Record<string, any>;
|
|
14
14
|
}) => Promise<void> | void;
|
|
15
|
-
export
|
|
16
|
-
export
|
|
17
|
-
export
|
|
18
|
-
export
|
|
19
|
-
export
|
|
15
|
+
export type OnMountedHook = (instance: ComponentInternalInstance) => Promise<void> | void;
|
|
16
|
+
export type StaticImports = Record<string, string[]>;
|
|
17
|
+
export type SsrFunction = (html: string, ssrContext: Record<string, any>) => string;
|
|
18
|
+
export type OnRenderedHook = (html: string, ssrContext: Record<string, any>) => string;
|
|
19
|
+
export type OnSetupFile = URL;
|
|
20
20
|
export interface VitrifyConfig extends UserConfig {
|
|
21
21
|
vitrify?: {
|
|
22
22
|
lang?: string;
|
|
@@ -81,8 +81,12 @@ export interface VitrifyConfig extends UserConfig {
|
|
|
81
81
|
dev?: {
|
|
82
82
|
alias?: Alias[];
|
|
83
83
|
};
|
|
84
|
+
/**
|
|
85
|
+
* Files which should be a seperate chunk
|
|
86
|
+
*/
|
|
87
|
+
manualChunks?: string[];
|
|
84
88
|
};
|
|
85
89
|
quasar?: QuasarConf;
|
|
86
90
|
}
|
|
87
|
-
export
|
|
91
|
+
export type VitrifyConfigAsync = VitrifyConfig | ((mode: string, command: string) => Promise<VitrifyConfig>);
|
|
88
92
|
export declare const defineConfig: (config: VitrifyConfig) => VitrifyConfig;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "vitrify",
|
|
3
|
-
"version": "0.11.
|
|
3
|
+
"version": "0.11.4",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"author": "Stefan van Herwijnen",
|
|
6
6
|
"description": "Vite as your Full Stack development tool",
|
|
@@ -52,7 +52,6 @@
|
|
|
52
52
|
"@fastify/static": "^6.5.0",
|
|
53
53
|
"@quasar/extras": "^1.15.2",
|
|
54
54
|
"@vitejs/plugin-vue": "^3.1.0",
|
|
55
|
-
"@vitrify/plugin-env": "^0.1.1",
|
|
56
55
|
"builtin-modules": "^3.3.0",
|
|
57
56
|
"cac": "^6.7.14",
|
|
58
57
|
"chalk": "^5.0.1",
|
|
@@ -51,6 +51,7 @@ const fastifyCsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
|
|
|
51
51
|
console.log('Dev mode')
|
|
52
52
|
if (!('use' in fastify)) {
|
|
53
53
|
const middie = (await import('@fastify/middie')).default
|
|
54
|
+
// @ts-ignore
|
|
54
55
|
await fastify.register(middie)
|
|
55
56
|
}
|
|
56
57
|
fastify.use(vite.middlewares)
|
|
@@ -98,6 +98,7 @@ const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (
|
|
|
98
98
|
|
|
99
99
|
if (!('use' in fastify)) {
|
|
100
100
|
const middie = (await import('@fastify/middie')).default
|
|
101
|
+
// @ts-ignore
|
|
101
102
|
await fastify.register(middie)
|
|
102
103
|
}
|
|
103
104
|
fastify.use(vite.middlewares)
|
package/src/node/index.ts
CHANGED
|
@@ -22,7 +22,6 @@ import type { VitrifyContext } from './bin/run.js'
|
|
|
22
22
|
import type { VitrifyPlugin } from './plugins/index.js'
|
|
23
23
|
import { resolve } from './app-urls.js'
|
|
24
24
|
import type { ManualChunksOption, RollupOptions } from 'rollup'
|
|
25
|
-
import envPlugin from '@vitrify/plugin-env'
|
|
26
25
|
import { addOrReplaceTitle, appendToBody } from './helpers/utils.js'
|
|
27
26
|
import type { ComponentResolver } from 'unplugin-vue-components'
|
|
28
27
|
import Components from 'unplugin-vue-components/vite'
|
|
@@ -69,26 +68,55 @@ const moduleChunks = {
|
|
|
69
68
|
vue: ['vue', '@vue', 'vue-router'],
|
|
70
69
|
quasar: ['quasar', '@quasar']
|
|
71
70
|
}
|
|
72
|
-
const
|
|
73
|
-
|
|
74
|
-
(
|
|
75
|
-
moduleNames
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
if (
|
|
86
|
-
return
|
|
71
|
+
const manualChunksFn = (manualChunkList?: string[]): ManualChunksOption => {
|
|
72
|
+
return (id: string) => {
|
|
73
|
+
const matchedModule = Object.entries(moduleChunks).find(
|
|
74
|
+
([chunkName, moduleNames]) =>
|
|
75
|
+
moduleNames.some((moduleName) => id.includes(moduleName + '/'))
|
|
76
|
+
)
|
|
77
|
+
if (id.includes('vitrify/src/')) {
|
|
78
|
+
const name = id.split('/').at(-1)?.split('.').at(0)
|
|
79
|
+
if (name && manualChunkNames.includes(name)) return name
|
|
80
|
+
} else if (
|
|
81
|
+
VIRTUAL_MODULES.some((virtualModule) => id.includes(virtualModule))
|
|
82
|
+
) {
|
|
83
|
+
return VIRTUAL_MODULES.find((name) => id.includes(name))
|
|
84
|
+
} else if (manualChunkList?.some((file) => id.includes(file))) {
|
|
85
|
+
return manualChunkList.find((file) => id.includes(file))
|
|
86
|
+
} else if (id.includes('node_modules')) {
|
|
87
|
+
if (matchedModule) {
|
|
88
|
+
return matchedModule[0]
|
|
89
|
+
}
|
|
90
|
+
return 'vendor'
|
|
87
91
|
}
|
|
88
|
-
return 'vendor'
|
|
89
92
|
}
|
|
90
93
|
}
|
|
91
94
|
|
|
95
|
+
// const manualChunks: ManualChunksOption = (
|
|
96
|
+
// id: string,
|
|
97
|
+
// manualChunkList?: string[]
|
|
98
|
+
// ) => {
|
|
99
|
+
// const matchedModule = Object.entries(moduleChunks).find(
|
|
100
|
+
// ([chunkName, moduleNames]) =>
|
|
101
|
+
// moduleNames.some((moduleName) => id.includes(moduleName + '/'))
|
|
102
|
+
// )
|
|
103
|
+
// if (id.includes('vitrify/src/')) {
|
|
104
|
+
// const name = id.split('/').at(-1)?.split('.').at(0)
|
|
105
|
+
// if (name && manualChunkNames.includes(name)) return name
|
|
106
|
+
// } else if (
|
|
107
|
+
// VIRTUAL_MODULES.some((virtualModule) => id.includes(virtualModule))
|
|
108
|
+
// ) {
|
|
109
|
+
// return VIRTUAL_MODULES.find((name) => id.includes(name))
|
|
110
|
+
// } else if (manualChunkList?.some((file) => id.includes(file))) {
|
|
111
|
+
// return manualChunkList.find((file) => id.includes(file))
|
|
112
|
+
// } else if (id.includes('node_modules')) {
|
|
113
|
+
// if (matchedModule) {
|
|
114
|
+
// return matchedModule[0]
|
|
115
|
+
// }
|
|
116
|
+
// return 'vendor'
|
|
117
|
+
// }
|
|
118
|
+
// }
|
|
119
|
+
|
|
92
120
|
export const VIRTUAL_MODULES = [
|
|
93
121
|
'virtual:vitrify-hooks',
|
|
94
122
|
'virtual:static-imports',
|
|
@@ -252,6 +280,7 @@ export const baseConfig = async ({
|
|
|
252
280
|
encoding: 'utf-8'
|
|
253
281
|
})
|
|
254
282
|
))
|
|
283
|
+
if (!productName) productName = vitrifyConfig.vitrify?.productName
|
|
255
284
|
} catch (e) {
|
|
256
285
|
console.error('package.json not found')
|
|
257
286
|
productName = 'Product name'
|
|
@@ -324,7 +353,6 @@ export const baseConfig = async ({
|
|
|
324
353
|
}
|
|
325
354
|
},
|
|
326
355
|
vuePlugin(),
|
|
327
|
-
envPlugin(),
|
|
328
356
|
...frameworkPlugins,
|
|
329
357
|
{
|
|
330
358
|
name: 'vitrify-setup',
|
|
@@ -393,6 +421,8 @@ export const baseConfig = async ({
|
|
|
393
421
|
.replaceAll('/', '')
|
|
394
422
|
.replaceAll('.', '')
|
|
395
423
|
.replaceAll('-', '')
|
|
424
|
+
.replaceAll('_', '')
|
|
425
|
+
.replaceAll('+', '')
|
|
396
426
|
return `import ${varName} from '${url.pathname}'; onSetup.push(${varName})`
|
|
397
427
|
})
|
|
398
428
|
.join('\n')}`
|
|
@@ -546,7 +576,7 @@ export const baseConfig = async ({
|
|
|
546
576
|
entryFileNames: '[name].mjs',
|
|
547
577
|
chunkFileNames: '[name].mjs',
|
|
548
578
|
format: 'es',
|
|
549
|
-
manualChunks
|
|
579
|
+
manualChunks: manualChunksFn(vitrifyConfig?.vitrify?.manualChunks)
|
|
550
580
|
}
|
|
551
581
|
}
|
|
552
582
|
// Create a SSR bundle
|
|
@@ -563,7 +593,7 @@ export const baseConfig = async ({
|
|
|
563
593
|
entryFileNames: '[name].mjs',
|
|
564
594
|
chunkFileNames: '[name].mjs',
|
|
565
595
|
format: 'es',
|
|
566
|
-
manualChunks
|
|
596
|
+
manualChunks: manualChunksFn(vitrifyConfig?.vitrify?.manualChunks)
|
|
567
597
|
}
|
|
568
598
|
}
|
|
569
599
|
// Create a SSR bundle
|
|
@@ -579,7 +609,7 @@ export const baseConfig = async ({
|
|
|
579
609
|
entryFileNames: '[name].mjs',
|
|
580
610
|
chunkFileNames: '[name].mjs',
|
|
581
611
|
format: 'es',
|
|
582
|
-
manualChunks
|
|
612
|
+
manualChunks: manualChunksFn(vitrifyConfig?.vitrify?.manualChunks)
|
|
583
613
|
}
|
|
584
614
|
}
|
|
585
615
|
}
|