vitrify 0.1.0 → 0.1.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 +86 -0
- package/dist/app-urls.js +32 -0
- package/dist/bin/build.js +73 -0
- package/dist/bin/cli.js +137 -0
- package/dist/bin/dev.js +106 -0
- package/dist/bin/run.js +26 -0
- package/dist/helpers/logger.js +108 -0
- package/dist/helpers/routes.js +24 -0
- package/dist/helpers/utils.js +24 -0
- package/dist/index.js +288 -0
- package/dist/plugins/index.js +1 -0
- package/dist/plugins/quasar.js +294 -0
- package/dist/types/app-urls.d.ts +11 -0
- package/dist/types/bin/build.d.ts +8 -0
- package/dist/types/bin/cli.d.ts +2 -0
- package/dist/types/bin/dev.d.ts +15 -0
- package/dist/types/bin/run.d.ts +8 -0
- package/dist/types/bin/test.d.ts +3 -0
- package/dist/types/helpers/logger.d.ts +23 -0
- package/dist/types/helpers/routes.d.ts +2 -0
- package/dist/types/helpers/utils.d.ts +5 -0
- package/dist/types/index.d.ts +15 -0
- package/dist/types/plugins/index.d.ts +7 -0
- package/dist/types/plugins/quasar.d.ts +16 -0
- package/dist/types/vitrify-config.d.ts +64 -0
- package/dist/types/vue/fastify-ssr-plugin.d.ts +14 -0
- package/dist/types/vue/prerender.d.ts +8 -0
- package/dist/types/vue/server.d.ts +9 -0
- package/dist/vitrify-config.js +1 -0
- package/dist/vue/fastify-ssr-plugin.js +91 -0
- package/dist/vue/prerender.js +29 -0
- package/dist/vue/server.js +20 -0
- package/package.json +94 -18
- package/src/vite/vue/components.d.ts +25 -0
- package/src/vite/vue/csr/entry.ts +8 -0
- package/src/vite/vue/index.html +16 -0
- package/src/vite/vue/main.ts +89 -0
- package/src/vite/vue/ssr/entry-client.ts +9 -0
- package/src/vite/vue/ssr/entry-server.ts +97 -0
- package/src/vite/vue/ssr/fastify-ssr-plugin.ts +120 -0
- package/src/vite/vue/ssr/prerender.ts +4 -0
- package/src/vite/vue/ssr/server.ts +15 -0
- package/src/vite/vue/ssr/server.ts.bak +61 -0
- package/src/vite/vue/ssr/tsconfig.json +9 -0
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { fastifySsrPlugin } from '../../../node/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,15 @@
|
|
|
1
|
+
import { createApp } from '../../../node/vue/server.js'
|
|
2
|
+
import { appDir } from '../../../node/app-urls.js'
|
|
3
|
+
import { setup } from 'virtual:fastify-setup'
|
|
4
|
+
|
|
5
|
+
// const appDir = getPkgJsonDir(import.meta.url)
|
|
6
|
+
const getString = (str?: string) => str
|
|
7
|
+
let baseUrl = getString(__BASE_URL__)
|
|
8
|
+
|
|
9
|
+
const app = createApp({
|
|
10
|
+
setup,
|
|
11
|
+
appDir,
|
|
12
|
+
baseUrl
|
|
13
|
+
})
|
|
14
|
+
|
|
15
|
+
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')
|