@revojs/vue 0.1.0

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.
@@ -0,0 +1,7 @@
1
+ import { App, Module } from "revojs";
2
+
3
+ //#region src/index.d.ts
4
+ declare function addPages(app: App, path: string): void;
5
+ declare function vue(): Module;
6
+ //#endregion
7
+ export { addPages, vue };
package/dist/index.js ADDED
@@ -0,0 +1,24 @@
1
+ import { addRoutes, useKit } from "revojs/vite";
2
+
3
+ //#region src/index.ts
4
+ function addPages(app, path) {
5
+ app.config.sources.pages?.entries.push(path);
6
+ }
7
+ function vue() {
8
+ return {
9
+ config: { sources: { pages: {
10
+ match: "**/*.vue",
11
+ entries: ["./routes"]
12
+ } } },
13
+ setup(app) {
14
+ const { toPath, addAlias } = useKit(app, import.meta.url);
15
+ app.config.client = toPath("./module/index.html");
16
+ addRoutes(app, toPath("./module/routes"));
17
+ addAlias("vue/app", "./module/app.ts");
18
+ addAlias("vue/main", "./module/main.vue");
19
+ }
20
+ };
21
+ }
22
+
23
+ //#endregion
24
+ export { addPages, vue };
@@ -0,0 +1,47 @@
1
+ import { isServer, Radix, toRoutePath, type Node, type Route } from "revojs";
2
+ import { type Component, createSSRApp } from "vue";
3
+ import { createMemoryHistory, createRouter, createWebHistory, RouterView, type RouteRecordRaw } from "vue-router";
4
+ import Main from "#alias/vue/main";
5
+ import pages from "#virtual/pages";
6
+
7
+ function toRoute(path: string, node: Node<Component>): RouteRecordRaw {
8
+ const layout = node.children["+layout"];
9
+
10
+ if (layout) {
11
+ delete node.children["+layout"];
12
+ }
13
+
14
+ const children = Object.entries(node.children).map(([path, node]) => toRoute(path, node));
15
+
16
+ if (node.value && (children.length || layout)) {
17
+ children.push({ path: "", component: node.value });
18
+ }
19
+
20
+ const route = {
21
+ path,
22
+ children,
23
+ component: children.length ? (layout?.value ?? RouterView) : (node.value ?? RouterView),
24
+ };
25
+
26
+ return route;
27
+ }
28
+
29
+ export default () => {
30
+ const radix = new Radix<Component>();
31
+
32
+ for (const name in pages) {
33
+ const [path] = toRoutePath(name);
34
+
35
+ const Page = pages[name];
36
+ if (Page) {
37
+ radix.use(path, Page);
38
+ }
39
+ }
40
+
41
+ const router = createRouter({
42
+ history: isServer() ? createMemoryHistory() : createWebHistory(),
43
+ routes: Object.entries(radix.rootNode.children).map(([path, node]) => toRoute(path, node)),
44
+ });
45
+
46
+ return createSSRApp(Main).use(router);
47
+ };
@@ -0,0 +1,16 @@
1
+ <!doctype html>
2
+ <html lang="en">
3
+ <head>
4
+ <meta charset="UTF-8" />
5
+ <meta name="viewport" content="width=device-width, initial-scale=1.0" />
6
+ <title>Vue</title>
7
+ </head>
8
+ <body>
9
+ <div id="app"><!-- MAIN --></div>
10
+ <script type="module">
11
+ import createApp from "#alias/vue/app";
12
+
13
+ createApp().mount("#app");
14
+ </script>
15
+ </body>
16
+ </html>
@@ -0,0 +1,3 @@
1
+ <template>
2
+ <RouterView />
3
+ </template>
@@ -0,0 +1,10 @@
1
+ import { defineRoute, sendHtml } from "revojs";
2
+ import { renderToString } from "vue/server-renderer";
3
+ import createApp from "#alias/vue/app";
4
+ import client from "#virtual/client";
5
+
6
+ export default defineRoute({
7
+ async fetch(scope) {
8
+ return sendHtml(scope, client.replace("<!-- MAIN -->", await renderToString(createApp())));
9
+ },
10
+ });
package/package.json ADDED
@@ -0,0 +1,36 @@
1
+ {
2
+ "name": "@revojs/vue",
3
+ "version": "0.1.0",
4
+ "type": "module",
5
+ "repository": "coverbase/revojs",
6
+ "license": "MIT",
7
+ "exports": {
8
+ ".": {
9
+ "types": "./dist/index.d.ts",
10
+ "import": "./dist/index.js"
11
+ },
12
+ "./types": {
13
+ "types": "./src/types/index.d.ts"
14
+ }
15
+ },
16
+ "types": "./dist/index.d.ts",
17
+ "module": "./dist/index.js",
18
+ "main": "./dist/index.js",
19
+ "files": [
20
+ "dist",
21
+ "src/types"
22
+ ],
23
+ "scripts": {
24
+ "build": "tsdown",
25
+ "watch": "tsdown -w"
26
+ },
27
+ "dependencies": {
28
+ "revojs": "*",
29
+ "vue": "^3.5.19",
30
+ "vue-router": "^4.5.1"
31
+ },
32
+ "devDependencies": {
33
+ "@revojs/tsconfig": "*",
34
+ "tsdown": "^0.15.1"
35
+ }
36
+ }
@@ -0,0 +1,28 @@
1
+ declare module "#alias/vue/app" {
2
+ import type { App } from "vue";
3
+
4
+ export default function createApp(): App;
5
+ }
6
+
7
+ declare module "#alias/vue/main" {
8
+ import type { Component } from "vue";
9
+
10
+ const main: Component;
11
+
12
+ export default app;
13
+ }
14
+
15
+ declare module "#virtual/pages" {
16
+ import type { Component } from "vue";
17
+
18
+ const pages: Record<string, Component>;
19
+
20
+ export default pages;
21
+ }
22
+
23
+ declare module "*.vue" {
24
+ import type { DefineComponent } from "vue";
25
+
26
+ const component: DefineComponent<Record<string, never>, Record<string, never>, any>;
27
+ export default component;
28
+ }