vitrify 0.3.0 → 0.5.1
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 +2 -2
- package/dist/app-urls.js +1 -1
- package/dist/bin/build.js +9 -8
- package/dist/bin/cli.js +28 -6
- package/dist/bin/dev.js +73 -29
- package/dist/frameworks/vue/fastify-csr-plugin.js +38 -0
- package/dist/frameworks/vue/fastify-ssr-plugin.js +83 -18
- package/dist/frameworks/vue/server.js +10 -5
- package/dist/helpers/collect-css-ssr.js +61 -0
- package/dist/index.js +298 -77
- package/dist/plugins/quasar.js +30 -9
- package/dist/types/bin/build.d.ts +2 -2
- package/dist/types/bin/dev.d.ts +43 -4
- package/dist/types/frameworks/vue/fastify-csr-plugin.d.ts +17 -0
- package/dist/types/frameworks/vue/fastify-ssr-plugin.d.ts +6 -3
- package/dist/types/frameworks/vue/server.d.ts +10 -5
- package/dist/types/helpers/collect-css-ssr.d.ts +14 -0
- package/dist/types/helpers/routes.d.ts +1 -1
- package/dist/types/index.d.ts +4 -2
- package/dist/types/plugins/index.d.ts +1 -1
- package/dist/types/vitrify-config.d.ts +16 -5
- package/package.json +33 -32
- package/src/node/app-urls.ts +1 -1
- package/src/node/bin/build.ts +11 -10
- package/src/node/bin/cli.ts +35 -7
- package/src/node/bin/dev.ts +109 -38
- package/src/node/frameworks/vue/fastify-csr-plugin.ts +72 -0
- package/src/node/frameworks/vue/fastify-ssr-plugin.ts +99 -20
- package/src/node/frameworks/vue/server.ts +24 -9
- package/src/node/helpers/collect-css-ssr.ts +85 -0
- package/src/node/index.ts +338 -90
- package/src/node/plugins/index.ts +1 -1
- package/src/node/plugins/quasar.ts +40 -9
- package/src/node/vitrify-config.ts +20 -5
- package/src/vite/fastify/entry.ts +11 -0
- package/src/vite/fastify/server.ts +12 -0
- package/src/vite/vue/csr/app.ts +25 -0
- package/src/vite/vue/csr/fastify-csr-plugin.ts +3 -0
- package/src/vite/vue/csr/server.ts +8 -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/dist/index.js
CHANGED
|
@@ -1,20 +1,118 @@
|
|
|
1
1
|
import vuePlugin from '@vitejs/plugin-vue';
|
|
2
2
|
import { mergeConfig } from 'vite';
|
|
3
|
+
import { build } from 'esbuild';
|
|
4
|
+
import fs from 'fs';
|
|
5
|
+
import path from 'path';
|
|
6
|
+
import { pathToFileURL } from 'url';
|
|
3
7
|
import { readFileSync } from 'fs';
|
|
4
8
|
import builtinModules from 'builtin-modules';
|
|
5
9
|
import { resolve } from 'import-meta-resolve';
|
|
6
10
|
import { getPkgJsonDir } from './app-urls.js';
|
|
7
|
-
const
|
|
11
|
+
const internalServerModules = [
|
|
12
|
+
// 'fs',
|
|
13
|
+
// 'path',
|
|
14
|
+
// 'url',
|
|
15
|
+
// 'module',
|
|
16
|
+
// 'crypto',
|
|
17
|
+
// 'node:fs',
|
|
18
|
+
'util',
|
|
19
|
+
'node:url',
|
|
20
|
+
'node:util',
|
|
21
|
+
'node:fs',
|
|
22
|
+
'node:process',
|
|
23
|
+
'vitrify',
|
|
24
|
+
'vitrify/dev',
|
|
25
|
+
// 'import-meta-resolve',
|
|
26
|
+
'vite',
|
|
27
|
+
'fastify',
|
|
28
|
+
'@fastify',
|
|
29
|
+
'node'
|
|
30
|
+
// 'middie',
|
|
31
|
+
// 'knex',
|
|
32
|
+
// 'bcrypt',
|
|
33
|
+
// 'objection',
|
|
34
|
+
// '@fastify/formbody',
|
|
35
|
+
// '@fastify/static',
|
|
36
|
+
// '@fastify/cors',
|
|
37
|
+
// '@fastify/cookie',
|
|
38
|
+
// 'mercurius',
|
|
39
|
+
// 'jose',
|
|
40
|
+
// 'oidc-provider',
|
|
41
|
+
// 'node-fetch'
|
|
42
|
+
];
|
|
8
43
|
const configPluginMap = {
|
|
9
44
|
quasar: () => import('./plugins/quasar.js').then((module) => module.QuasarPlugin)
|
|
10
45
|
};
|
|
11
|
-
const
|
|
46
|
+
const manualChunkNames = [
|
|
47
|
+
'prerender',
|
|
48
|
+
'fastify-ssr-plugin',
|
|
49
|
+
'fastify-csr-plugin',
|
|
50
|
+
'server'
|
|
51
|
+
];
|
|
52
|
+
const manualChunks = (id) => {
|
|
53
|
+
if (id.includes('vitrify/src/vite/')) {
|
|
54
|
+
const name = id.split('/').at(-1)?.split('.').at(0);
|
|
55
|
+
if (name && manualChunkNames.includes(name))
|
|
56
|
+
return name;
|
|
57
|
+
}
|
|
58
|
+
else if (id.includes('node_modules')) {
|
|
59
|
+
return 'vendor';
|
|
60
|
+
}
|
|
61
|
+
};
|
|
12
62
|
export const VIRTUAL_MODULES = [
|
|
13
63
|
'virtual:vitrify-hooks',
|
|
14
64
|
'virtual:global-css',
|
|
15
65
|
'virtual:static-imports'
|
|
16
66
|
];
|
|
17
|
-
|
|
67
|
+
async function bundleConfigFile(fileName, isESM = false) {
|
|
68
|
+
const result = await build({
|
|
69
|
+
absWorkingDir: process.cwd(),
|
|
70
|
+
entryPoints: [fileName],
|
|
71
|
+
outfile: 'out.js',
|
|
72
|
+
write: false,
|
|
73
|
+
platform: 'node',
|
|
74
|
+
bundle: true,
|
|
75
|
+
format: 'esm',
|
|
76
|
+
sourcemap: 'inline',
|
|
77
|
+
metafile: true,
|
|
78
|
+
plugins: [
|
|
79
|
+
{
|
|
80
|
+
name: 'externalize-deps',
|
|
81
|
+
setup(build) {
|
|
82
|
+
build.onResolve({ filter: /.*/ }, (args) => {
|
|
83
|
+
const id = args.path;
|
|
84
|
+
if (id[0] !== '.' && !path.isAbsolute(id)) {
|
|
85
|
+
return {
|
|
86
|
+
external: true
|
|
87
|
+
};
|
|
88
|
+
}
|
|
89
|
+
});
|
|
90
|
+
}
|
|
91
|
+
},
|
|
92
|
+
{
|
|
93
|
+
name: 'replace-import-meta',
|
|
94
|
+
setup(build) {
|
|
95
|
+
build.onLoad({ filter: /\.[jt]s$/ }, async (args) => {
|
|
96
|
+
const contents = await fs.promises.readFile(args.path, 'utf8');
|
|
97
|
+
return {
|
|
98
|
+
loader: args.path.endsWith('.ts') ? 'ts' : 'js',
|
|
99
|
+
contents: contents
|
|
100
|
+
.replace(/\bimport\.meta\.url\b/g, JSON.stringify(pathToFileURL(args.path).href))
|
|
101
|
+
.replace(/\b__dirname\b/g, JSON.stringify(path.dirname(args.path)))
|
|
102
|
+
.replace(/\b__filename\b/g, JSON.stringify(args.path))
|
|
103
|
+
};
|
|
104
|
+
});
|
|
105
|
+
}
|
|
106
|
+
}
|
|
107
|
+
]
|
|
108
|
+
});
|
|
109
|
+
const { text } = result.outputFiles[0];
|
|
110
|
+
return {
|
|
111
|
+
code: text,
|
|
112
|
+
dependencies: result.metafile ? Object.keys(result.metafile.inputs) : []
|
|
113
|
+
};
|
|
114
|
+
}
|
|
115
|
+
export const baseConfig = async ({ ssr, appDir, publicDir, base = '/', command = 'build', mode = 'production', framework = 'vue', pwa = false }) => {
|
|
18
116
|
const { getAppDir, getCliDir, getCliViteDir, getSrcDir, getCwd } = await import('./app-urls.js');
|
|
19
117
|
if (!appDir) {
|
|
20
118
|
appDir = getAppDir();
|
|
@@ -24,17 +122,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
24
122
|
const cliDir = getCliDir();
|
|
25
123
|
const cliViteDir = getCliViteDir(cliDir);
|
|
26
124
|
const frameworkDir = new URL(`${framework}/`, cliViteDir);
|
|
27
|
-
const
|
|
28
|
-
const cliPackages = ['vitest'];
|
|
29
|
-
const packageUrls = {};
|
|
30
|
-
await (async () => {
|
|
31
|
-
for (const val of localPackages)
|
|
32
|
-
packageUrls[val] = getPkgJsonDir(new URL(await resolve(val, appDir.href)));
|
|
33
|
-
})();
|
|
34
|
-
await (async () => {
|
|
35
|
-
for (const val of cliPackages)
|
|
36
|
-
packageUrls[val] = getPkgJsonDir(new URL(await resolve(val, cliDir.href)));
|
|
37
|
-
})();
|
|
125
|
+
const fastifyDir = new URL('fastify/', cliViteDir);
|
|
38
126
|
if (!publicDir)
|
|
39
127
|
publicDir = new URL('public/', appDir);
|
|
40
128
|
/**
|
|
@@ -42,18 +130,46 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
42
130
|
*/
|
|
43
131
|
let vitrifyConfig;
|
|
44
132
|
try {
|
|
45
|
-
|
|
133
|
+
if (fs.existsSync(new URL('vitrify.config.ts', appDir).pathname)) {
|
|
134
|
+
const configPath = new URL('vitrify.config.ts', appDir).pathname;
|
|
135
|
+
const bundledConfig = await bundleConfigFile(new URL('vitrify.config.ts', appDir).pathname);
|
|
136
|
+
fs.writeFileSync(configPath + '.js', bundledConfig.code);
|
|
137
|
+
vitrifyConfig = (await import(configPath + '.js')).default;
|
|
138
|
+
fs.unlinkSync(configPath + '.js');
|
|
139
|
+
}
|
|
140
|
+
else {
|
|
141
|
+
vitrifyConfig = (await import(new URL('vitrify.config.js', appDir).pathname)).default;
|
|
142
|
+
}
|
|
46
143
|
if (typeof vitrifyConfig === 'function')
|
|
47
|
-
vitrifyConfig = vitrifyConfig({ mode, command });
|
|
144
|
+
vitrifyConfig = await vitrifyConfig({ mode, command });
|
|
48
145
|
}
|
|
49
146
|
catch (e) {
|
|
50
|
-
console.
|
|
51
|
-
console.log('No vitrify.config.js file found, using defaults');
|
|
147
|
+
console.log('No vitrify.config.(ts|js) file found, using defaults');
|
|
52
148
|
vitrifyConfig = {};
|
|
53
149
|
}
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
}
|
|
150
|
+
const localPackages = ['vue', 'vue-router'];
|
|
151
|
+
const cliPackages = [];
|
|
152
|
+
const packageUrls = vitrifyConfig.vitrify?.urls?.packages || {};
|
|
153
|
+
await (async () => {
|
|
154
|
+
for (const val of localPackages)
|
|
155
|
+
packageUrls[val] = getPkgJsonDir(new URL(await resolve(val, appDir.href)));
|
|
156
|
+
})();
|
|
157
|
+
// await (async () => {
|
|
158
|
+
// for (const val of cliPackages)
|
|
159
|
+
// packageUrls[val] = getPkgJsonDir(
|
|
160
|
+
// new URL(await resolve(val, cliDir!.href))
|
|
161
|
+
// )
|
|
162
|
+
// })()
|
|
163
|
+
let productName = 'Product name';
|
|
164
|
+
try {
|
|
165
|
+
;
|
|
166
|
+
({ productName } = JSON.parse(readFileSync(new URL('package.json', appDir).pathname, {
|
|
167
|
+
encoding: 'utf-8'
|
|
168
|
+
})));
|
|
169
|
+
}
|
|
170
|
+
catch (e) {
|
|
171
|
+
console.error('package.json not found');
|
|
172
|
+
}
|
|
57
173
|
const ssrTransformCustomDir = () => {
|
|
58
174
|
return {
|
|
59
175
|
props: [],
|
|
@@ -73,13 +189,20 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
73
189
|
let onBootHooks;
|
|
74
190
|
let onRenderedHooks;
|
|
75
191
|
let onMountedHooks;
|
|
76
|
-
let
|
|
192
|
+
let onSetupFiles;
|
|
77
193
|
let globalCss;
|
|
78
194
|
let staticImports;
|
|
79
195
|
let sassVariables;
|
|
80
196
|
let additionalData;
|
|
197
|
+
let serverModules = internalServerModules;
|
|
198
|
+
if (vitrifyConfig.vitrify?.ssr?.serverModules)
|
|
199
|
+
serverModules = [
|
|
200
|
+
...serverModules,
|
|
201
|
+
...vitrifyConfig.vitrify.ssr.serverModules
|
|
202
|
+
];
|
|
81
203
|
const plugins = [
|
|
82
204
|
vuePlugin({
|
|
205
|
+
compiler: await import('vue/compiler-sfc'),
|
|
83
206
|
template: {
|
|
84
207
|
ssr: !!ssr,
|
|
85
208
|
compilerOptions: {
|
|
@@ -107,7 +230,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
107
230
|
onBootHooks = config.vitrify?.hooks?.onBoot || [];
|
|
108
231
|
onRenderedHooks = config.vitrify?.hooks?.onRendered || [];
|
|
109
232
|
onMountedHooks = config.vitrify?.hooks?.onMounted || [];
|
|
110
|
-
|
|
233
|
+
onSetupFiles = config?.vitrify?.hooks?.onSetup || [];
|
|
111
234
|
globalCss = config.vitrify?.globalCss || [];
|
|
112
235
|
staticImports = config.vitrify?.staticImports || {};
|
|
113
236
|
sassVariables = config.vitrify?.sass?.variables || {};
|
|
@@ -134,9 +257,16 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
134
257
|
},
|
|
135
258
|
resolveId(id) {
|
|
136
259
|
if (VIRTUAL_MODULES.includes(id))
|
|
137
|
-
return id;
|
|
260
|
+
return { id, moduleSideEffects: false };
|
|
138
261
|
return;
|
|
139
262
|
},
|
|
263
|
+
transform: (code, id) => {
|
|
264
|
+
if (id.endsWith('main.ts') && id.includes('vitrify')) {
|
|
265
|
+
code =
|
|
266
|
+
`${globalCss.map((css) => `import '${css}'`).join('\n')}\n` + code;
|
|
267
|
+
}
|
|
268
|
+
return code;
|
|
269
|
+
},
|
|
140
270
|
load(id) {
|
|
141
271
|
if (id === 'virtual:vitrify-hooks') {
|
|
142
272
|
return `export const onBoot = [${onBootHooks
|
|
@@ -148,12 +278,22 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
148
278
|
export const onRendered = [${onRenderedHooks
|
|
149
279
|
.map((fn) => `${String(fn)}`)
|
|
150
280
|
.join(', ')}]
|
|
151
|
-
export const onSetup = [
|
|
152
|
-
|
|
153
|
-
.
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
281
|
+
export const onSetup = []
|
|
282
|
+
${onSetupFiles
|
|
283
|
+
.map((url, index) => `import ${url.pathname
|
|
284
|
+
.replaceAll('/', '')
|
|
285
|
+
.replaceAll('.', '')} from '${url.pathname}'; onSetup.push(${url.pathname
|
|
286
|
+
.replaceAll('/', '')
|
|
287
|
+
.replaceAll('.', '')})`)
|
|
288
|
+
.join('\n')}`;
|
|
289
|
+
// export const onSetup = [${onSetupHooks
|
|
290
|
+
// .map((fn) => `${String(fn)}`)
|
|
291
|
+
// .join(', ')}]`
|
|
292
|
+
/**
|
|
293
|
+
* CSS imports in virtual files do not seem to work. Using transform() instead
|
|
294
|
+
*/
|
|
295
|
+
// } else if (id === 'virtual:global-css') {
|
|
296
|
+
// return `${globalCss.map((css) => `import '${css}'`).join('\n')}`
|
|
157
297
|
}
|
|
158
298
|
else if (id === 'virtual:static-imports') {
|
|
159
299
|
return `${Object.entries(staticImports)
|
|
@@ -188,6 +328,9 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
188
328
|
case 'client':
|
|
189
329
|
entry = new URL('ssr/entry-client.ts', frameworkDir).pathname;
|
|
190
330
|
break;
|
|
331
|
+
case 'fastify':
|
|
332
|
+
entry = new URL('entry.ts', fastifyDir).pathname;
|
|
333
|
+
break;
|
|
191
334
|
default:
|
|
192
335
|
entry = new URL('csr/entry.ts', frameworkDir).pathname;
|
|
193
336
|
}
|
|
@@ -221,18 +364,102 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
221
364
|
{ find: 'cwd', replacement: cwd.pathname },
|
|
222
365
|
{ find: 'boot', replacement: new URL('boot/', srcDir).pathname },
|
|
223
366
|
{ find: 'assets', replacement: new URL('assets/', srcDir).pathname },
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
367
|
+
...Object.entries(packageUrls).map(([key, value]) => ({
|
|
368
|
+
find: key,
|
|
369
|
+
replacement: value.pathname
|
|
370
|
+
}))
|
|
371
|
+
// { find: 'vue', replacement: packageUrls['vue'].pathname },
|
|
372
|
+
// { find: 'vue-router', replacement: packageUrls['vue-router'].pathname },
|
|
373
|
+
// { find: 'vitrify', replacement: cliDir.pathname }
|
|
227
374
|
];
|
|
375
|
+
if (mode === 'development' && vitrifyConfig.vitrify?.dev?.alias)
|
|
376
|
+
alias.push(...vitrifyConfig.vitrify.dev.alias);
|
|
228
377
|
if (command === 'test')
|
|
229
378
|
alias.push({
|
|
230
379
|
find: 'vitest',
|
|
231
|
-
replacement:
|
|
380
|
+
replacement: new URL(await resolve('vitest', cliDir.href)).pathname
|
|
232
381
|
});
|
|
382
|
+
let rollupOptions = {};
|
|
383
|
+
let noExternal = [
|
|
384
|
+
new RegExp(`^(?!(${[...builtinModules, ...serverModules].join('|')}))`)
|
|
385
|
+
];
|
|
386
|
+
const external = [...builtinModules, ...serverModules];
|
|
387
|
+
if (ssr === 'server') {
|
|
388
|
+
rollupOptions = {
|
|
389
|
+
input: [
|
|
390
|
+
new URL('ssr/entry-server.ts', frameworkDir).pathname,
|
|
391
|
+
new URL('ssr/prerender.ts', frameworkDir).pathname,
|
|
392
|
+
new URL('ssr/server.ts', frameworkDir).pathname
|
|
393
|
+
],
|
|
394
|
+
external,
|
|
395
|
+
output: {
|
|
396
|
+
minifyInternalExports: false,
|
|
397
|
+
entryFileNames: '[name].mjs',
|
|
398
|
+
chunkFileNames: '[name].mjs',
|
|
399
|
+
format: 'es',
|
|
400
|
+
manualChunks
|
|
401
|
+
// manualChunks: (id) => {
|
|
402
|
+
// if (id.includes('vitrify/src/vite/')) {
|
|
403
|
+
// const name = id.split('/').at(-1)?.split('.').at(0)
|
|
404
|
+
// if (name && manualChunks.includes(name)) return name
|
|
405
|
+
// } else if (id.includes('node_modules')) {
|
|
406
|
+
// return 'vendor'
|
|
407
|
+
// }
|
|
408
|
+
// }
|
|
409
|
+
}
|
|
410
|
+
};
|
|
411
|
+
// Create a SSR bundle
|
|
412
|
+
noExternal = [
|
|
413
|
+
new RegExp(`^(?!(${[...builtinModules, ...serverModules].join('|')}))`)
|
|
414
|
+
// new RegExp(`^(?!.*(${[...builtinModules, ...serverModules].join('|')}))`)
|
|
415
|
+
];
|
|
416
|
+
}
|
|
417
|
+
else if (ssr === 'fastify') {
|
|
418
|
+
rollupOptions = {
|
|
419
|
+
input: [new URL('server.ts', fastifyDir).pathname],
|
|
420
|
+
external,
|
|
421
|
+
output: {
|
|
422
|
+
minifyInternalExports: false,
|
|
423
|
+
entryFileNames: '[name].mjs',
|
|
424
|
+
chunkFileNames: '[name].mjs',
|
|
425
|
+
format: 'es',
|
|
426
|
+
manualChunks
|
|
427
|
+
// manualChunks: (id) => {
|
|
428
|
+
// if (id.includes('vitrify/src/vite/')) {
|
|
429
|
+
// const name = id.split('/').at(-1)?.split('.').at(0)
|
|
430
|
+
// if (name && manualChunks.includes(name)) return name
|
|
431
|
+
// } else if (id.includes('node_modules')) {
|
|
432
|
+
// return 'vendor'
|
|
433
|
+
// }
|
|
434
|
+
// }
|
|
435
|
+
}
|
|
436
|
+
};
|
|
437
|
+
// Create a SSR bundle
|
|
438
|
+
noExternal = [
|
|
439
|
+
new RegExp(`^(?!(${[...builtinModules, ...serverModules].join('|')}))`)
|
|
440
|
+
];
|
|
441
|
+
}
|
|
442
|
+
else {
|
|
443
|
+
rollupOptions = {
|
|
444
|
+
input: [
|
|
445
|
+
new URL('index.html', frameworkDir).pathname
|
|
446
|
+
// new URL('csr/server.ts', frameworkDir).pathname
|
|
447
|
+
],
|
|
448
|
+
external,
|
|
449
|
+
output: {
|
|
450
|
+
minifyInternalExports: false,
|
|
451
|
+
entryFileNames: '[name].mjs',
|
|
452
|
+
chunkFileNames: '[name].mjs',
|
|
453
|
+
format: 'es',
|
|
454
|
+
manualChunks
|
|
455
|
+
}
|
|
456
|
+
};
|
|
457
|
+
}
|
|
233
458
|
const config = {
|
|
234
|
-
root: frameworkDir.pathname,
|
|
459
|
+
root: ssr === 'fastify' ? appDir.pathname : frameworkDir.pathname,
|
|
235
460
|
publicDir: publicDir.pathname,
|
|
461
|
+
base,
|
|
462
|
+
envDir: appDir.pathname,
|
|
236
463
|
vitrify: {
|
|
237
464
|
productName,
|
|
238
465
|
urls: {
|
|
@@ -245,60 +472,54 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
245
472
|
},
|
|
246
473
|
plugins,
|
|
247
474
|
optimizeDeps: {
|
|
248
|
-
exclude: ['vue']
|
|
475
|
+
exclude: ['vue', ...serverModules, ...builtinModules]
|
|
249
476
|
},
|
|
250
477
|
resolve: {
|
|
251
|
-
|
|
252
|
-
// dedupe: [
|
|
253
|
-
// 'vue',
|
|
254
|
-
// 'vue-router'
|
|
255
|
-
// ],
|
|
478
|
+
dedupe: ['vue', 'vue-router'],
|
|
256
479
|
alias
|
|
257
480
|
},
|
|
258
481
|
build: {
|
|
259
|
-
target: ssr === 'server' ? 'esnext' : 'modules',
|
|
260
|
-
ssr: ssr === 'server' ? true : false,
|
|
482
|
+
target: ssr === 'server' || ssr === 'fastify' ? 'esnext' : 'modules',
|
|
483
|
+
ssr: ssr === 'server' || ssr === 'fastify' ? true : false,
|
|
261
484
|
ssrManifest: ssr === 'client' || ssr === 'ssg',
|
|
262
|
-
rollupOptions
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
279
|
-
|
|
280
|
-
|
|
281
|
-
|
|
282
|
-
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
|
|
286
|
-
|
|
287
|
-
|
|
288
|
-
|
|
289
|
-
|
|
290
|
-
}
|
|
291
|
-
}
|
|
485
|
+
rollupOptions
|
|
486
|
+
// ssr === 'server'
|
|
487
|
+
// ? {
|
|
488
|
+
// input: [
|
|
489
|
+
// new URL('ssr/entry-server.ts', frameworkDir).pathname,
|
|
490
|
+
// new URL('ssr/prerender.ts', frameworkDir).pathname,
|
|
491
|
+
// new URL('ssr/server.ts', frameworkDir).pathname
|
|
492
|
+
// ],
|
|
493
|
+
// output: {
|
|
494
|
+
// minifyInternalExports: false,
|
|
495
|
+
// entryFileNames: '[name].mjs',
|
|
496
|
+
// chunkFileNames: '[name].mjs',
|
|
497
|
+
// format: 'es',
|
|
498
|
+
// manualChunks: (id) => {
|
|
499
|
+
// if (id.includes('vitrify/src/vite/')) {
|
|
500
|
+
// const name = id.split('/').at(-1)?.split('.').at(0)
|
|
501
|
+
// if (name && manualChunks.includes(name)) return name
|
|
502
|
+
// } else if (id.includes('node_modules')) {
|
|
503
|
+
// return 'vendor'
|
|
504
|
+
// }
|
|
505
|
+
// }
|
|
506
|
+
// }
|
|
507
|
+
// }
|
|
508
|
+
// : {
|
|
509
|
+
// output: {
|
|
510
|
+
// format: 'es'
|
|
511
|
+
// }
|
|
512
|
+
// }
|
|
292
513
|
},
|
|
293
514
|
ssr: {
|
|
294
515
|
// Create a SSR bundle
|
|
295
|
-
|
|
296
|
-
|
|
297
|
-
]
|
|
516
|
+
external,
|
|
517
|
+
noExternal
|
|
298
518
|
},
|
|
299
519
|
define: {
|
|
300
|
-
__BASE_URL__: `'
|
|
520
|
+
__BASE_URL__: `'${base}'`
|
|
301
521
|
}
|
|
302
522
|
};
|
|
303
523
|
return mergeConfig(config, vitrifyConfig);
|
|
304
524
|
};
|
|
525
|
+
export const vitrifyDir = new URL('..', import.meta.url);
|
package/dist/plugins/quasar.js
CHANGED
|
@@ -37,6 +37,19 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
|
|
|
37
37
|
Components({
|
|
38
38
|
resolvers: [QuasarResolver()]
|
|
39
39
|
}),
|
|
40
|
+
{
|
|
41
|
+
name: 'vite-plugin-quasar-transform',
|
|
42
|
+
enforce: 'pre',
|
|
43
|
+
transform: (code, id, options) => {
|
|
44
|
+
const { ssr } = options || {};
|
|
45
|
+
code = code
|
|
46
|
+
.replaceAll('__QUASAR_SSR__', ssr ? ssr.toString() : 'false')
|
|
47
|
+
.replaceAll('__QUASAR_SSR_SERVER__', ssr ? 'import.meta.env.SSR' : 'false')
|
|
48
|
+
.replaceAll('__QUASAR_SSR_CLIENT__', ssr ? '!import.meta.env.SSR' : 'false')
|
|
49
|
+
.replaceAll('__QUASAR_SSR_PWA__', ssr && pwa ? '!import.meta.env.SSR' : 'false');
|
|
50
|
+
return code;
|
|
51
|
+
}
|
|
52
|
+
},
|
|
40
53
|
{
|
|
41
54
|
name: 'vite-plugin-quasar-setup',
|
|
42
55
|
enforce: 'pre',
|
|
@@ -61,7 +74,7 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
|
|
|
61
74
|
const quasarPlugins = await import('virtual:quasar-plugins');
|
|
62
75
|
// @ts-ignore
|
|
63
76
|
const directives = await import('quasar/src/directives.js');
|
|
64
|
-
app.use(staticImports
|
|
77
|
+
app.use(staticImports?.Quasar, {
|
|
65
78
|
plugins: quasarPlugins,
|
|
66
79
|
directives
|
|
67
80
|
}, ssrContext);
|
|
@@ -137,9 +150,14 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
|
|
|
137
150
|
replacement: new URL('src/', urls?.packages?.quasar).pathname
|
|
138
151
|
},
|
|
139
152
|
{
|
|
140
|
-
find: 'quasar',
|
|
141
|
-
replacement: new URL('src/', urls?.packages?.quasar)
|
|
153
|
+
find: new RegExp('^quasar$'),
|
|
154
|
+
replacement: new URL('src/index.all.js', urls?.packages?.quasar)
|
|
155
|
+
.pathname
|
|
142
156
|
},
|
|
157
|
+
// {
|
|
158
|
+
// find: 'quasar',
|
|
159
|
+
// replacement: new URL('src/index.all.js', urls?.packages?.quasar).pathname
|
|
160
|
+
// },
|
|
143
161
|
{
|
|
144
162
|
find: `@quasar/extras`,
|
|
145
163
|
replacement: new URL('.', urls?.packages?.['@quasar/extras'])
|
|
@@ -149,11 +167,14 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
|
|
|
149
167
|
},
|
|
150
168
|
define: {
|
|
151
169
|
__DEV__: process.env.NODE_ENV !== 'production' || true,
|
|
152
|
-
__QUASAR_VERSION__: `'${version}'
|
|
153
|
-
__QUASAR_SSR__: !!ssr,
|
|
154
|
-
__QUASAR_SSR_SERVER__: ssr === 'server',
|
|
155
|
-
|
|
156
|
-
|
|
170
|
+
__QUASAR_VERSION__: `'${version}'`
|
|
171
|
+
// __QUASAR_SSR__: !!ssr,
|
|
172
|
+
// // __QUASAR_SSR_SERVER__: ssr === 'server',
|
|
173
|
+
// __QUASAR_SSR_SERVER__: `import.meta.env.SSR`,
|
|
174
|
+
// // __QUASAR_SSR_CLIENT__: ssr === 'client',
|
|
175
|
+
// __QUASAR_SSR_CLIENT__: `!import.meta.env.SSR`,
|
|
176
|
+
// // __QUASAR_SSR_PWA__: ssr === 'client' && pwa
|
|
177
|
+
// __QUASAR_SSR_PWA__: pwa ? `!import.meta.env.SSR` : false
|
|
157
178
|
},
|
|
158
179
|
ssr: {
|
|
159
180
|
noExternal: ['quasar']
|
|
@@ -167,7 +188,7 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
|
|
|
167
188
|
config: async (config, env) => ({
|
|
168
189
|
resolve: {
|
|
169
190
|
alias: [
|
|
170
|
-
|
|
191
|
+
// { find: new RegExp('^quasar$'), replacement: 'virtual:quasar' }
|
|
171
192
|
]
|
|
172
193
|
}
|
|
173
194
|
}),
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
#!/usr/bin/node --experimental-specifier-resolution=node
|
|
2
2
|
export declare function build(opts: {
|
|
3
|
-
ssr?: 'client' | 'server' | 'ssg';
|
|
3
|
+
ssr?: 'client' | 'server' | 'ssg' | 'fastify';
|
|
4
4
|
base?: string;
|
|
5
|
-
outDir
|
|
5
|
+
outDir: string;
|
|
6
6
|
appDir?: URL;
|
|
7
7
|
publicDir?: URL;
|
|
8
8
|
}): Promise<import("rollup").RollupOutput | import("rollup").RollupOutput[] | import("rollup").RollupWatcher>;
|
package/dist/types/bin/dev.d.ts
CHANGED
|
@@ -1,15 +1,54 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
|
-
import type {
|
|
2
|
+
import type { LogLevel, InlineConfig } from 'vite';
|
|
3
|
+
import { ViteDevServer } from 'vite';
|
|
3
4
|
import type { Server } from 'net';
|
|
4
|
-
export declare function
|
|
5
|
+
export declare function createVitrifyDevServer({ port, logLevel, ssr, framework, host, appDir, publicDir, base }: {
|
|
5
6
|
port?: number;
|
|
6
7
|
logLevel?: LogLevel;
|
|
7
|
-
|
|
8
|
+
ssr?: 'ssr' | 'fastify';
|
|
9
|
+
framework?: 'vue';
|
|
10
|
+
host?: string;
|
|
11
|
+
appDir?: URL;
|
|
12
|
+
publicDir?: URL;
|
|
13
|
+
base?: string;
|
|
14
|
+
}): Promise<ViteDevServer>;
|
|
15
|
+
export declare function createServer({ port, logLevel, ssr, framework, host, appDir, publicDir }: {
|
|
16
|
+
port?: number;
|
|
17
|
+
logLevel?: LogLevel;
|
|
18
|
+
ssr?: 'ssr' | 'fastify';
|
|
8
19
|
framework?: 'vue';
|
|
9
20
|
host?: string;
|
|
10
21
|
appDir?: URL;
|
|
11
22
|
publicDir?: URL;
|
|
12
23
|
}): Promise<{
|
|
13
24
|
server: Server;
|
|
14
|
-
|
|
25
|
+
config: Readonly<Omit<import("vite").UserConfig, "plugins" | "assetsInclude" | "optimizeDeps" | "worker"> & {
|
|
26
|
+
configFile: string | undefined;
|
|
27
|
+
configFileDependencies: string[];
|
|
28
|
+
inlineConfig: InlineConfig;
|
|
29
|
+
root: string;
|
|
30
|
+
base: string;
|
|
31
|
+
publicDir: string;
|
|
32
|
+
cacheDir: string;
|
|
33
|
+
command: "build" | "serve";
|
|
34
|
+
mode: string;
|
|
35
|
+
isWorker: boolean;
|
|
36
|
+
isProduction: boolean;
|
|
37
|
+
env: Record<string, any>;
|
|
38
|
+
resolve: import("vite").ResolveOptions & {
|
|
39
|
+
alias: import("vite").Alias[];
|
|
40
|
+
};
|
|
41
|
+
plugins: readonly import("vite").Plugin[];
|
|
42
|
+
server: import("vite").ResolvedServerOptions;
|
|
43
|
+
build: Required<import("vite").BuildOptions>;
|
|
44
|
+
preview: import("vite").ResolvedPreviewOptions;
|
|
45
|
+
ssr: import("vite").ResolvedSSROptions | undefined;
|
|
46
|
+
assetsInclude: (file: string) => boolean;
|
|
47
|
+
logger: import("vite").Logger;
|
|
48
|
+
createResolver: (options?: Partial<import("vite").InternalResolveOptions> | undefined) => import("vite").ResolveFn;
|
|
49
|
+
optimizeDeps: import("vite").DepOptimizationOptions;
|
|
50
|
+
worker: import("vite").ResolveWorkerOptions;
|
|
51
|
+
appType: import("vite").AppType;
|
|
52
|
+
experimental: import("vite").ResolvedExperimentalOptions;
|
|
53
|
+
}>;
|
|
15
54
|
}>;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import type { FastifyPluginCallback, FastifyRequest, FastifyReply } from 'fastify';
|
|
2
|
+
import type { OnRenderedHook } from '../../vitrify-config.js';
|
|
3
|
+
import type { ViteDevServer } from 'vite';
|
|
4
|
+
export interface FastifySsrOptions {
|
|
5
|
+
baseUrl?: string;
|
|
6
|
+
provide?: (req: FastifyRequest, res: FastifyReply) => Promise<Record<string, unknown>>;
|
|
7
|
+
vitrifyDir?: URL;
|
|
8
|
+
vite?: ViteDevServer;
|
|
9
|
+
appDir?: URL;
|
|
10
|
+
publicDir?: URL;
|
|
11
|
+
productName?: string;
|
|
12
|
+
onRendered?: OnRenderedHook[];
|
|
13
|
+
mode?: string;
|
|
14
|
+
}
|
|
15
|
+
declare const fastifyCsrPlugin: FastifyPluginCallback<FastifySsrOptions>;
|
|
16
|
+
export { fastifyCsrPlugin };
|
|
17
|
+
export declare type FastifyCsrPlugin = typeof fastifyCsrPlugin;
|