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.
Files changed (44) hide show
  1. package/README.md +2 -2
  2. package/dist/app-urls.js +1 -1
  3. package/dist/bin/build.js +9 -8
  4. package/dist/bin/cli.js +28 -6
  5. package/dist/bin/dev.js +73 -29
  6. package/dist/frameworks/vue/fastify-csr-plugin.js +38 -0
  7. package/dist/frameworks/vue/fastify-ssr-plugin.js +83 -18
  8. package/dist/frameworks/vue/server.js +10 -5
  9. package/dist/helpers/collect-css-ssr.js +61 -0
  10. package/dist/index.js +298 -77
  11. package/dist/plugins/quasar.js +30 -9
  12. package/dist/types/bin/build.d.ts +2 -2
  13. package/dist/types/bin/dev.d.ts +43 -4
  14. package/dist/types/frameworks/vue/fastify-csr-plugin.d.ts +17 -0
  15. package/dist/types/frameworks/vue/fastify-ssr-plugin.d.ts +6 -3
  16. package/dist/types/frameworks/vue/server.d.ts +10 -5
  17. package/dist/types/helpers/collect-css-ssr.d.ts +14 -0
  18. package/dist/types/helpers/routes.d.ts +1 -1
  19. package/dist/types/index.d.ts +4 -2
  20. package/dist/types/plugins/index.d.ts +1 -1
  21. package/dist/types/vitrify-config.d.ts +16 -5
  22. package/package.json +33 -32
  23. package/src/node/app-urls.ts +1 -1
  24. package/src/node/bin/build.ts +11 -10
  25. package/src/node/bin/cli.ts +35 -7
  26. package/src/node/bin/dev.ts +109 -38
  27. package/src/node/frameworks/vue/fastify-csr-plugin.ts +72 -0
  28. package/src/node/frameworks/vue/fastify-ssr-plugin.ts +99 -20
  29. package/src/node/frameworks/vue/server.ts +24 -9
  30. package/src/node/helpers/collect-css-ssr.ts +85 -0
  31. package/src/node/index.ts +338 -90
  32. package/src/node/plugins/index.ts +1 -1
  33. package/src/node/plugins/quasar.ts +40 -9
  34. package/src/node/vitrify-config.ts +20 -5
  35. package/src/vite/fastify/entry.ts +11 -0
  36. package/src/vite/fastify/server.ts +12 -0
  37. package/src/vite/vue/csr/app.ts +25 -0
  38. package/src/vite/vue/csr/fastify-csr-plugin.ts +3 -0
  39. package/src/vite/vue/csr/server.ts +8 -0
  40. package/src/vite/vue/index.html +1 -0
  41. package/src/vite/vue/main.ts +0 -1
  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/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: Record<string, any>
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 = (fastify: FastifyInstance) => any
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?: OnSetupHook[]
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,12 @@
1
+ import Fastify from 'fastify'
2
+ import { setup } from './entry'
3
+
4
+ const fastify = Fastify({
5
+ logger: true
6
+ })
7
+ await setup({ fastify })
8
+
9
+ fastify.listen({
10
+ port: Number(process.env.PORT || 3000),
11
+ host: process.env.HOST || '127.0.0.1'
12
+ })
@@ -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
+ }
@@ -0,0 +1,3 @@
1
+ import { fastifyCsrPlugin } from '../../../node/frameworks/vue/fastify-csr-plugin.js'
2
+
3
+ export { fastifyCsrPlugin }
@@ -0,0 +1,8 @@
1
+ import { setupApp } from './app.js'
2
+
3
+ const app = await setupApp()
4
+
5
+ app.listen({
6
+ port: Number(process.env.PORT || 3000),
7
+ host: process.env.HOST || '127.0.0.1'
8
+ })
@@ -10,6 +10,7 @@
10
10
  <body>
11
11
  <!-- Do not add whitespace or newlines to #app, this will cause hydration errors -->
12
12
  <div id="app"><!--app-html--></div>
13
+ <!--dev-ssr-css-->
13
14
  <!--entry-script-->
14
15
  <!--initial-state-->
15
16
  </body>
@@ -9,7 +9,6 @@ import {
9
9
  } from 'vue'
10
10
  import { onBoot, onMounted } from 'virtual:vitrify-hooks'
11
11
  import routes from 'src/router/routes'
12
- import 'virtual:global-css'
13
12
  import * as staticImports from 'virtual:static-imports'
14
13
 
15
14
  interface ssrContext {
@@ -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 '@vue/server-renderer'
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, setup } from 'virtual:vitrify-hooks'
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
- setup,
13
- appDir,
14
- baseUrl,
15
- onRendered
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.listen(process.env.PORT || 3000, process.env.HOST || '127.0.0.1')
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
+ })