vitrify 0.3.0 → 0.5.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 +2 -2
- package/dist/app-urls.js +1 -1
- package/dist/bin/build.js +9 -8
- package/dist/bin/cli.js +28 -6
- package/dist/bin/dev.js +73 -29
- package/dist/frameworks/vue/fastify-csr-plugin.js +38 -0
- package/dist/frameworks/vue/fastify-ssr-plugin.js +83 -18
- package/dist/frameworks/vue/server.js +10 -5
- package/dist/helpers/collect-css-ssr.js +61 -0
- package/dist/index.js +298 -77
- package/dist/plugins/quasar.js +30 -9
- package/dist/types/bin/build.d.ts +2 -2
- package/dist/types/bin/dev.d.ts +43 -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/server.d.ts +10 -5
- package/dist/types/helpers/collect-css-ssr.d.ts +14 -0
- 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 +16 -5
- package/package.json +33 -32
- package/src/node/app-urls.ts +1 -1
- package/src/node/bin/build.ts +11 -10
- package/src/node/bin/cli.ts +35 -7
- package/src/node/bin/dev.ts +109 -38
- package/src/node/frameworks/vue/fastify-csr-plugin.ts +72 -0
- package/src/node/frameworks/vue/fastify-ssr-plugin.ts +99 -20
- package/src/node/frameworks/vue/server.ts +24 -9
- package/src/node/helpers/collect-css-ssr.ts +85 -0
- package/src/node/index.ts +338 -90
- package/src/node/plugins/index.ts +1 -1
- package/src/node/plugins/quasar.ts +40 -9
- package/src/node/vitrify-config.ts +20 -5
- 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 +0 -1
- package/src/vite/vue/ssr/app.ts +25 -0
- package/src/vite/vue/ssr/entry-server.ts +13 -1
- package/src/vite/vue/ssr/server.ts +23 -14
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { FastifyInstance } from 'fastify'
|
|
2
|
-
import type { UserConfig } from 'vite'
|
|
2
|
+
import type { Alias, UserConfig } from 'vite'
|
|
3
3
|
import type { QuasarConf } from './plugins/quasar.js'
|
|
4
4
|
import type { ComponentInternalInstance } from '@vue/runtime-core'
|
|
5
5
|
|
|
@@ -19,7 +19,7 @@ export type OnBootHook = ({
|
|
|
19
19
|
}: {
|
|
20
20
|
app: any
|
|
21
21
|
ssrContext: Record<string, unknown>
|
|
22
|
-
staticImports
|
|
22
|
+
staticImports?: Record<string, any>
|
|
23
23
|
}) => Promise<void> | void
|
|
24
24
|
export type OnMountedHook = (
|
|
25
25
|
instance: ComponentInternalInstance
|
|
@@ -33,8 +33,11 @@ export type OnRenderedHook = (
|
|
|
33
33
|
html: string,
|
|
34
34
|
ssrContext: Record<string, any>
|
|
35
35
|
) => string
|
|
36
|
-
export type OnSetupHook = (
|
|
37
|
-
|
|
36
|
+
// export type OnSetupHook = (
|
|
37
|
+
// fastify: FastifyInstance,
|
|
38
|
+
// staticImports?: Record<string, any>
|
|
39
|
+
// ) => any
|
|
40
|
+
export type OnSetupFile = URL
|
|
38
41
|
export interface VitrifyConfig extends UserConfig {
|
|
39
42
|
vitrify?: {
|
|
40
43
|
/**
|
|
@@ -49,7 +52,7 @@ export interface VitrifyConfig extends UserConfig {
|
|
|
49
52
|
/**
|
|
50
53
|
* setup() is called directly after instantiating fastify. Use it to register your own plugins, routes etc.
|
|
51
54
|
*/
|
|
52
|
-
onSetup?:
|
|
55
|
+
onSetup?: OnSetupFile[]
|
|
53
56
|
/**
|
|
54
57
|
* Functions which run in the onMounted hook of the app
|
|
55
58
|
*/
|
|
@@ -84,6 +87,18 @@ export interface VitrifyConfig extends UserConfig {
|
|
|
84
87
|
cwd?: URL
|
|
85
88
|
packages?: Record<string, URL>
|
|
86
89
|
}
|
|
90
|
+
/**
|
|
91
|
+
* SSR specific configuration
|
|
92
|
+
*/
|
|
93
|
+
ssr?: {
|
|
94
|
+
serverModules?: string[]
|
|
95
|
+
}
|
|
96
|
+
/**
|
|
97
|
+
* Development only configuration
|
|
98
|
+
*/
|
|
99
|
+
dev?: {
|
|
100
|
+
alias?: Alias[]
|
|
101
|
+
}
|
|
87
102
|
}
|
|
88
103
|
quasar?: QuasarConf
|
|
89
104
|
}
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type { FastifyInstance } from 'fastify'
|
|
2
|
+
import { onSetup } from 'virtual:vitrify-hooks'
|
|
3
|
+
|
|
4
|
+
export const setup = async ({ fastify }: { fastify: FastifyInstance }) => {
|
|
5
|
+
if (onSetup?.length) {
|
|
6
|
+
for (const setup of onSetup) {
|
|
7
|
+
await setup(fastify)
|
|
8
|
+
}
|
|
9
|
+
}
|
|
10
|
+
return fastify
|
|
11
|
+
}
|
|
@@ -0,0 +1,25 @@
|
|
|
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 { onRendered, onSetup } from 'virtual:vitrify-hooks'
|
|
5
|
+
import { fastifyCsrPlugin } from './fastify-csr-plugin.js'
|
|
6
|
+
import type { ViteDevServer } from 'vite'
|
|
7
|
+
import * as imr from 'import-meta-resolve'
|
|
8
|
+
const { resolve } = imr
|
|
9
|
+
// const appDir = getPkgJsonDir(import.meta.url)
|
|
10
|
+
const getString = (str?: string) => str
|
|
11
|
+
let baseUrl = getString(__BASE_URL__)
|
|
12
|
+
const appDir = getAppDir()
|
|
13
|
+
|
|
14
|
+
export const setupApp = async () => {
|
|
15
|
+
const vitrifyDir = new URL('../', await resolve('vitrify', import.meta.url))
|
|
16
|
+
return createApp({
|
|
17
|
+
onSetup,
|
|
18
|
+
appDir,
|
|
19
|
+
baseUrl,
|
|
20
|
+
onRendered,
|
|
21
|
+
fastifyPlugin: fastifyCsrPlugin,
|
|
22
|
+
vitrifyDir,
|
|
23
|
+
mode: import.meta.env.MODE
|
|
24
|
+
})
|
|
25
|
+
}
|
package/src/vite/vue/index.html
CHANGED
package/src/vite/vue/main.ts
CHANGED
|
@@ -0,0 +1,25 @@
|
|
|
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 { onRendered, onSetup } from 'virtual:vitrify-hooks'
|
|
5
|
+
import { fastifySsrPlugin } from './fastify-ssr-plugin.js'
|
|
6
|
+
import type { ViteDevServer } from 'vite'
|
|
7
|
+
import * as imr from 'import-meta-resolve'
|
|
8
|
+
const { resolve } = imr
|
|
9
|
+
// const appDir = getPkgJsonDir(import.meta.url)
|
|
10
|
+
const getString = (str?: string) => str
|
|
11
|
+
let baseUrl = getString(__BASE_URL__)
|
|
12
|
+
const appDir = getAppDir()
|
|
13
|
+
|
|
14
|
+
export const setupApp = async () => {
|
|
15
|
+
const vitrifyDir = new URL('../', await resolve('vitrify', import.meta.url))
|
|
16
|
+
return createApp({
|
|
17
|
+
onSetup,
|
|
18
|
+
appDir,
|
|
19
|
+
baseUrl,
|
|
20
|
+
onRendered,
|
|
21
|
+
fastifyPlugin: fastifySsrPlugin,
|
|
22
|
+
vitrifyDir,
|
|
23
|
+
mode: import.meta.env.MODE
|
|
24
|
+
})
|
|
25
|
+
}
|
|
@@ -1,9 +1,21 @@
|
|
|
1
1
|
import { createApp } from '../main.js'
|
|
2
|
-
import { renderToString } from '
|
|
2
|
+
import { renderToString } from 'vue/server-renderer'
|
|
3
|
+
import type { FastifyInstance } from 'fastify'
|
|
3
4
|
// import * as ApolloSSR from '@vue/apollo-ssr'
|
|
4
5
|
// import { ApolloClients } from '@vue/apollo-composable'
|
|
5
6
|
// import serialize from 'serialize-javascript'
|
|
6
7
|
|
|
8
|
+
import { onSetup } from 'virtual:vitrify-hooks'
|
|
9
|
+
|
|
10
|
+
export const setup = async ({ fastify }: { fastify: FastifyInstance }) => {
|
|
11
|
+
if (onSetup?.length) {
|
|
12
|
+
for (const setup of onSetup) {
|
|
13
|
+
await setup(fastify)
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return fastify
|
|
17
|
+
}
|
|
18
|
+
|
|
7
19
|
const initializeApp = async (url, ssrContext) => {
|
|
8
20
|
const onRenderedList = []
|
|
9
21
|
Object.assign(ssrContext, {
|
|
@@ -1,18 +1,27 @@
|
|
|
1
|
-
import { createApp } from '../../../node/frameworks/vue/server.js'
|
|
2
|
-
import { getAppDir } from '../../../node/app-urls.js'
|
|
1
|
+
// import { createApp } from '../../../node/frameworks/vue/server.js'
|
|
2
|
+
// import { getAppDir } from '../../../node/app-urls.js'
|
|
3
3
|
// import { setup } from 'virtual:fastify-setup'
|
|
4
|
-
import { onRendered,
|
|
5
|
-
|
|
4
|
+
// import { onRendered, onSetup } from 'virtual:vitrify-hooks'
|
|
5
|
+
// import { fastifySsrPlugin } from './fastify-ssr-plugin.js'
|
|
6
|
+
import { setupApp } from './app.js'
|
|
7
|
+
// import * as staticImports from 'virtual:static-imports'
|
|
6
8
|
// const appDir = getPkgJsonDir(import.meta.url)
|
|
7
|
-
const getString = (str?: string) => str
|
|
8
|
-
let baseUrl = getString(__BASE_URL__)
|
|
9
|
-
const appDir = getAppDir()
|
|
9
|
+
// const getString = (str?: string) => str
|
|
10
|
+
// let baseUrl = getString(__BASE_URL__)
|
|
11
|
+
// const appDir = getAppDir()
|
|
10
12
|
|
|
11
|
-
const app = createApp({
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
13
|
+
// const app = createApp({
|
|
14
|
+
// onSetup,
|
|
15
|
+
// appDir,
|
|
16
|
+
// baseUrl,
|
|
17
|
+
// onRendered,
|
|
18
|
+
// fastifySsrPlugin,
|
|
19
|
+
// mode: import.meta.env.MODE
|
|
20
|
+
// })
|
|
17
21
|
|
|
18
|
-
app
|
|
22
|
+
const app = await setupApp()
|
|
23
|
+
|
|
24
|
+
app.listen({
|
|
25
|
+
port: Number(process.env.PORT || 3000),
|
|
26
|
+
host: process.env.HOST || '127.0.0.1'
|
|
27
|
+
})
|