vitrify 0.2.4 → 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.
Files changed (47) hide show
  1. package/dist/app-urls.js +1 -2
  2. package/dist/bin/build.js +0 -43
  3. package/dist/bin/cli.js +29 -7
  4. package/dist/bin/dev.js +58 -67
  5. package/dist/frameworks/vue/fastify-ssr-plugin.js +67 -23
  6. package/dist/frameworks/vue/prerender.js +3 -3
  7. package/dist/frameworks/vue/server.js +9 -10
  8. package/dist/helpers/collect-css-ssr.js +57 -0
  9. package/dist/helpers/logger.js +0 -72
  10. package/dist/index.js +268 -122
  11. package/dist/plugins/quasar.js +13 -106
  12. package/dist/types/bin/build.d.ts +2 -2
  13. package/dist/types/bin/dev.d.ts +39 -3
  14. package/dist/types/frameworks/vue/fastify-ssr-plugin.d.ts +6 -3
  15. package/dist/types/frameworks/vue/prerender.d.ts +3 -3
  16. package/dist/types/frameworks/vue/server.d.ts +9 -5
  17. package/dist/types/helpers/collect-css-ssr.d.ts +10 -0
  18. package/dist/types/helpers/logger.d.ts +0 -19
  19. package/dist/types/helpers/routes.d.ts +1 -1
  20. package/dist/types/index.d.ts +1 -1
  21. package/dist/types/plugins/index.d.ts +1 -1
  22. package/dist/types/vitrify-config.d.ts +20 -16
  23. package/package.json +32 -32
  24. package/src/node/app-urls.ts +1 -2
  25. package/src/node/bin/build.ts +2 -49
  26. package/src/node/bin/cli.ts +36 -8
  27. package/src/node/bin/dev.ts +89 -75
  28. package/src/node/bin/test.ts +0 -3
  29. package/src/node/frameworks/vue/fastify-ssr-plugin.ts +80 -26
  30. package/src/node/frameworks/vue/prerender.ts +5 -5
  31. package/src/node/frameworks/vue/server.ts +22 -16
  32. package/src/node/helpers/collect-css-ssr.ts +77 -0
  33. package/src/node/helpers/logger.ts +0 -87
  34. package/src/node/index.ts +302 -137
  35. package/src/node/plugins/index.ts +1 -1
  36. package/src/node/plugins/quasar.ts +14 -111
  37. package/src/node/vitrify-config.ts +31 -16
  38. package/src/vite/fastify/entry.ts +11 -0
  39. package/src/vite/fastify/server.ts +10 -0
  40. package/src/vite/vue/index.html +1 -0
  41. package/src/vite/vue/main.ts +5 -20
  42. package/src/vite/vue/ssr/app.ts +25 -0
  43. package/src/vite/vue/ssr/entry-server.ts +13 -1
  44. package/src/vite/vue/ssr/fastify-ssr-plugin.ts +2 -118
  45. package/src/vite/vue/ssr/prerender.ts +2 -2
  46. package/src/vite/vue/ssr/server.ts +24 -15
  47. package/src/node/helpers/ssr.ts.bak +0 -52
@@ -0,0 +1,77 @@
1
+ // collect-css-ssr.ts
2
+ import type { ViteDevServer, ModuleNode, UpdatePayload } from 'vite'
3
+
4
+ /**
5
+ * Collect SSR CSS for Vite
6
+ */
7
+ export const componentsModules = (
8
+ components: string[],
9
+ vite: ViteDevServer
10
+ ) => {
11
+ const matchedModules = new Set<ModuleNode>()
12
+ components.forEach((component) => {
13
+ const modules = vite.moduleGraph.getModulesByFile(component)
14
+ modules?.forEach((mod) => matchedModules.add(mod))
15
+ })
16
+ return matchedModules
17
+ }
18
+
19
+ export const collectCss = (
20
+ mods: Set<ModuleNode>,
21
+ styles = new Map<string, string>(),
22
+ checkedComponents = new Set()
23
+ ) => {
24
+ for (const mod of mods) {
25
+ if (
26
+ (mod.file?.endsWith('.scss') ||
27
+ mod.file?.endsWith('.css') ||
28
+ mod.id?.includes('vue&type=style')) &&
29
+ mod.ssrModule
30
+ ) {
31
+ styles.set(mod.url, mod.ssrModule.default)
32
+ }
33
+ if (mod.importedModules.size > 0 && !checkedComponents.has(mod.id)) {
34
+ checkedComponents.add(mod.id)
35
+ collectCss(mod.importedModules, styles, checkedComponents)
36
+ }
37
+ }
38
+ let result = ''
39
+ styles.forEach((content, id) => {
40
+ const styleTag = `<style type="text/css" vite-module-id="${hashCode(
41
+ id
42
+ )}">${content}</style>`
43
+ result = result.concat(styleTag)
44
+ })
45
+ return result
46
+ }
47
+
48
+ /**
49
+ * Client listener to detect updated modules through HMR, and remove the initial styled attached to the head
50
+ */
51
+ export const removeCssHotReloaded = () => {
52
+ if (import.meta.hot) {
53
+ import.meta.hot.on('vite:beforeUpdate', (module: UpdatePayload) => {
54
+ module.updates.forEach((update) => {
55
+ const moduleStyle = document.querySelector(
56
+ `[vite-module-id="${hashCode(update.acceptedPath)}"]`
57
+ )
58
+ if (moduleStyle) {
59
+ moduleStyle.remove()
60
+ }
61
+ })
62
+ })
63
+ }
64
+ }
65
+
66
+ const hashCode = (moduleId: string) => {
67
+ let hash = 0,
68
+ i,
69
+ chr
70
+ if (moduleId.length === 0) return hash
71
+ for (i = 0; i < moduleId.length; i++) {
72
+ chr = moduleId.charCodeAt(i)
73
+ hash = (hash << 5) - hash + chr
74
+ hash |= 0 // Convert to 32bit integer
75
+ }
76
+ return hash
77
+ }
@@ -1,98 +1,11 @@
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 type { AddressInfo, Server } from 'net'
6
4
  import type { ResolvedConfig, Logger } from 'vite'
7
5
  import os from 'os'
8
6
  import type { Hostname } from '../helpers/utils.js'
9
7
  import { resolveHostname } from '../helpers/utils.js'
10
8
 
11
- /**
12
- * Main approach - App CLI related
13
- */
14
-
15
- const dot = '•'
16
- const banner = 'App ' + dot
17
- const greenBanner = green(banner)
18
- const redBanner = red(banner)
19
- const yellowBanner = yellow(banner)
20
-
21
- export const clearConsole = process.stdout.isTTY
22
- ? () => {
23
- // Fill screen with blank lines. Then move to 0 (beginning of visible part) and clear it
24
- const blank = '\n'.repeat(process.stdout.rows)
25
- console.log(blank)
26
- readline.cursorTo(process.stdout, 0, 0)
27
- readline.clearScreenDown(process.stdout)
28
- }
29
- : () => {}
30
-
31
- export const log = function (msg?: string) {
32
- console.log(msg ? ` ${greenBanner} ${msg}` : '')
33
- }
34
-
35
- export const warn = function (msg?: string, pill?: string) {
36
- if (msg !== void 0) {
37
- const pillBanner = pill !== void 0 ? bgYellow.black('', pill, '') + ' ' : ''
38
-
39
- console.warn(` ${yellowBanner} ⚠️ ${pillBanner}${msg}`)
40
- } else {
41
- console.warn()
42
- }
43
- }
44
-
45
- export const fatal = function (msg?: string, pill?: string) {
46
- if (msg !== void 0) {
47
- const pillBanner = pill !== void 0 ? errorPill(pill) + ' ' : ''
48
-
49
- console.error(`\n ${redBanner} ⚠️ ${pillBanner}${msg}\n`)
50
- } else {
51
- console.error()
52
- }
53
-
54
- process.exit(1)
55
- }
56
-
57
- /**
58
- * Extended approach - Compilation status & pills
59
- */
60
-
61
- export const successPill = (msg?: string) => bgGreen.black('', msg, '')
62
- export const infoPill = (msg?: string) => inverse('', msg, '')
63
- export const errorPill = (msg?: string) => bgRed.white('', msg, '')
64
- export const warningPill = (msg?: string) => bgYellow.black('', msg, '')
65
-
66
- export const success = function (msg?: string, title = 'SUCCESS') {
67
- console.log(` ${greenBanner} ${successPill(title)} ${green(dot + ' ' + msg)}`)
68
- }
69
- export const getSuccess = function (msg?: string, title?: string) {
70
- return ` ${greenBanner} ${successPill(title)} ${green(dot + ' ' + msg)}`
71
- }
72
-
73
- export const info = function (msg?: string, title = 'INFO') {
74
- console.log(` ${greenBanner} ${infoPill(title)} ${green(dot)} ${msg}`)
75
- }
76
- export const getInfo = function (msg?: string, title?: string) {
77
- return ` ${greenBanner} ${infoPill(title)} ${green(dot)} ${msg}`
78
- }
79
-
80
- export const error = function (msg?: string, title = 'ERROR') {
81
- console.log(` ${redBanner} ${errorPill(title)} ${red(dot + ' ' + msg)}`)
82
- }
83
- export const getError = function (msg?: string, title = 'ERROR') {
84
- return ` ${redBanner} ${errorPill(title)} ${red(dot + ' ' + msg)}`
85
- }
86
-
87
- export const warning = function (msg?: string, title = 'WARNING') {
88
- console.log(
89
- ` ${yellowBanner} ${warningPill(title)} ${yellow(dot + ' ' + msg)}`
90
- )
91
- }
92
- export const getWarning = function (msg?: string, title = 'WARNING') {
93
- return ` ${yellowBanner} ${warningPill(title)} ${yellow(dot + ' ' + msg)}`
94
- }
95
-
96
9
  export function printHttpServerUrls(
97
10
  server: Server,
98
11
  config: ResolvedConfig