vitrify 0.2.3 → 0.3.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 +0 -1
- package/dist/bin/build.js +0 -43
- package/dist/bin/cli.js +3 -3
- package/dist/bin/dev.js +1 -42
- package/dist/frameworks/vue/fastify-ssr-plugin.js +2 -9
- package/dist/frameworks/vue/prerender.js +3 -3
- package/dist/frameworks/vue/server.js +2 -8
- package/dist/helpers/logger.js +0 -72
- package/dist/index.js +22 -62
- package/dist/plugins/quasar.js +4 -102
- package/dist/types/frameworks/vue/fastify-ssr-plugin.d.ts +2 -2
- package/dist/types/frameworks/vue/prerender.d.ts +3 -3
- package/dist/types/frameworks/vue/server.d.ts +3 -3
- package/dist/types/helpers/logger.d.ts +0 -19
- package/dist/types/vitrify-config.d.ts +20 -15
- package/package.json +2 -2
- package/src/node/app-urls.ts +0 -1
- package/src/node/bin/build.ts +0 -47
- package/src/node/bin/cli.ts +3 -3
- package/src/node/bin/dev.ts +1 -45
- package/src/node/bin/test.ts +0 -3
- package/src/node/frameworks/vue/fastify-ssr-plugin.ts +4 -12
- package/src/node/frameworks/vue/prerender.ts +5 -5
- package/src/node/frameworks/vue/server.ts +4 -12
- package/src/node/helpers/logger.ts +0 -87
- package/src/node/index.ts +28 -67
- package/src/node/plugins/quasar.ts +5 -107
- package/src/node/vitrify-config.ts +27 -15
- package/src/vite/vue/main.ts +5 -19
- package/src/vite/vue/ssr/fastify-ssr-plugin.ts +2 -118
- package/src/vite/vue/ssr/prerender.ts +2 -2
- package/src/vite/vue/ssr/server.ts +3 -3
- package/src/node/helpers/ssr.ts.bak +0 -52
package/dist/app-urls.js
CHANGED
|
@@ -12,7 +12,6 @@ export const getCliDir = () => getPkgJsonDir(new URL('./', import.meta.url));
|
|
|
12
12
|
export const getCliViteDir = (cliDir) => new URL('src/vite/', cliDir);
|
|
13
13
|
export const getSrcDir = (appDir) => new URL('src/', appDir);
|
|
14
14
|
export const getCwd = () => new URL(`file://${process.cwd()}/`);
|
|
15
|
-
// export const quasarDir = getPkgJsonDir(new URL('./', await resolve('quasar', appDir.href)))
|
|
16
15
|
export const parsePath = (path, basePath) => {
|
|
17
16
|
if (path) {
|
|
18
17
|
if (path.slice(-1) !== '/')
|
package/dist/bin/build.js
CHANGED
|
@@ -1,49 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/node --experimental-specifier-resolution=node
|
|
2
2
|
import { baseConfig } from '../index.js';
|
|
3
|
-
// import { promises as fs } from 'fs'
|
|
4
|
-
// import { routesToPaths } from '../helpers/routes.js'
|
|
5
3
|
import { build as viteBuild } from 'vite';
|
|
6
|
-
// import { SsrFunction } from '../vitrify-config.js'
|
|
7
|
-
// export const prerender = async ({
|
|
8
|
-
// outDir,
|
|
9
|
-
// templatePath,
|
|
10
|
-
// manifestPath,
|
|
11
|
-
// entryServerPath,
|
|
12
|
-
// injectSsrContext
|
|
13
|
-
// }: {
|
|
14
|
-
// outDir: string
|
|
15
|
-
// templatePath: string
|
|
16
|
-
// manifestPath: string
|
|
17
|
-
// entryServerPath: string
|
|
18
|
-
// injectSsrContext: SsrFunction
|
|
19
|
-
// }) => {
|
|
20
|
-
// let template
|
|
21
|
-
// let manifest
|
|
22
|
-
// const promises = []
|
|
23
|
-
// template = (await fs.readFile(templatePath)).toString()
|
|
24
|
-
// manifest = await fs.readFile(manifestPath)
|
|
25
|
-
// let { render, getRoutes } = await import(entryServerPath)
|
|
26
|
-
// const routes = await getRoutes()
|
|
27
|
-
// const paths = routesToPaths(routes).filter(
|
|
28
|
-
// (i) => !i.includes(':') && !i.includes('*')
|
|
29
|
-
// )
|
|
30
|
-
// for (let url of paths) {
|
|
31
|
-
// const filename =
|
|
32
|
-
// (url.endsWith('/') ? 'index' : url.replace(/^\//g, '')) + '.html'
|
|
33
|
-
// console.log(`Generating ${filename}`)
|
|
34
|
-
// const ssrContext = {
|
|
35
|
-
// req: { headers: {}, url },
|
|
36
|
-
// res: {}
|
|
37
|
-
// }
|
|
38
|
-
// const [appHtml, preloadLinks] = await render(url, manifest, ssrContext)
|
|
39
|
-
// let html = template
|
|
40
|
-
// .replace(`<!--preload-links-->`, preloadLinks)
|
|
41
|
-
// .replace(`<!--app-html-->`, appHtml)
|
|
42
|
-
// html = injectSsrContext(html, ssrContext)
|
|
43
|
-
// promises.push(fs.writeFile(outDir + filename, html, 'utf-8'))
|
|
44
|
-
// }
|
|
45
|
-
// return Promise.all(promises)
|
|
46
|
-
// }
|
|
47
4
|
export async function build(opts) {
|
|
48
5
|
const config = await baseConfig({
|
|
49
6
|
command: 'build',
|
package/dist/bin/cli.js
CHANGED
|
@@ -14,7 +14,7 @@ cli
|
|
|
14
14
|
.action(async (options) => {
|
|
15
15
|
const { build } = await import('./build.js');
|
|
16
16
|
let appDir;
|
|
17
|
-
let prerender,
|
|
17
|
+
let prerender, onRenderedHooks;
|
|
18
18
|
if (options.appDir) {
|
|
19
19
|
if (options.appDir.slice(-1) !== '/')
|
|
20
20
|
options.appDir += '/';
|
|
@@ -59,7 +59,7 @@ cli
|
|
|
59
59
|
...args,
|
|
60
60
|
outDir: new URL('ssr/server/', baseOutDir).pathname
|
|
61
61
|
});
|
|
62
|
-
({ prerender,
|
|
62
|
+
({ prerender, onRenderedHooks } = await import(new URL('ssr/server/prerender.mjs', baseOutDir).pathname));
|
|
63
63
|
prerender({
|
|
64
64
|
outDir: new URL('static/', baseOutDir).pathname,
|
|
65
65
|
templatePath: new URL('static/index.html', baseOutDir).pathname,
|
|
@@ -67,7 +67,7 @@ cli
|
|
|
67
67
|
.pathname,
|
|
68
68
|
entryServerPath: new URL('ssr/server/entry-server.mjs', baseOutDir)
|
|
69
69
|
.pathname,
|
|
70
|
-
|
|
70
|
+
onRenderedHooks
|
|
71
71
|
});
|
|
72
72
|
break;
|
|
73
73
|
default:
|
package/dist/bin/dev.js
CHANGED
|
@@ -8,7 +8,7 @@ export async function createServer({ port = 3000, logLevel = 'info', mode = 'csr
|
|
|
8
8
|
const cliDir = getCliDir();
|
|
9
9
|
if (!appDir)
|
|
10
10
|
appDir = getAppDir();
|
|
11
|
-
const { fastifySsrPlugin } = await import(
|
|
11
|
+
const { fastifySsrPlugin } = await import(`../frameworks/${framework}/fastify-ssr-plugin.js`);
|
|
12
12
|
/**
|
|
13
13
|
* @type {import('vite').ViteDevServer}
|
|
14
14
|
*/
|
|
@@ -57,47 +57,6 @@ export async function createServer({ port = 3000, logLevel = 'info', mode = 'csr
|
|
|
57
57
|
vite,
|
|
58
58
|
productName
|
|
59
59
|
});
|
|
60
|
-
// await app.register(middie)
|
|
61
|
-
// app.use(vite.middlewares)
|
|
62
|
-
// app.get('*', async (req, res) => {
|
|
63
|
-
// try {
|
|
64
|
-
// // const url = req.originalUrl
|
|
65
|
-
// const url = req.raw.url
|
|
66
|
-
// let template
|
|
67
|
-
// let render
|
|
68
|
-
// const ssrContext = {
|
|
69
|
-
// req,
|
|
70
|
-
// res
|
|
71
|
-
// }
|
|
72
|
-
// // always read fresh template in dev
|
|
73
|
-
// // template = readFileSync(resolve('index.html'), 'utf-8')
|
|
74
|
-
// template = readFileSync(new URL('index.html', cliDir)).toString()
|
|
75
|
-
// // template = await vite.transformIndexHtml(url, template)
|
|
76
|
-
// const entryUrl = new URL('ssr/entry-server.ts', cliDir).pathname
|
|
77
|
-
// render = (await vite.ssrLoadModule(entryUrl)).render
|
|
78
|
-
// let manifest
|
|
79
|
-
// // TODO: https://github.com/vitejs/vite/issues/2282
|
|
80
|
-
// try {
|
|
81
|
-
// manifest = {}
|
|
82
|
-
// } catch (e) {
|
|
83
|
-
// manifest = {}
|
|
84
|
-
// }
|
|
85
|
-
// const [appHtml, preloadLinks] = await render(url, manifest, ssrContext)
|
|
86
|
-
// const html = template
|
|
87
|
-
// .replace(`<!--preload-links-->`, preloadLinks)
|
|
88
|
-
// .replace(`<!--app-html-->`, appHtml)
|
|
89
|
-
// .replace('<!--product-name-->', productName)
|
|
90
|
-
// res.code(200)
|
|
91
|
-
// res.type('text/html')
|
|
92
|
-
// res.send(html)
|
|
93
|
-
// // res.status(200).set({ 'Content-Type': 'text/html' }).end(html)
|
|
94
|
-
// } catch (e: any) {
|
|
95
|
-
// console.error(e.stack)
|
|
96
|
-
// vite && vite.ssrFixStacktrace(e)
|
|
97
|
-
// res.code(500)
|
|
98
|
-
// res.send(e.stack)
|
|
99
|
-
// }
|
|
100
|
-
// })
|
|
101
60
|
await app.listen(port || 3000, host);
|
|
102
61
|
server = app.server;
|
|
103
62
|
}
|
|
@@ -9,16 +9,12 @@ const fastifySsrPlugin = async (fastify, options, done) => {
|
|
|
9
9
|
fastify.use(options.vite.middlewares);
|
|
10
10
|
fastify.get('*', async (req, res) => {
|
|
11
11
|
try {
|
|
12
|
-
// const url = req.originalUrl
|
|
13
12
|
const url = req.raw.url;
|
|
14
13
|
const ssrContext = {
|
|
15
14
|
req,
|
|
16
15
|
res
|
|
17
16
|
};
|
|
18
|
-
// always read fresh template in dev
|
|
19
|
-
// template = readFileSync(resolve('index.html'), 'utf-8')
|
|
20
17
|
const template = readFileSync(new URL('index.html', options.cliDir)).toString();
|
|
21
|
-
// template = await vite.transformIndexHtml(url, template)
|
|
22
18
|
const entryUrl = new URL('ssr/entry-server.ts', options.cliDir).pathname;
|
|
23
19
|
const render = (await options.vite.ssrLoadModule(entryUrl)).render;
|
|
24
20
|
let manifest;
|
|
@@ -63,9 +59,6 @@ const fastifySsrPlugin = async (fastify, options, done) => {
|
|
|
63
59
|
res,
|
|
64
60
|
provide
|
|
65
61
|
};
|
|
66
|
-
// template = readFileSync(new URL('../client/index.html', import.meta.url).pathname).toString()
|
|
67
|
-
// manifest = JSON.parse(readFileSync(new URL('../client/ssr-manifest.json', import.meta.url)).toString())
|
|
68
|
-
// render = (await import(new URL('./entry-server.mjs', import.meta.url).pathname)).render
|
|
69
62
|
const template = readFileSync(new URL('./dist/ssr/client/index.html', options.appDir).pathname).toString();
|
|
70
63
|
const manifest = JSON.parse(readFileSync(new URL('./dist/ssr/client/ssr-manifest.json', options.appDir)).toString());
|
|
71
64
|
const render = (await import(new URL('./dist/ssr/server/entry-server.mjs', options.appDir).pathname)).render;
|
|
@@ -76,8 +69,8 @@ const fastifySsrPlugin = async (fastify, options, done) => {
|
|
|
76
69
|
let html = template
|
|
77
70
|
.replace(`<!--preload-links-->`, preloadLinks)
|
|
78
71
|
.replace(`<!--app-html-->`, appHtml);
|
|
79
|
-
if (options.
|
|
80
|
-
for (const ssrFunction of options.
|
|
72
|
+
if (options.onRenderedHooks?.length) {
|
|
73
|
+
for (const ssrFunction of options.onRenderedHooks) {
|
|
81
74
|
html = ssrFunction(html, ssrContext);
|
|
82
75
|
}
|
|
83
76
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { promises as fs } from 'fs';
|
|
2
2
|
import { routesToPaths } from '../../helpers/routes.js';
|
|
3
|
-
export const prerender = async ({ outDir, templatePath, manifestPath, entryServerPath,
|
|
3
|
+
export const prerender = async ({ outDir, templatePath, manifestPath, entryServerPath, onRenderedHooks }) => {
|
|
4
4
|
const promises = [];
|
|
5
5
|
const template = (await fs.readFile(templatePath)).toString();
|
|
6
6
|
const manifest = await fs.readFile(manifestPath);
|
|
@@ -18,8 +18,8 @@ export const prerender = async ({ outDir, templatePath, manifestPath, entryServe
|
|
|
18
18
|
let html = template
|
|
19
19
|
.replace(`<!--preload-links-->`, preloadLinks)
|
|
20
20
|
.replace(`<!--app-html-->`, appHtml);
|
|
21
|
-
if (
|
|
22
|
-
for (const ssrFunction of
|
|
21
|
+
if (onRenderedHooks?.length) {
|
|
22
|
+
for (const ssrFunction of onRenderedHooks) {
|
|
23
23
|
html = ssrFunction(html, ssrContext);
|
|
24
24
|
}
|
|
25
25
|
}
|
|
@@ -1,20 +1,14 @@
|
|
|
1
1
|
import fastify from 'fastify';
|
|
2
|
-
// import { setup } from 'virtual:fastify-setup'
|
|
3
2
|
import { fastifySsrPlugin } from './fastify-ssr-plugin.js';
|
|
4
|
-
|
|
5
|
-
export const createApp = ({ setup, appDir, baseUrl, ssrFunctions }) => {
|
|
3
|
+
export const createApp = ({ setup, appDir, baseUrl, onRenderedHooks }) => {
|
|
6
4
|
const app = fastify({
|
|
7
5
|
logger: true
|
|
8
6
|
});
|
|
9
7
|
app.register(fastifySsrPlugin, {
|
|
10
8
|
baseUrl,
|
|
11
9
|
appDir,
|
|
12
|
-
|
|
10
|
+
onRenderedHooks
|
|
13
11
|
});
|
|
14
12
|
setup(app);
|
|
15
13
|
return app;
|
|
16
14
|
};
|
|
17
|
-
// const app = createApp({
|
|
18
|
-
// setup
|
|
19
|
-
// })
|
|
20
|
-
// app.listen(process.env.PORT || 3000, process.env.HOST || '127.0.0.1')
|
package/dist/helpers/logger.js
CHANGED
|
@@ -1,79 +1,7 @@
|
|
|
1
1
|
// https://github.com/quasarframework/quasar/blob/dev/app/lib/helpers/logger.js
|
|
2
2
|
import chalk from 'chalk';
|
|
3
|
-
const { bgGreen, green, inverse, bgRed, red, bgYellow, yellow } = chalk;
|
|
4
|
-
import readline from 'readline';
|
|
5
3
|
import os from 'os';
|
|
6
4
|
import { resolveHostname } from '../helpers/utils.js';
|
|
7
|
-
/**
|
|
8
|
-
* Main approach - App CLI related
|
|
9
|
-
*/
|
|
10
|
-
const dot = '•';
|
|
11
|
-
const banner = 'App ' + dot;
|
|
12
|
-
const greenBanner = green(banner);
|
|
13
|
-
const redBanner = red(banner);
|
|
14
|
-
const yellowBanner = yellow(banner);
|
|
15
|
-
export const clearConsole = process.stdout.isTTY
|
|
16
|
-
? () => {
|
|
17
|
-
// Fill screen with blank lines. Then move to 0 (beginning of visible part) and clear it
|
|
18
|
-
const blank = '\n'.repeat(process.stdout.rows);
|
|
19
|
-
console.log(blank);
|
|
20
|
-
readline.cursorTo(process.stdout, 0, 0);
|
|
21
|
-
readline.clearScreenDown(process.stdout);
|
|
22
|
-
}
|
|
23
|
-
: () => { };
|
|
24
|
-
export const log = function (msg) {
|
|
25
|
-
console.log(msg ? ` ${greenBanner} ${msg}` : '');
|
|
26
|
-
};
|
|
27
|
-
export const warn = function (msg, pill) {
|
|
28
|
-
if (msg !== void 0) {
|
|
29
|
-
const pillBanner = pill !== void 0 ? bgYellow.black('', pill, '') + ' ' : '';
|
|
30
|
-
console.warn(` ${yellowBanner} ⚠️ ${pillBanner}${msg}`);
|
|
31
|
-
}
|
|
32
|
-
else {
|
|
33
|
-
console.warn();
|
|
34
|
-
}
|
|
35
|
-
};
|
|
36
|
-
export const fatal = function (msg, pill) {
|
|
37
|
-
if (msg !== void 0) {
|
|
38
|
-
const pillBanner = pill !== void 0 ? errorPill(pill) + ' ' : '';
|
|
39
|
-
console.error(`\n ${redBanner} ⚠️ ${pillBanner}${msg}\n`);
|
|
40
|
-
}
|
|
41
|
-
else {
|
|
42
|
-
console.error();
|
|
43
|
-
}
|
|
44
|
-
process.exit(1);
|
|
45
|
-
};
|
|
46
|
-
/**
|
|
47
|
-
* Extended approach - Compilation status & pills
|
|
48
|
-
*/
|
|
49
|
-
export const successPill = (msg) => bgGreen.black('', msg, '');
|
|
50
|
-
export const infoPill = (msg) => inverse('', msg, '');
|
|
51
|
-
export const errorPill = (msg) => bgRed.white('', msg, '');
|
|
52
|
-
export const warningPill = (msg) => bgYellow.black('', msg, '');
|
|
53
|
-
export const success = function (msg, title = 'SUCCESS') {
|
|
54
|
-
console.log(` ${greenBanner} ${successPill(title)} ${green(dot + ' ' + msg)}`);
|
|
55
|
-
};
|
|
56
|
-
export const getSuccess = function (msg, title) {
|
|
57
|
-
return ` ${greenBanner} ${successPill(title)} ${green(dot + ' ' + msg)}`;
|
|
58
|
-
};
|
|
59
|
-
export const info = function (msg, title = 'INFO') {
|
|
60
|
-
console.log(` ${greenBanner} ${infoPill(title)} ${green(dot)} ${msg}`);
|
|
61
|
-
};
|
|
62
|
-
export const getInfo = function (msg, title) {
|
|
63
|
-
return ` ${greenBanner} ${infoPill(title)} ${green(dot)} ${msg}`;
|
|
64
|
-
};
|
|
65
|
-
export const error = function (msg, title = 'ERROR') {
|
|
66
|
-
console.log(` ${redBanner} ${errorPill(title)} ${red(dot + ' ' + msg)}`);
|
|
67
|
-
};
|
|
68
|
-
export const getError = function (msg, title = 'ERROR') {
|
|
69
|
-
return ` ${redBanner} ${errorPill(title)} ${red(dot + ' ' + msg)}`;
|
|
70
|
-
};
|
|
71
|
-
export const warning = function (msg, title = 'WARNING') {
|
|
72
|
-
console.log(` ${yellowBanner} ${warningPill(title)} ${yellow(dot + ' ' + msg)}`);
|
|
73
|
-
};
|
|
74
|
-
export const getWarning = function (msg, title = 'WARNING') {
|
|
75
|
-
return ` ${yellowBanner} ${warningPill(title)} ${yellow(dot + ' ' + msg)}`;
|
|
76
|
-
};
|
|
77
5
|
export function printHttpServerUrls(server, config) {
|
|
78
6
|
const address = server.address();
|
|
79
7
|
const isAddressInfo = (x) => x?.address;
|
package/dist/index.js
CHANGED
|
@@ -8,11 +8,9 @@ const serverModules = ['fastify', 'middie'];
|
|
|
8
8
|
const configPluginMap = {
|
|
9
9
|
quasar: () => import('./plugins/quasar.js').then((module) => module.QuasarPlugin)
|
|
10
10
|
};
|
|
11
|
+
const manualChunks = ['prerender', 'fastify-ssr-plugin', 'server'];
|
|
11
12
|
export const VIRTUAL_MODULES = [
|
|
12
|
-
'virtual:
|
|
13
|
-
'virtual:boot-functions',
|
|
14
|
-
'virtual:ssr-functions',
|
|
15
|
-
'virtual:on-mounted-hooks',
|
|
13
|
+
'virtual:vitrify-hooks',
|
|
16
14
|
'virtual:global-css',
|
|
17
15
|
'virtual:static-imports'
|
|
18
16
|
];
|
|
@@ -25,15 +23,7 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
25
23
|
const cwd = getCwd();
|
|
26
24
|
const cliDir = getCliDir();
|
|
27
25
|
const cliViteDir = getCliViteDir(cliDir);
|
|
28
|
-
// const {
|
|
29
|
-
// appDir: tempAppDir,
|
|
30
|
-
// cliDir,
|
|
31
|
-
// cliViteDir,
|
|
32
|
-
// srcDir
|
|
33
|
-
// } = await import('./app-urls.js')
|
|
34
|
-
// const cwd = appDir || tempAppDir
|
|
35
26
|
const frameworkDir = new URL(`${framework}/`, cliViteDir);
|
|
36
|
-
// const localPackages = ['vue', 'vue-router', 'quasar']
|
|
37
27
|
const localPackages = ['vue', 'vue-router'];
|
|
38
28
|
const cliPackages = ['vitest'];
|
|
39
29
|
const packageUrls = {};
|
|
@@ -45,17 +35,6 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
45
35
|
for (const val of cliPackages)
|
|
46
36
|
packageUrls[val] = getPkgJsonDir(new URL(await resolve(val, cliDir.href)));
|
|
47
37
|
})();
|
|
48
|
-
// if (appDir) {
|
|
49
|
-
// srcDir = new URL('src/', appDir);
|
|
50
|
-
// quasarDir = new URL(await resolve('quasar/', appDir.href));
|
|
51
|
-
// ({ appDir: cwd, cliDir } = await import('./app-urls.js'))
|
|
52
|
-
// } else {
|
|
53
|
-
// ({ appDir, cliDir, srcDir, quasarDir } = await import('./app-urls.js'))
|
|
54
|
-
// cwd = appDir
|
|
55
|
-
// }
|
|
56
|
-
// vueDir = new URL('./', await resolve('vue', appDir.href));
|
|
57
|
-
// vueRouterDir = new URL('../', await resolve('vue-router', appDir.href));
|
|
58
|
-
// vitestDir = new URL('../', await resolve('vitest', cliDir.href));
|
|
59
38
|
if (!publicDir)
|
|
60
39
|
publicDir = new URL('public/', appDir);
|
|
61
40
|
/**
|
|
@@ -75,7 +54,6 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
75
54
|
let { productName = 'Product name' } = JSON.parse(readFileSync(new URL('package.json', appDir).pathname, {
|
|
76
55
|
encoding: 'utf-8'
|
|
77
56
|
}));
|
|
78
|
-
const fastifySetup = vitrifyConfig.vitrify?.fastify?.setup || ((fastify) => { });
|
|
79
57
|
const ssrTransformCustomDir = () => {
|
|
80
58
|
return {
|
|
81
59
|
props: [],
|
|
@@ -92,9 +70,10 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
92
70
|
}));
|
|
93
71
|
}
|
|
94
72
|
}
|
|
95
|
-
let
|
|
96
|
-
let
|
|
73
|
+
let onBootHooks;
|
|
74
|
+
let onRenderedHooks;
|
|
97
75
|
let onMountedHooks;
|
|
76
|
+
let onSetupHooks;
|
|
98
77
|
let globalCss;
|
|
99
78
|
let staticImports;
|
|
100
79
|
let sassVariables;
|
|
@@ -121,18 +100,14 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
121
100
|
}
|
|
122
101
|
}),
|
|
123
102
|
...frameworkPlugins,
|
|
124
|
-
// await QuasarPlugin({
|
|
125
|
-
// ssr: ssr,
|
|
126
|
-
// pwa: pwa
|
|
127
|
-
// // quasarDir: packageUrls.quasar
|
|
128
|
-
// }),
|
|
129
103
|
{
|
|
130
104
|
name: 'vitrify-setup',
|
|
131
105
|
enforce: 'post',
|
|
132
106
|
config: async (config, env) => {
|
|
133
|
-
|
|
134
|
-
|
|
107
|
+
onBootHooks = config.vitrify?.hooks?.onBoot || [];
|
|
108
|
+
onRenderedHooks = config.vitrify?.hooks?.onRendered || [];
|
|
135
109
|
onMountedHooks = config.vitrify?.hooks?.onMounted || [];
|
|
110
|
+
onSetupHooks = config?.vitrify?.hooks?.onSetup || [];
|
|
136
111
|
globalCss = config.vitrify?.globalCss || [];
|
|
137
112
|
staticImports = config.vitrify?.staticImports || {};
|
|
138
113
|
sassVariables = config.vitrify?.sass?.variables || {};
|
|
@@ -163,21 +138,17 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
163
138
|
return;
|
|
164
139
|
},
|
|
165
140
|
load(id) {
|
|
166
|
-
if (id === 'virtual:
|
|
167
|
-
return `export const
|
|
168
|
-
}
|
|
169
|
-
else if (id === 'virtual:boot-functions') {
|
|
170
|
-
return `export default [${bootFunctions
|
|
141
|
+
if (id === 'virtual:vitrify-hooks') {
|
|
142
|
+
return `export const onBoot = [${onBootHooks
|
|
171
143
|
.map((fn) => `${String(fn)}`)
|
|
172
|
-
.join(', ')}]
|
|
173
|
-
|
|
174
|
-
else if (id === 'virtual:ssr-functions') {
|
|
175
|
-
return `export default [${ssrFunctions
|
|
144
|
+
.join(', ')}]
|
|
145
|
+
export const onMounted = [${onMountedHooks
|
|
176
146
|
.map((fn) => `${String(fn)}`)
|
|
177
|
-
.join(', ')}]
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
147
|
+
.join(', ')}]
|
|
148
|
+
export const onRendered = [${onRenderedHooks
|
|
149
|
+
.map((fn) => `${String(fn)}`)
|
|
150
|
+
.join(', ')}]
|
|
151
|
+
export const onSetup = [${onSetupHooks
|
|
181
152
|
.map((fn) => `${String(fn)}`)
|
|
182
153
|
.join(', ')}]`;
|
|
183
154
|
}
|
|
@@ -250,9 +221,6 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
250
221
|
{ find: 'cwd', replacement: cwd.pathname },
|
|
251
222
|
{ find: 'boot', replacement: new URL('boot/', srcDir).pathname },
|
|
252
223
|
{ find: 'assets', replacement: new URL('assets/', srcDir).pathname },
|
|
253
|
-
// ...Object.entries(packageUrls).map(([key, value]) => ({
|
|
254
|
-
// find: key, replacement: value.pathname
|
|
255
|
-
// })),
|
|
256
224
|
{ find: 'vue', replacement: packageUrls['vue'].pathname },
|
|
257
225
|
{ find: 'vue-router', replacement: packageUrls['vue-router'].pathname },
|
|
258
226
|
{ find: 'vitrify', replacement: cliDir.pathname }
|
|
@@ -268,7 +236,6 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
268
236
|
vitrify: {
|
|
269
237
|
productName,
|
|
270
238
|
urls: {
|
|
271
|
-
// @ts-ignore
|
|
272
239
|
app: appDir,
|
|
273
240
|
cli: cliDir,
|
|
274
241
|
src: srcDir,
|
|
@@ -305,11 +272,11 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
305
272
|
chunkFileNames: '[name].mjs',
|
|
306
273
|
format: 'es',
|
|
307
274
|
manualChunks: (id) => {
|
|
308
|
-
if (id.includes('
|
|
309
|
-
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
275
|
+
if (id.includes('vitrify/src/vite/')) {
|
|
276
|
+
const name = id.split('/').at(-1)?.split('.').at(0);
|
|
277
|
+
console.log(name);
|
|
278
|
+
if (manualChunks.includes(id))
|
|
279
|
+
return name;
|
|
313
280
|
}
|
|
314
281
|
else if (id.includes('node_modules')) {
|
|
315
282
|
return 'vendor';
|
|
@@ -323,13 +290,6 @@ export const baseConfig = async ({ ssr, appDir, publicDir, command = 'build', mo
|
|
|
323
290
|
}
|
|
324
291
|
}
|
|
325
292
|
},
|
|
326
|
-
// css: {
|
|
327
|
-
// preprocessorOptions: {
|
|
328
|
-
// sass: {
|
|
329
|
-
// additionalData: sass ? [...sass].join('\n') : undefined
|
|
330
|
-
// }
|
|
331
|
-
// }
|
|
332
|
-
// },
|
|
333
293
|
ssr: {
|
|
334
294
|
// Create a SSR bundle
|
|
335
295
|
noExternal: [
|
package/dist/plugins/quasar.js
CHANGED
|
@@ -31,38 +31,9 @@ export const injectSsrContext = (html, ssrContext) => html
|
|
|
31
31
|
}
|
|
32
32
|
return `${start} class="${classes.trim()}" ${ssrContext._meta.bodyAttrs || ''}${end}${ssrContext._meta.bodyTags || ''}`;
|
|
33
33
|
});
|
|
34
|
-
// export interface Configuration {
|
|
35
|
-
// ssr?: 'server' | 'client' | 'ssg' | false
|
|
36
|
-
// }
|
|
37
34
|
export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
|
|
38
|
-
// const extraPlugins: Plugin[] = []
|
|
39
|
-
// const ctx = {
|
|
40
|
-
// prod: process.env.MODE === 'production',
|
|
41
|
-
// dev: process.env.MODE === 'development',
|
|
42
|
-
// mode: {
|
|
43
|
-
// ssr: !!ssr,
|
|
44
|
-
// pwa: !!pwa
|
|
45
|
-
// }
|
|
46
|
-
// }
|
|
47
|
-
// let bootFilePaths: Record<string, any> = {}
|
|
48
|
-
// let components: string[] = []
|
|
49
35
|
let plugins = [];
|
|
50
|
-
// let css: string[] = []
|
|
51
|
-
let extras = [];
|
|
52
36
|
return [
|
|
53
|
-
// {
|
|
54
|
-
// name: 'legacy-support',
|
|
55
|
-
// enforce: 'pre',
|
|
56
|
-
// transform (code, id) {
|
|
57
|
-
// /**
|
|
58
|
-
// * ESM does not resolve an import to .default when there are multiple exports. The following is required to make the VuePlugin import of QCalendar work.
|
|
59
|
-
// */
|
|
60
|
-
// if (code.includes('app.use(VuePlugin)')) {
|
|
61
|
-
// code = code.replace(/app\.use\(VuePlugin\)/g, `app.use(VuePlugin.install ? VuePlugin : VuePlugin.default)`)
|
|
62
|
-
// }
|
|
63
|
-
// return code
|
|
64
|
-
// }
|
|
65
|
-
// },
|
|
66
37
|
Components({
|
|
67
38
|
resolvers: [QuasarResolver()]
|
|
68
39
|
}),
|
|
@@ -84,10 +55,8 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
|
|
|
84
55
|
$q.onSSRHydrated !== void 0 && $q.onSSRHydrated();
|
|
85
56
|
}
|
|
86
57
|
];
|
|
87
|
-
const
|
|
58
|
+
const onBootHooks = [
|
|
88
59
|
async ({ app, ssrContext, staticImports }) => {
|
|
89
|
-
// @ts-ignore
|
|
90
|
-
// const quasarVuePlugin = (await import('quasar/vue-plugin')).default
|
|
91
60
|
// @ts-ignore
|
|
92
61
|
const quasarPlugins = await import('virtual:quasar-plugins');
|
|
93
62
|
// @ts-ignore
|
|
@@ -101,14 +70,14 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
|
|
|
101
70
|
return {
|
|
102
71
|
vitrify: {
|
|
103
72
|
urls,
|
|
104
|
-
bootFunctions,
|
|
105
|
-
ssrFunctions: [injectSsrContext],
|
|
106
73
|
globalCss,
|
|
107
74
|
staticImports: {
|
|
108
75
|
quasar: ['Quasar']
|
|
109
76
|
},
|
|
110
77
|
hooks: {
|
|
111
|
-
|
|
78
|
+
onBoot: onBootHooks,
|
|
79
|
+
onMounted: onMountedHooks,
|
|
80
|
+
onRendered: [injectSsrContext]
|
|
112
81
|
},
|
|
113
82
|
sass: {
|
|
114
83
|
additionalData: [`@import 'quasar/src/css/index.sass'`]
|
|
@@ -120,50 +89,10 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
|
|
|
120
89
|
{
|
|
121
90
|
name: 'vite-plugin-quasar',
|
|
122
91
|
enforce: 'post',
|
|
123
|
-
// transformIndexHtml: {
|
|
124
|
-
// enforce: 'post',
|
|
125
|
-
// transform: (html) => {
|
|
126
|
-
// return html.replace(
|
|
127
|
-
// '<!--product-name-->',
|
|
128
|
-
// productName
|
|
129
|
-
// )
|
|
130
|
-
// }
|
|
131
|
-
// },
|
|
132
92
|
config: async (config, env) => {
|
|
133
|
-
// let appDir: URL
|
|
134
|
-
// let cliDir: URL
|
|
135
|
-
// let cwd: URL
|
|
136
|
-
// let quasarDir: URL
|
|
137
|
-
// let quasarConf: QuasarConf | undefined
|
|
138
93
|
const { quasar: quasarConf, vitrify: { urls } = {} } = config;
|
|
139
94
|
const quasarPkgJsonPath = new URL('package.json', urls?.packages?.quasar).pathname;
|
|
140
95
|
const { version } = JSON.parse(readFileSync(quasarPkgJsonPath, { encoding: 'utf-8' }));
|
|
141
|
-
// if (quasarConf?.boot) {
|
|
142
|
-
// bootFilePaths = (quasarConf.boot as (Record<string, any> | string)[])
|
|
143
|
-
// .filter(entry => {
|
|
144
|
-
// if (typeof entry === 'object') return (entry.server && (ssr === 'server'))
|
|
145
|
-
// else if (entry !== '') return true
|
|
146
|
-
// })
|
|
147
|
-
// .map(entry => {
|
|
148
|
-
// if (typeof entry === 'string') return entry
|
|
149
|
-
// else if (typeof entry === 'object') return entry.path
|
|
150
|
-
// })
|
|
151
|
-
// .reduce((acc, entry) => {
|
|
152
|
-
// if (entry[0] === '~') {
|
|
153
|
-
// const split = entry.substring(1).split('/')
|
|
154
|
-
// const name = split[0].replace(/[|&;$%@"<>()+,]/g, "");
|
|
155
|
-
// acc[name] = {
|
|
156
|
-
// path: new URL(`node_modules/${entry.substring(1)}`, urls?.app).pathname
|
|
157
|
-
// }
|
|
158
|
-
// } else {
|
|
159
|
-
// const name = entry.split('.')[0]
|
|
160
|
-
// acc[name] = {
|
|
161
|
-
// path: `src/boot/${entry}`
|
|
162
|
-
// }
|
|
163
|
-
// }
|
|
164
|
-
// return acc
|
|
165
|
-
// }, {})
|
|
166
|
-
// }
|
|
167
96
|
/**
|
|
168
97
|
* All components should have been auto-imported
|
|
169
98
|
*/
|
|
@@ -175,13 +104,6 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
|
|
|
175
104
|
];
|
|
176
105
|
plugins = quasarConf?.framework.plugins;
|
|
177
106
|
}
|
|
178
|
-
// css = (quasarConf?.css || []).map((v => {
|
|
179
|
-
// if (v[0] === '~') {
|
|
180
|
-
// return v.slice(1)
|
|
181
|
-
// }
|
|
182
|
-
// return v
|
|
183
|
-
// })).map((v) => `@import '${v}'`)
|
|
184
|
-
extras = quasarConf?.extras || [];
|
|
185
107
|
return {
|
|
186
108
|
resolve: {
|
|
187
109
|
alias: [
|
|
@@ -214,11 +136,6 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
|
|
|
214
136
|
find: 'quasar/src',
|
|
215
137
|
replacement: new URL('src/', urls?.packages?.quasar).pathname
|
|
216
138
|
},
|
|
217
|
-
// ...extras.map(extra => ({
|
|
218
|
-
// find: `@quasar/extras/${extra}/${extra}.css`,
|
|
219
|
-
// replacement: new URL(`${extra}/${extra}.css`, urls?.packages?.['@quasar/extras']).pathname
|
|
220
|
-
// })
|
|
221
|
-
// ),
|
|
222
139
|
{
|
|
223
140
|
find: 'quasar',
|
|
224
141
|
replacement: new URL('src/', urls?.packages?.quasar).pathname
|
|
@@ -228,8 +145,6 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
|
|
|
228
145
|
replacement: new URL('.', urls?.packages?.['@quasar/extras'])
|
|
229
146
|
.pathname
|
|
230
147
|
}
|
|
231
|
-
// { find: new RegExp('^quasar$'), replacement: new URL('src/index.all.js', urls?.packages?.quasar).pathname },
|
|
232
|
-
// { find: new RegExp('^quasar$'), replacement: 'virtual:quasar' },
|
|
233
148
|
]
|
|
234
149
|
},
|
|
235
150
|
define: {
|
|
@@ -240,19 +155,6 @@ export const QuasarPlugin = async ({ ssr = false, pwa = false }) => {
|
|
|
240
155
|
__QUASAR_SSR_CLIENT__: ssr === 'client',
|
|
241
156
|
__QUASAR_SSR_PWA__: ssr === 'client' && pwa
|
|
242
157
|
},
|
|
243
|
-
// css: {
|
|
244
|
-
// preprocessorOptions: {
|
|
245
|
-
// sass: {
|
|
246
|
-
// additionalData: `@import 'quasar/src/css/index.sass'`
|
|
247
|
-
// // [
|
|
248
|
-
// // // ...extras.map(extra => `@import "@quasar/extras/${extra}/${extra}.css"`),
|
|
249
|
-
// // // ...extras.map(extra => `@import ${new URL(`${extra}/${extra}.css`, urls?.packages?.['@quasar/extras']).pathname}`) || [],
|
|
250
|
-
// // // config.css?.preprocessorOptions?.sass?.additionalData,
|
|
251
|
-
// // `@import 'quasar/src/css/index.sass'`
|
|
252
|
-
// // ].join('\n')
|
|
253
|
-
// }
|
|
254
|
-
// }
|
|
255
|
-
// },
|
|
256
158
|
ssr: {
|
|
257
159
|
noExternal: ['quasar']
|
|
258
160
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { FastifyPluginCallback, FastifyRequest, FastifyReply } from 'fastify';
|
|
2
2
|
import type { ViteDevServer } from 'vite';
|
|
3
|
-
import type {
|
|
3
|
+
import type { OnRenderedHook } from '../../vitrify-config.js';
|
|
4
4
|
export interface FastifySsrOptions {
|
|
5
5
|
baseUrl?: string;
|
|
6
6
|
provide?: (req: FastifyRequest, res: FastifyReply) => Promise<Record<string, unknown>>;
|
|
@@ -8,7 +8,7 @@ export interface FastifySsrOptions {
|
|
|
8
8
|
cliDir?: URL;
|
|
9
9
|
appDir?: URL;
|
|
10
10
|
productName?: string;
|
|
11
|
-
|
|
11
|
+
onRenderedHooks?: OnRenderedHook[];
|
|
12
12
|
}
|
|
13
13
|
declare const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions>;
|
|
14
14
|
export { fastifySsrPlugin };
|