vitrify 0.2.5 → 0.5.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/README.md +2 -2
- package/dist/app-urls.js +1 -2
- package/dist/bin/build.js +9 -51
- package/dist/bin/cli.js +31 -9
- package/dist/bin/dev.js +72 -70
- package/dist/frameworks/vue/fastify-csr-plugin.js +38 -0
- package/dist/frameworks/vue/fastify-ssr-plugin.js +83 -25
- package/dist/frameworks/vue/prerender.js +3 -3
- package/dist/frameworks/vue/server.js +10 -11
- package/dist/helpers/collect-css-ssr.js +61 -0
- package/dist/helpers/logger.js +0 -72
- package/dist/index.js +310 -130
- package/dist/plugins/quasar.js +34 -111
- package/dist/types/bin/build.d.ts +2 -2
- package/dist/types/bin/dev.d.ts +42 -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/prerender.d.ts +3 -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/logger.d.ts +0 -19
- 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 +33 -17
- package/package.json +33 -32
- package/src/node/app-urls.ts +1 -2
- package/src/node/bin/build.ts +11 -57
- package/src/node/bin/cli.ts +38 -10
- package/src/node/bin/dev.ts +106 -80
- package/src/node/bin/test.ts +0 -3
- package/src/node/frameworks/vue/fastify-csr-plugin.ts +72 -0
- package/src/node/frameworks/vue/fastify-ssr-plugin.ts +99 -28
- package/src/node/frameworks/vue/prerender.ts +5 -5
- package/src/node/frameworks/vue/server.ts +24 -17
- package/src/node/helpers/collect-css-ssr.ts +85 -0
- package/src/node/helpers/logger.ts +0 -87
- package/src/node/index.ts +353 -146
- package/src/node/plugins/index.ts +1 -1
- package/src/node/plugins/quasar.ts +39 -116
- package/src/node/vitrify-config.ts +44 -17
- 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 +5 -20
- package/src/vite/vue/ssr/app.ts +25 -0
- package/src/vite/vue/ssr/entry-server.ts +13 -1
- 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 +24 -15
- package/src/node/helpers/ssr.ts.bak +0 -52
|
@@ -0,0 +1,61 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Collect SSR CSS for Vite
|
|
3
|
+
*/
|
|
4
|
+
export const componentsModules = (components, vite) => {
|
|
5
|
+
const matchedModules = new Set();
|
|
6
|
+
components.forEach((component) => {
|
|
7
|
+
const modules = vite.moduleGraph.getModulesByFile(component);
|
|
8
|
+
modules?.forEach((mod) => matchedModules.add(mod));
|
|
9
|
+
});
|
|
10
|
+
return matchedModules;
|
|
11
|
+
};
|
|
12
|
+
export const collectCss = ({ mods, styles = new Map(), checkedComponents = new Set() }) => {
|
|
13
|
+
for (const mod of mods) {
|
|
14
|
+
if ((mod.file?.endsWith('.scss') ||
|
|
15
|
+
mod.file?.endsWith('.css') ||
|
|
16
|
+
mod.id?.includes('vue&type=style')) &&
|
|
17
|
+
mod.ssrModule) {
|
|
18
|
+
styles.set(mod.url, mod.ssrModule.default);
|
|
19
|
+
}
|
|
20
|
+
if (mod.importedModules.size > 0 && !checkedComponents.has(mod.id)) {
|
|
21
|
+
checkedComponents.add(mod.id);
|
|
22
|
+
collectCss({
|
|
23
|
+
mods: mod.importedModules,
|
|
24
|
+
styles,
|
|
25
|
+
checkedComponents
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
let result = '';
|
|
30
|
+
styles.forEach((content, id) => {
|
|
31
|
+
const styleTag = `<style type="text/css" vite-module-id="${hashCode(id)}">${content}</style>`;
|
|
32
|
+
result = result.concat(styleTag);
|
|
33
|
+
});
|
|
34
|
+
return result;
|
|
35
|
+
};
|
|
36
|
+
/**
|
|
37
|
+
* Client listener to detect updated modules through HMR, and remove the initial styled attached to the head
|
|
38
|
+
*/
|
|
39
|
+
export const removeCssHotReloaded = () => {
|
|
40
|
+
if (import.meta.hot) {
|
|
41
|
+
import.meta.hot.on('vite:beforeUpdate', (module) => {
|
|
42
|
+
module.updates.forEach((update) => {
|
|
43
|
+
const moduleStyle = document.querySelector(`[vite-module-id="${hashCode(update.acceptedPath)}"]`);
|
|
44
|
+
if (moduleStyle) {
|
|
45
|
+
moduleStyle.remove();
|
|
46
|
+
}
|
|
47
|
+
});
|
|
48
|
+
});
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
const hashCode = (moduleId) => {
|
|
52
|
+
let hash = 0, i, chr;
|
|
53
|
+
if (moduleId.length === 0)
|
|
54
|
+
return hash;
|
|
55
|
+
for (i = 0; i < moduleId.length; i++) {
|
|
56
|
+
chr = moduleId.charCodeAt(i);
|
|
57
|
+
hash = (hash << 5) - hash + chr;
|
|
58
|
+
hash |= 0; // Convert to 32bit integer
|
|
59
|
+
}
|
|
60
|
+
return hash;
|
|
61
|
+
};
|
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;
|