@revojs/vue 0.1.30 → 0.1.32

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.
@@ -20,6 +20,7 @@ declare function useFetch<T, TError = Error>(scope: Scope, input: string | URL,
20
20
  refresh: (options?: AsyncOptions<TError> | undefined) => Promise<T | undefined>;
21
21
  }>;
22
22
  declare function refreshAsync(scope: Scope, input?: string | Array<string>): Promise<void[] | undefined>;
23
+ declare const isServerSideRendering: boolean;
23
24
  declare const REFRESH_ASYNC_HOOK: revojs0.Descriptor<(names?: Array<string>) => Promise<void>>;
24
25
  //#endregion
25
- export { AsyncOptions, REFRESH_ASYNC_HOOK, refreshAsync, useAsync, useFetch, useScope, useState };
26
+ export { AsyncOptions, REFRESH_ASYNC_HOOK, isServerSideRendering, refreshAsync, useAsync, useFetch, useScope, useState };
@@ -54,7 +54,8 @@ function useFetch(scope, input, options) {
54
54
  async function refreshAsync(scope, input) {
55
55
  if (isClient) return await scope.dispatchHook(REFRESH_ASYNC_HOOK, input === void 0 ? void 0 : Array.isArray(input) ? input : [input]);
56
56
  }
57
+ const isServerSideRendering = import.meta.SERVER_SIDE_RENDERING ?? globalThis?.import?.meta?.SERVER_SIDE_RENDERING;
57
58
  const REFRESH_ASYNC_HOOK = defineHook("REFRESH_ASYNC_HOOK");
58
59
 
59
60
  //#endregion
60
- export { REFRESH_ASYNC_HOOK, refreshAsync, useAsync, useFetch, useScope, useState };
61
+ export { REFRESH_ASYNC_HOOK, isServerSideRendering, refreshAsync, useAsync, useFetch, useScope, useState };
package/dist/index.d.ts CHANGED
@@ -1,7 +1,10 @@
1
1
  import { App, Module } from "revojs";
2
2
 
3
3
  //#region src/index.d.ts
4
+ interface VueOptions {
5
+ serverSideRendering?: boolean;
6
+ }
4
7
  declare function addPages(app: App, path: string): void;
5
- declare function vue(): Module;
8
+ declare function vue(options?: VueOptions): Module;
6
9
  //#endregion
7
- export { addPages, vue };
10
+ export { VueOptions, addPages, vue };
package/dist/index.js CHANGED
@@ -4,12 +4,15 @@ import { addAlias, addRoutes, addTypes, useKit } from "revojs/kit";
4
4
  function addPages(app, path) {
5
5
  app.config.sources.pages?.entries.push(path);
6
6
  }
7
- function vue() {
7
+ function vue(options) {
8
8
  return {
9
- config: { sources: { pages: {
10
- match: "**/{page,layout}.vue",
11
- entries: ["./routes"]
12
- } } },
9
+ config: {
10
+ variables: { SERVER_SIDE_RENDERING: options?.serverSideRendering ?? true },
11
+ sources: { pages: {
12
+ match: "**/{page,layout}.vue",
13
+ entries: ["./routes"]
14
+ } }
15
+ },
13
16
  setup(app) {
14
17
  const { fromModule } = useKit(import.meta.url);
15
18
  app.config.template.head.children.push({
@@ -1,7 +1,7 @@
1
1
  import Main from "#alias/vue/main";
2
2
  import pages from "#virtual/pages";
3
3
  import { isServer, Radix, Scope, useUrl, type Node } from "revojs";
4
- import { createSSRApp, type Component } from "vue";
4
+ import { createApp, createSSRApp, type Component } from "vue";
5
5
  import {
6
6
  createMemoryHistory,
7
7
  createRouter,
@@ -10,6 +10,7 @@ import {
10
10
  RouterView,
11
11
  type RouteRecordRaw,
12
12
  } from "vue-router";
13
+ import { isServerSideRendering } from "../client";
13
14
 
14
15
  function toRoute(path: string, node: Node<Component>, index: number): RouteRecordRaw {
15
16
  const layout = node.children["layout"];
@@ -70,7 +71,9 @@ export default async (scope: Scope) => {
70
71
  routes: [rootNode],
71
72
  });
72
73
 
73
- const app = createSSRApp(Main).use(router).provide("REVOJS_SCOPE", scope);
74
+ const app = (isServerSideRendering ? createSSRApp(Main) : createApp(Main))
75
+ .use(router)
76
+ .provide("REVOJS_SCOPE", scope);
74
77
 
75
78
  app.config.throwUnhandledErrorInProduction = true;
76
79
 
@@ -2,27 +2,33 @@ import createApp from "#alias/vue/app";
2
2
  import client from "#virtual/client";
3
3
  import { defineRoute, sendHtml, useServer } from "revojs";
4
4
  import { renderToString } from "vue/server-renderer";
5
+ import { isServerSideRendering } from "../../../client";
5
6
 
6
7
  export default defineRoute({
7
8
  async fetch(scope) {
8
9
  const { states } = useServer(scope);
9
10
 
10
- const app = await createApp(scope);
11
+ let content = client;
11
12
 
12
- let exception;
13
- app.config.errorHandler = (value) => (exception = value);
13
+ if (isServerSideRendering) {
14
+ const app = await createApp(scope);
14
15
 
15
- const content = client
16
- .replace("<!-- BODY -->", await renderToString(app))
17
- .replace(
18
- "<!-- HEAD -->",
19
- "<script id='STATES' type='application/json'>" + JSON.stringify(states) + "</script>"
20
- );
16
+ let exception;
17
+ app.config.errorHandler = (value) => (exception = value);
18
+
19
+ content = content.replace("<!-- BODY -->", await renderToString(app));
21
20
 
22
- if (exception) {
23
- throw exception;
21
+ if (exception) {
22
+ throw exception;
23
+ }
24
24
  }
25
25
 
26
- return sendHtml(scope, content);
26
+ return sendHtml(
27
+ scope,
28
+ content.replace(
29
+ "<!-- HEAD -->",
30
+ "<script id='STATES' type='application/json'>" + JSON.stringify(states) + "</script>"
31
+ )
32
+ );
27
33
  },
28
34
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@revojs/vue",
3
- "version": "0.1.30",
3
+ "version": "0.1.32",
4
4
  "type": "module",
5
5
  "repository": "coverbase/revojs",
6
6
  "license": "MIT",
@@ -26,3 +26,7 @@ declare module "*.vue" {
26
26
  const component: DefineComponent<Record<string, never>, Record<string, never>, any>;
27
27
  export default component;
28
28
  }
29
+
30
+ interface ImportMeta {
31
+ readonly SERVER_SIDE_RENDERING: boolean;
32
+ }