@vixt/react 0.6.3 → 0.6.4
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/dist/client/App.tsx +17 -0
- package/dist/client/entry.js +3 -3
- package/dist/index.mjs +26 -10
- package/package.json +3 -2
- package/src/client/App.tsx +17 -0
- package/src/client/entry.ts +1 -1
- package/src/modules/virtual-root-component.ts +33 -13
- package/tsdown.config.ts +3 -1
- package/dist/client/App.d.ts +0 -7
- package/dist/client/App.js +0 -14
- package/src/client/App.ts +0 -15
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import routes from '~react-pages'
|
|
3
|
+
import { BrowserRouter, useRoutes } from 'react-router'
|
|
4
|
+
import appConfig from 'virtual:vixt:app-config'
|
|
5
|
+
import { setupLayouts } from 'virtual:vixt:setup-layouts'
|
|
6
|
+
|
|
7
|
+
function App() {
|
|
8
|
+
const routesWithLayouts = setupLayouts(routes)
|
|
9
|
+
const Routes = () => useRoutes(routesWithLayouts)
|
|
10
|
+
return (
|
|
11
|
+
<BrowserRouter basename={appConfig.baseURL}>
|
|
12
|
+
<Routes />
|
|
13
|
+
</BrowserRouter>
|
|
14
|
+
)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default App
|
package/dist/client/entry.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { createElement } from "react";
|
|
2
|
-
import appConfig from "virtual:vixt:app-config";
|
|
3
1
|
import "virtual:vixt:css";
|
|
4
2
|
import "virtual:uno.css";
|
|
5
3
|
import { applyPlugins, createVixtApp } from "@vixt/core/client";
|
|
4
|
+
import { createElement } from "react";
|
|
6
5
|
import { createRoot } from "react-dom/client";
|
|
6
|
+
import appConfig from "virtual:vixt:app-config";
|
|
7
7
|
import plugins from "virtual:vixt:plugins";
|
|
8
|
-
import RootComponent from "virtual:vixt:root-component";
|
|
8
|
+
import RootComponent from "virtual:vixt:root-component.tsx";
|
|
9
9
|
|
|
10
10
|
//#region src/client/entry.ts
|
|
11
11
|
async function entry() {
|
package/dist/index.mjs
CHANGED
|
@@ -16,6 +16,7 @@ import fg from "fast-glob";
|
|
|
16
16
|
import { pascalCase } from "unplugin-vue-components";
|
|
17
17
|
import extractComments from "extract-comments";
|
|
18
18
|
import { parse } from "yaml";
|
|
19
|
+
import { parseAst } from "vite";
|
|
19
20
|
|
|
20
21
|
//#region rolldown:runtime
|
|
21
22
|
var __create = Object.create;
|
|
@@ -8789,28 +8790,43 @@ var preset_react_default = defineVixtModule({
|
|
|
8789
8790
|
|
|
8790
8791
|
//#endregion
|
|
8791
8792
|
//#region src/modules/virtual-root-component.ts
|
|
8792
|
-
function
|
|
8793
|
+
function resolveRootComponent(vixt) {
|
|
8793
8794
|
for (const layer of vixt._layers) {
|
|
8794
8795
|
const layerRootComponentPath = posix.resolve(layer.config.srcDir, "App.tsx");
|
|
8795
|
-
|
|
8796
|
+
const layerRootComponentCode = import_lib.default.existsSync(layerRootComponentPath) && import_lib.default.readFileSync(layerRootComponentPath, "utf-8") || "";
|
|
8797
|
+
if (!isEmptyCode(layerRootComponentCode)) return {
|
|
8798
|
+
path: layerRootComponentPath,
|
|
8799
|
+
code: layerRootComponentCode
|
|
8800
|
+
};
|
|
8801
|
+
}
|
|
8802
|
+
const defaultRootComponentPath = resolvePathSync("@vixt/react/client/App");
|
|
8803
|
+
return {
|
|
8804
|
+
path: defaultRootComponentPath,
|
|
8805
|
+
code: import_lib.default.readFileSync(defaultRootComponentPath, "utf-8")
|
|
8806
|
+
};
|
|
8807
|
+
}
|
|
8808
|
+
function isEmptyCode(code) {
|
|
8809
|
+
if (!code) return true;
|
|
8810
|
+
try {
|
|
8811
|
+
return !parseAst(code, { jsx: true }).body.length;
|
|
8812
|
+
} catch {
|
|
8813
|
+
return false;
|
|
8796
8814
|
}
|
|
8797
|
-
return resolvePathSync("@vixt/react/client/App");
|
|
8798
8815
|
}
|
|
8799
|
-
const name$1 = "virtual:vixt:root-component";
|
|
8800
|
-
const virtualModuleId$1 = name$1;
|
|
8801
|
-
const resolvedVirtualModuleId$1 = `\0${virtualModuleId$1}`;
|
|
8816
|
+
const name$1 = "virtual:vixt:root-component.tsx";
|
|
8802
8817
|
var virtual_root_component_default = defineVixtModule({
|
|
8803
8818
|
meta: { name: name$1 },
|
|
8804
8819
|
setup(_, vixt) {
|
|
8805
8820
|
return {
|
|
8806
8821
|
name: name$1,
|
|
8807
8822
|
resolveId(id) {
|
|
8808
|
-
if (id ===
|
|
8823
|
+
if (id === name$1) return name$1;
|
|
8809
8824
|
},
|
|
8810
8825
|
load(id) {
|
|
8811
|
-
if (id ===
|
|
8812
|
-
const
|
|
8813
|
-
|
|
8826
|
+
if (id === name$1) {
|
|
8827
|
+
const { path: path$13, code } = resolveRootComponent(vixt);
|
|
8828
|
+
this.addWatchFile(path$13);
|
|
8829
|
+
return code;
|
|
8814
8830
|
}
|
|
8815
8831
|
}
|
|
8816
8832
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@vixt/react",
|
|
3
3
|
"type": "module",
|
|
4
|
-
"version": "0.6.
|
|
4
|
+
"version": "0.6.4",
|
|
5
5
|
"author": "SoulLyoko<https://github.com/SoulLyoko>",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"homepage": "https://soullyoko.github.io/vixt/",
|
|
@@ -13,6 +13,7 @@
|
|
|
13
13
|
],
|
|
14
14
|
"exports": {
|
|
15
15
|
".": "./dist/index.mjs",
|
|
16
|
+
"./client/App": "./src/client/App.tsx",
|
|
16
17
|
"./client/*": "./dist/client/*.js",
|
|
17
18
|
"./types": "./dist/types/index.d.ts",
|
|
18
19
|
"./package.json": "./package.json"
|
|
@@ -35,6 +36,6 @@
|
|
|
35
36
|
"vite-plugin-pages": "^0.33.2",
|
|
36
37
|
"vite-plugin-vue-layouts": "^0.11.0",
|
|
37
38
|
"yaml": "^2.8.2",
|
|
38
|
-
"@vixt/core": "0.6.
|
|
39
|
+
"@vixt/core": "0.6.4"
|
|
39
40
|
}
|
|
40
41
|
}
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
// @ts-nocheck
|
|
2
|
+
import routes from '~react-pages'
|
|
3
|
+
import { BrowserRouter, useRoutes } from 'react-router'
|
|
4
|
+
import appConfig from 'virtual:vixt:app-config'
|
|
5
|
+
import { setupLayouts } from 'virtual:vixt:setup-layouts'
|
|
6
|
+
|
|
7
|
+
function App() {
|
|
8
|
+
const routesWithLayouts = setupLayouts(routes)
|
|
9
|
+
const Routes = () => useRoutes(routesWithLayouts)
|
|
10
|
+
return (
|
|
11
|
+
<BrowserRouter basename={appConfig.baseURL}>
|
|
12
|
+
<Routes />
|
|
13
|
+
</BrowserRouter>
|
|
14
|
+
)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
export default App
|
package/src/client/entry.ts
CHANGED
|
@@ -8,7 +8,7 @@ import appConfig from 'virtual:vixt:app-config'
|
|
|
8
8
|
// @ts-expect-error virtual file
|
|
9
9
|
import plugins from 'virtual:vixt:plugins'
|
|
10
10
|
// @ts-expect-error virtual file
|
|
11
|
-
import RootComponent from 'virtual:vixt:root-component'
|
|
11
|
+
import RootComponent from 'virtual:vixt:root-component.tsx'
|
|
12
12
|
|
|
13
13
|
async function entry() {
|
|
14
14
|
const app = createRoot(document.getElementById(appConfig.rootId || 'app')!)
|
|
@@ -4,35 +4,55 @@ import { defineVixtModule } from '@vixt/core'
|
|
|
4
4
|
import fs from 'fs-extra'
|
|
5
5
|
import { resolvePathSync } from 'mlly'
|
|
6
6
|
import path from 'pathe'
|
|
7
|
+
import { parseAst } from 'vite'
|
|
7
8
|
|
|
8
|
-
function
|
|
9
|
+
function resolveRootComponent(vixt: Vixt) {
|
|
9
10
|
for (const layer of vixt._layers) {
|
|
10
11
|
const layerRootComponentPath = path.resolve(layer.config!.srcDir!, 'App.tsx')
|
|
11
|
-
|
|
12
|
-
|
|
12
|
+
const isExists = fs.existsSync(layerRootComponentPath)
|
|
13
|
+
const layerRootComponentCode = (isExists && fs.readFileSync(layerRootComponentPath, 'utf-8')) || ''
|
|
14
|
+
if (!isEmptyCode(layerRootComponentCode)) {
|
|
15
|
+
return {
|
|
16
|
+
path: layerRootComponentPath,
|
|
17
|
+
code: layerRootComponentCode,
|
|
18
|
+
}
|
|
19
|
+
}
|
|
20
|
+
}
|
|
21
|
+
|
|
22
|
+
const defaultRootComponentPath = resolvePathSync('@vixt/react/client/App')
|
|
23
|
+
return {
|
|
24
|
+
path: defaultRootComponentPath,
|
|
25
|
+
code: fs.readFileSync(defaultRootComponentPath, 'utf-8'),
|
|
13
26
|
}
|
|
27
|
+
}
|
|
14
28
|
|
|
15
|
-
|
|
29
|
+
export function isEmptyCode(code?: string) {
|
|
30
|
+
if (!code)
|
|
31
|
+
return true
|
|
32
|
+
try {
|
|
33
|
+
return !parseAst(code, { jsx: true }).body.length
|
|
34
|
+
}
|
|
35
|
+
catch {
|
|
36
|
+
return false
|
|
37
|
+
}
|
|
16
38
|
}
|
|
17
39
|
|
|
18
|
-
const name = 'virtual:vixt:root-component'
|
|
19
|
-
const virtualModuleId = name
|
|
20
|
-
const resolvedVirtualModuleId = `\0${virtualModuleId}`
|
|
40
|
+
const name = 'virtual:vixt:root-component.tsx'
|
|
21
41
|
export default defineVixtModule({
|
|
22
42
|
meta: { name },
|
|
23
43
|
setup(_, vixt) {
|
|
24
44
|
return {
|
|
25
45
|
name,
|
|
26
46
|
resolveId(id) {
|
|
27
|
-
if (id ===
|
|
28
|
-
return
|
|
47
|
+
if (id === name) {
|
|
48
|
+
return name
|
|
29
49
|
}
|
|
30
50
|
},
|
|
31
51
|
load(id) {
|
|
32
|
-
if (id ===
|
|
33
|
-
const
|
|
34
|
-
|
|
35
|
-
return
|
|
52
|
+
if (id === name) {
|
|
53
|
+
const { path, code } = resolveRootComponent(vixt)
|
|
54
|
+
this.addWatchFile(path)
|
|
55
|
+
return code
|
|
36
56
|
}
|
|
37
57
|
},
|
|
38
58
|
}
|
package/tsdown.config.ts
CHANGED
|
@@ -5,11 +5,13 @@ export default defineConfig([
|
|
|
5
5
|
entry: 'src/index.ts',
|
|
6
6
|
platform: 'node',
|
|
7
7
|
copy: ['src/types'],
|
|
8
|
+
external: ['vite'],
|
|
8
9
|
},
|
|
9
10
|
{
|
|
10
|
-
entry: 'src/client/**/*',
|
|
11
|
+
entry: ['src/client/**/*', '!src/client/App.tsx'],
|
|
11
12
|
platform: 'browser',
|
|
12
13
|
outDir: 'dist/client',
|
|
13
14
|
external: [/virtual:/],
|
|
15
|
+
copy: ['src/client/App.tsx'],
|
|
14
16
|
},
|
|
15
17
|
])
|
package/dist/client/App.d.ts
DELETED
package/dist/client/App.js
DELETED
|
@@ -1,14 +0,0 @@
|
|
|
1
|
-
import routes from "~react-pages";
|
|
2
|
-
import { createElement } from "react";
|
|
3
|
-
import { RouterProvider, createBrowserRouter } from "react-router";
|
|
4
|
-
import appConfig from "virtual:vixt:app-config";
|
|
5
|
-
import { setupLayouts } from "virtual:vixt:setup-layouts";
|
|
6
|
-
|
|
7
|
-
//#region src/client/App.ts
|
|
8
|
-
function App() {
|
|
9
|
-
return createElement(RouterProvider, { router: createBrowserRouter(setupLayouts(routes), { basename: appConfig.baseURL }) });
|
|
10
|
-
}
|
|
11
|
-
var App_default = App;
|
|
12
|
-
|
|
13
|
-
//#endregion
|
|
14
|
-
export { App_default as default };
|
package/src/client/App.ts
DELETED
|
@@ -1,15 +0,0 @@
|
|
|
1
|
-
// @ts-expect-error virtual file
|
|
2
|
-
import routes from '~react-pages'
|
|
3
|
-
import { createElement } from 'react'
|
|
4
|
-
import { createBrowserRouter, RouterProvider } from 'react-router'
|
|
5
|
-
// @ts-expect-error virtual file
|
|
6
|
-
import appConfig from 'virtual:vixt:app-config'
|
|
7
|
-
// @ts-expect-error virtual file
|
|
8
|
-
import { setupLayouts } from 'virtual:vixt:setup-layouts'
|
|
9
|
-
|
|
10
|
-
function App() {
|
|
11
|
-
const router = createBrowserRouter(setupLayouts(routes), { basename: appConfig.baseURL })
|
|
12
|
-
return createElement(RouterProvider, { router })
|
|
13
|
-
}
|
|
14
|
-
|
|
15
|
-
export default App
|