vitrify 0.1.0 → 0.2.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.
Files changed (46) hide show
  1. package/README.md +86 -0
  2. package/dist/app-urls.js +36 -0
  3. package/dist/bin/build.js +73 -0
  4. package/dist/bin/cli.js +139 -0
  5. package/dist/bin/dev.js +108 -0
  6. package/dist/bin/run.js +29 -0
  7. package/dist/frameworks/vue/fastify-ssr-plugin.js +91 -0
  8. package/dist/frameworks/vue/prerender.js +29 -0
  9. package/dist/frameworks/vue/server.js +20 -0
  10. package/dist/helpers/logger.js +108 -0
  11. package/dist/helpers/routes.js +24 -0
  12. package/dist/helpers/utils.js +24 -0
  13. package/dist/index.js +341 -0
  14. package/dist/plugins/index.js +1 -0
  15. package/dist/plugins/quasar.js +299 -0
  16. package/dist/types/app-urls.d.ts +12 -0
  17. package/dist/types/bin/build.d.ts +8 -0
  18. package/dist/types/bin/cli.d.ts +2 -0
  19. package/dist/types/bin/dev.d.ts +15 -0
  20. package/dist/types/bin/run.d.ts +8 -0
  21. package/dist/types/bin/test.d.ts +3 -0
  22. package/dist/types/frameworks/vue/fastify-ssr-plugin.d.ts +14 -0
  23. package/dist/types/frameworks/vue/prerender.d.ts +8 -0
  24. package/dist/types/frameworks/vue/server.d.ts +9 -0
  25. package/dist/types/helpers/logger.d.ts +23 -0
  26. package/dist/types/helpers/routes.d.ts +2 -0
  27. package/dist/types/helpers/utils.d.ts +5 -0
  28. package/dist/types/index.d.ts +15 -0
  29. package/dist/types/plugins/index.d.ts +7 -0
  30. package/dist/types/plugins/quasar.d.ts +16 -0
  31. package/dist/types/vitrify-config.d.ts +67 -0
  32. package/dist/vitrify-config.js +1 -0
  33. package/package.json +94 -19
  34. package/src/node/frameworks/vue/fastify-ssr-plugin.ts +137 -0
  35. package/src/node/frameworks/vue/prerender.ts +49 -0
  36. package/src/node/frameworks/vue/server.ts +38 -0
  37. package/src/vite/vue/csr/entry.ts +8 -0
  38. package/src/vite/vue/index.html +16 -0
  39. package/src/vite/vue/main.ts +89 -0
  40. package/src/vite/vue/ssr/entry-client.ts +9 -0
  41. package/src/vite/vue/ssr/entry-server.ts +97 -0
  42. package/src/vite/vue/ssr/fastify-ssr-plugin.ts +120 -0
  43. package/src/vite/vue/ssr/prerender.ts +4 -0
  44. package/src/vite/vue/ssr/server.ts +18 -0
  45. package/src/vite/vue/ssr/server.ts.bak +61 -0
  46. package/src/vite/vue/ssr/tsconfig.json +9 -0
@@ -0,0 +1,120 @@
1
+ import { fastifySsrPlugin } from '../../../node/frameworks/vue/fastify-ssr-plugin.js'
2
+ import ssrFunctions from 'virtual:ssr-functions'
3
+
4
+ export { fastifySsrPlugin, ssrFunctions }
5
+
6
+ // import { FastifyPluginCallback, FastifyRequest, FastifyReply } from 'fastify'
7
+ // import fastifyStatic from 'fastify-static'
8
+ // import { readFileSync } from 'fs'
9
+ // import { injectSsrContext } from '../../node/helpers/ssr.js'
10
+ // import type { ViteDevServer } from 'vite'
11
+
12
+ // export interface FastifySsrOptions {
13
+ // baseUrl?: string
14
+ // provide?: (req: FastifyRequest, res: FastifyReply) => Promise<Record<string, unknown>>
15
+ // vite?: ViteDevServer
16
+ // cliDir?: URL
17
+ // appDir?: URL
18
+ // productName?: string
19
+ // }
20
+
21
+ // const fastifySsrPlugin: FastifyPluginCallback<FastifySsrOptions> = async (fastify, options, done) => {
22
+ // if (import.meta.env.MODE === 'development') {
23
+ // if (!options.vite) throw new Error('Option vite cannot be undefined')
24
+ // const middie = (await import('middie')).default
25
+ // await fastify.register(middie)
26
+ // fastify.use(options.vite.middlewares)
27
+
28
+ // fastify.get('*', async (req, res) => {
29
+ // try {
30
+ // // const url = req.originalUrl
31
+ // const url = req.raw.url
32
+ // let template
33
+ // let render
34
+ // const ssrContext = {
35
+ // req,
36
+ // res
37
+ // }
38
+ // // always read fresh template in dev
39
+ // // template = readFileSync(resolve('index.html'), 'utf-8')
40
+ // template = readFileSync(new URL('index.html', options.cliDir)).toString()
41
+
42
+ // // template = await vite.transformIndexHtml(url, template)
43
+ // const entryUrl = new URL('ssr/entry-server.ts', options.cliDir).pathname
44
+ // render = (await options.vite!.ssrLoadModule(entryUrl)).render
45
+ // let manifest
46
+ // // TODO: https://github.com/vitejs/vite/issues/2282
47
+ // try {
48
+ // manifest = {}
49
+ // } catch (e) {
50
+ // manifest = {}
51
+ // }
52
+
53
+ // const [appHtml, preloadLinks] = await render(url, manifest, ssrContext)
54
+ // const html = template
55
+ // .replace(`<!--preload-links-->`, preloadLinks)
56
+ // .replace(`<!--app-html-->`, appHtml)
57
+ // .replace('<!--product-name-->', options.productName || 'Product name')
58
+
59
+ // res.code(200)
60
+ // res.type('text/html')
61
+ // res.send(html)
62
+ // // res.status(200).set({ 'Content-Type': 'text/html' }).end(html)
63
+ // } catch (e: any) {
64
+ // console.error(e.stack)
65
+ // options.vite && options.vite.ssrFixStacktrace(e)
66
+ // res.code(500)
67
+ // res.send(e.stack)
68
+ // }
69
+ // })
70
+ // } else {
71
+ // options.baseUrl = options.baseUrl || '/'
72
+ // fastify.register(fastifyStatic, {
73
+ // root: new URL('./dist/ssr/client', options.appDir).pathname,
74
+ // wildcard: false,
75
+ // index: false,
76
+ // prefix: options.baseUrl
77
+ // })
78
+
79
+ // fastify.get(`${options.baseUrl}*`, async (req, res) => {
80
+ // const url = req.raw.url
81
+ // const provide = options.provide ? await options.provide(req, res) : {}
82
+ // let template
83
+ // let render
84
+ // let manifest
85
+ // const ssrContext: Record<string, any> = {
86
+ // req,
87
+ // res,
88
+ // provide
89
+ // }
90
+
91
+ // // template = readFileSync(new URL('../client/index.html', import.meta.url).pathname).toString()
92
+ // // manifest = JSON.parse(readFileSync(new URL('../client/ssr-manifest.json', import.meta.url)).toString())
93
+ // // render = (await import(new URL('./entry-server.mjs', import.meta.url).pathname)).render
94
+ // template = readFileSync(new URL('./dist/ssr/client/index.html', options.appDir).pathname).toString()
95
+ // manifest = JSON.parse(readFileSync(new URL('./dist/ssr/client/ssr-manifest.json', options.appDir)).toString())
96
+ // render = (await import(new URL('./dist/ssr/server/entry-server.mjs', options.appDir).pathname)).render
97
+
98
+ // const [appHtml, preloadLinks] = await render(url, manifest, ssrContext)
99
+
100
+ // if (!ssrContext.initialState) ssrContext.initialState = {}
101
+ // ssrContext.initialState.provide = provide
102
+
103
+ // let html = template
104
+ // .replace(`<!--preload-links-->`, preloadLinks)
105
+ // .replace(`<!--app-html-->`, appHtml)
106
+ // html = injectSsrContext(html, ssrContext)
107
+
108
+ // res.code(200)
109
+ // res.type('text/html')
110
+ // res.send(html)
111
+ // })
112
+ // }
113
+
114
+ // done()
115
+
116
+ // }
117
+
118
+ // export {
119
+ // fastifySsrPlugin
120
+ // }
@@ -0,0 +1,4 @@
1
+ import { prerender } from '../../../node/frameworks/vue/prerender.js'
2
+ import ssrFunctions from 'virtual:ssr-functions'
3
+
4
+ export { prerender, ssrFunctions }
@@ -0,0 +1,18 @@
1
+ import { createApp } from '../../../node/frameworks/vue/server.js'
2
+ import { getAppDir } from '../../../node/app-urls.js'
3
+ import { setup } from 'virtual:fastify-setup'
4
+ import ssrFunctions from 'virtual:ssr-functions'
5
+
6
+ // const appDir = getPkgJsonDir(import.meta.url)
7
+ const getString = (str?: string) => str
8
+ let baseUrl = getString(__BASE_URL__)
9
+ const appDir = getAppDir()
10
+
11
+ const app = createApp({
12
+ setup,
13
+ appDir,
14
+ baseUrl,
15
+ ssrFunctions
16
+ })
17
+
18
+ app.listen(process.env.PORT || 3000, process.env.HOST || '127.0.0.1')
@@ -0,0 +1,61 @@
1
+ import fastify, { FastifyInstance } from 'fastify'
2
+ import { readFileSync } from 'fs'
3
+ import fastifyStatic from 'fastify-static'
4
+ import { resolve } from 'path'
5
+ import sensible from 'fastify-sensible'
6
+ import { injectSsrContext } from '../src/helpers/ssr.js'
7
+ import { setup } from 'virtual:fastify-setup'
8
+ export const createApp = ({
9
+ setup
10
+ }: {
11
+ setup: (fastify: FastifyInstance) => any
12
+ }) => {
13
+ const app = fastify({
14
+ logger: true
15
+ })
16
+
17
+ app.register(sensible)
18
+
19
+ setup(app)
20
+
21
+ app.register(fastifyStatic, {
22
+ root: resolve('../client'),
23
+ wildcard: false,
24
+ index: false
25
+ })
26
+
27
+ app.get('*', async (req, res) => {
28
+ const url = req.raw.url
29
+
30
+ let template
31
+ let render
32
+ let manifest
33
+ const ssrContext = {
34
+ req,
35
+ res
36
+ }
37
+ template = readFileSync(resolve('../client/index.html')).toString()
38
+ manifest = JSON.parse(readFileSync(resolve('../client/ssr-manifest.json')).toString())
39
+ render = (await import(resolve('./entry-server.mjs'))).render
40
+
41
+ const [appHtml, preloadLinks] = await render(url, manifest, ssrContext)
42
+
43
+ let html = template
44
+ .replace(`<!--preload-links-->`, preloadLinks)
45
+ .replace(`<!--app-html-->`, appHtml)
46
+ .replace('<!--initial-state-->', ssrContext.initialState)
47
+ html = injectSsrContext(html, ssrContext)
48
+
49
+ res.code(200)
50
+ res.type('text/html')
51
+ res.send(html)
52
+ })
53
+
54
+ return app
55
+ }
56
+
57
+ const app = createApp({
58
+ setup
59
+ })
60
+
61
+ app.listen(process.env.PORT || 3000, process.env.HOST || '127.0.0.1')
@@ -0,0 +1,9 @@
1
+ {
2
+ "compilerOptions": {
3
+ "strict": true,
4
+ "module": "esnext",
5
+ "moduleResolution": "Node",
6
+ "target": "esnext",
7
+ "types": ["vite/client"]
8
+ }
9
+ }