olovaplugin 1.0.9 → 1.0.10
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/olova-plugins.cjs +82 -9
- package/dist/olova-plugins.js +82 -9
- package/package.json +8 -7
package/dist/olova-plugins.cjs
CHANGED
|
@@ -151,7 +151,7 @@ function configPlugin() {
|
|
|
151
151
|
var import_fs2 = __toESM(require("fs"), 1);
|
|
152
152
|
var import_path2 = __toESM(require("path"), 1);
|
|
153
153
|
function routerPlugin() {
|
|
154
|
-
const virtualModuleId = "olova
|
|
154
|
+
const virtualModuleId = "virtual:olova-routes";
|
|
155
155
|
const resolvedVirtualModuleId = "\0" + virtualModuleId;
|
|
156
156
|
let server = null;
|
|
157
157
|
let root = process.cwd();
|
|
@@ -304,7 +304,7 @@ function frameworkPlugin() {
|
|
|
304
304
|
import React from 'react';
|
|
305
305
|
import { hydrateRoot, createRoot } from 'react-dom/client';
|
|
306
306
|
import Layout, { metadata as defaultMetadata } from '/src/root.tsx';
|
|
307
|
-
import { Router, loadRoute } from '
|
|
307
|
+
import { Router, loadRoute } from 'olova/Router';
|
|
308
308
|
|
|
309
309
|
// Helper to generate SEO meta tags
|
|
310
310
|
function generateSeoTags(metadata) {
|
|
@@ -425,7 +425,7 @@ loadRoute(path).then((result) => {
|
|
|
425
425
|
import React from 'react';
|
|
426
426
|
import { renderToString } from 'react-dom/server';
|
|
427
427
|
import Layout, { metadata as defaultMetadata } from '/src/root.tsx';
|
|
428
|
-
import { Router, loadRoute } from '
|
|
428
|
+
import { Router, loadRoute } from 'olova/Router';
|
|
429
429
|
|
|
430
430
|
// Generate SEO head content
|
|
431
431
|
function generateSeoHead(metadata) {
|
|
@@ -544,6 +544,8 @@ export { loadRoute };`;
|
|
|
544
544
|
// router/virtual-html.ts
|
|
545
545
|
var import_fs3 = __toESM(require("fs"), 1);
|
|
546
546
|
var import_path3 = __toESM(require("path"), 1);
|
|
547
|
+
var import_react = __toESM(require("react"), 1);
|
|
548
|
+
var import_server = require("react-dom/server");
|
|
547
549
|
|
|
548
550
|
// router/hydration.ts
|
|
549
551
|
function generateOlovaHydration(data, buildId) {
|
|
@@ -803,13 +805,51 @@ function virtualHtmlPlugin() {
|
|
|
803
805
|
const shouldSSR = isStaticRoute(routePath);
|
|
804
806
|
try {
|
|
805
807
|
if (shouldSSR) {
|
|
808
|
+
let RootLayout = void 0;
|
|
809
|
+
const srcDir = import_path3.default.resolve("src");
|
|
810
|
+
const layoutExtensions = [".tsx", ".jsx"];
|
|
811
|
+
let layoutPath = "";
|
|
812
|
+
for (const ext of layoutExtensions) {
|
|
813
|
+
const p = import_path3.default.join(srcDir, "root" + ext);
|
|
814
|
+
if (import_fs3.default.existsSync(p)) {
|
|
815
|
+
layoutPath = "/src/root" + ext;
|
|
816
|
+
break;
|
|
817
|
+
}
|
|
818
|
+
}
|
|
806
819
|
const { render } = await server.ssrLoadModule("olova/server");
|
|
807
|
-
|
|
820
|
+
if (layoutPath) {
|
|
821
|
+
const mod = await server.ssrLoadModule(layoutPath);
|
|
822
|
+
RootLayout = mod.default;
|
|
823
|
+
}
|
|
824
|
+
const { html: ssrHtml, hydrationData } = await render(routePath, RootLayout);
|
|
808
825
|
let fullHtml = ssrHtml;
|
|
809
|
-
|
|
826
|
+
if (layoutPath) {
|
|
827
|
+
const metadata = hydrationData.metadata || {};
|
|
828
|
+
if (metadata.title && !fullHtml.includes("<title>")) {
|
|
829
|
+
fullHtml = fullHtml.replace("</head>", `<title>${metadata.title}</title>
|
|
830
|
+
</head>`);
|
|
831
|
+
}
|
|
832
|
+
if (metadata.description && !fullHtml.includes('name="description"')) {
|
|
833
|
+
fullHtml = fullHtml.replace("</head>", `<meta name="description" content="${metadata.description}" />
|
|
834
|
+
</head>`);
|
|
835
|
+
}
|
|
836
|
+
}
|
|
837
|
+
const hydrationScript = `<script>window.__OLOVA_DATA__ = ${JSON.stringify(hydrationData)}; window.__OLOVA_HYDRATE_MANUAL__ = true;</script>`;
|
|
810
838
|
fullHtml = fullHtml.replace("</body>", `${hydrationScript}
|
|
811
839
|
</body>`);
|
|
812
|
-
|
|
840
|
+
let clientScript;
|
|
841
|
+
if (layoutPath) {
|
|
842
|
+
clientScript = `<script type="module">
|
|
843
|
+
import { hydrate } from '/olova/client';
|
|
844
|
+
import RootLayout from '${layoutPath}';
|
|
845
|
+
hydrate(RootLayout);
|
|
846
|
+
</script>`;
|
|
847
|
+
} else {
|
|
848
|
+
clientScript = `<script type="module">
|
|
849
|
+
import { hydrate } from '/olova/client';
|
|
850
|
+
hydrate();
|
|
851
|
+
</script>`;
|
|
852
|
+
}
|
|
813
853
|
fullHtml = fullHtml.replace("</body>", `${clientScript}
|
|
814
854
|
</body>`);
|
|
815
855
|
const devBuildId = "dev-" + Date.now().toString(36);
|
|
@@ -828,7 +868,7 @@ function virtualHtmlPlugin() {
|
|
|
828
868
|
res.end(html);
|
|
829
869
|
} else {
|
|
830
870
|
const { renderShellWithMetadata } = await server.ssrLoadModule("olova/server");
|
|
831
|
-
const { loadRoute: clientLoadRoute } = await server.ssrLoadModule("
|
|
871
|
+
const { loadRoute: clientLoadRoute } = await server.ssrLoadModule("olova/Router");
|
|
832
872
|
let pageMetadata = {};
|
|
833
873
|
try {
|
|
834
874
|
const result = await clientLoadRoute(routePath);
|
|
@@ -837,8 +877,41 @@ function virtualHtmlPlugin() {
|
|
|
837
877
|
}
|
|
838
878
|
} catch (e) {
|
|
839
879
|
}
|
|
840
|
-
let
|
|
841
|
-
const
|
|
880
|
+
let RootLayout = void 0;
|
|
881
|
+
const srcDir = import_path3.default.resolve("src");
|
|
882
|
+
const layoutExtensions = [".tsx", ".jsx"];
|
|
883
|
+
let layoutPath = "";
|
|
884
|
+
for (const ext of layoutExtensions) {
|
|
885
|
+
const p = import_path3.default.join(srcDir, "root" + ext);
|
|
886
|
+
if (import_fs3.default.existsSync(p)) {
|
|
887
|
+
layoutPath = "/src/root" + ext;
|
|
888
|
+
break;
|
|
889
|
+
}
|
|
890
|
+
}
|
|
891
|
+
if (layoutPath) {
|
|
892
|
+
const mod = await server.ssrLoadModule(layoutPath);
|
|
893
|
+
RootLayout = mod.default;
|
|
894
|
+
}
|
|
895
|
+
let fullHtml;
|
|
896
|
+
if (RootLayout && layoutPath) {
|
|
897
|
+
const App = import_react.default.createElement(RootLayout, null, import_react.default.createElement("div", null));
|
|
898
|
+
fullHtml = "<!DOCTYPE html>" + (0, import_server.renderToString)(App);
|
|
899
|
+
} else {
|
|
900
|
+
fullHtml = renderShellWithMetadata(pageMetadata);
|
|
901
|
+
}
|
|
902
|
+
let clientScript;
|
|
903
|
+
if (layoutPath) {
|
|
904
|
+
clientScript = `<script type="module">
|
|
905
|
+
import { hydrate } from '/olova/client';
|
|
906
|
+
import RootLayout from '${layoutPath}';
|
|
907
|
+
hydrate(RootLayout);
|
|
908
|
+
</script>`;
|
|
909
|
+
} else {
|
|
910
|
+
clientScript = `<script type="module">
|
|
911
|
+
import { hydrate } from '/olova/client';
|
|
912
|
+
hydrate();
|
|
913
|
+
</script>`;
|
|
914
|
+
}
|
|
842
915
|
fullHtml = fullHtml.replace("</body>", `${clientScript}
|
|
843
916
|
</body>`);
|
|
844
917
|
const devBuildId = "dev-" + Date.now().toString(36);
|
package/dist/olova-plugins.js
CHANGED
|
@@ -91,7 +91,7 @@ function configPlugin() {
|
|
|
91
91
|
import fs2 from "fs";
|
|
92
92
|
import path2 from "path";
|
|
93
93
|
function routerPlugin() {
|
|
94
|
-
const virtualModuleId = "olova
|
|
94
|
+
const virtualModuleId = "virtual:olova-routes";
|
|
95
95
|
const resolvedVirtualModuleId = "\0" + virtualModuleId;
|
|
96
96
|
let server = null;
|
|
97
97
|
let root = process.cwd();
|
|
@@ -244,7 +244,7 @@ function frameworkPlugin() {
|
|
|
244
244
|
import React from 'react';
|
|
245
245
|
import { hydrateRoot, createRoot } from 'react-dom/client';
|
|
246
246
|
import Layout, { metadata as defaultMetadata } from '/src/root.tsx';
|
|
247
|
-
import { Router, loadRoute } from '
|
|
247
|
+
import { Router, loadRoute } from 'olova/Router';
|
|
248
248
|
|
|
249
249
|
// Helper to generate SEO meta tags
|
|
250
250
|
function generateSeoTags(metadata) {
|
|
@@ -365,7 +365,7 @@ loadRoute(path).then((result) => {
|
|
|
365
365
|
import React from 'react';
|
|
366
366
|
import { renderToString } from 'react-dom/server';
|
|
367
367
|
import Layout, { metadata as defaultMetadata } from '/src/root.tsx';
|
|
368
|
-
import { Router, loadRoute } from '
|
|
368
|
+
import { Router, loadRoute } from 'olova/Router';
|
|
369
369
|
|
|
370
370
|
// Generate SEO head content
|
|
371
371
|
function generateSeoHead(metadata) {
|
|
@@ -484,6 +484,8 @@ export { loadRoute };`;
|
|
|
484
484
|
// router/virtual-html.ts
|
|
485
485
|
import fs3 from "fs";
|
|
486
486
|
import path3 from "path";
|
|
487
|
+
import React from "react";
|
|
488
|
+
import { renderToString } from "react-dom/server";
|
|
487
489
|
|
|
488
490
|
// router/hydration.ts
|
|
489
491
|
function generateOlovaHydration(data, buildId) {
|
|
@@ -743,13 +745,51 @@ function virtualHtmlPlugin() {
|
|
|
743
745
|
const shouldSSR = isStaticRoute(routePath);
|
|
744
746
|
try {
|
|
745
747
|
if (shouldSSR) {
|
|
748
|
+
let RootLayout = void 0;
|
|
749
|
+
const srcDir = path3.resolve("src");
|
|
750
|
+
const layoutExtensions = [".tsx", ".jsx"];
|
|
751
|
+
let layoutPath = "";
|
|
752
|
+
for (const ext of layoutExtensions) {
|
|
753
|
+
const p = path3.join(srcDir, "root" + ext);
|
|
754
|
+
if (fs3.existsSync(p)) {
|
|
755
|
+
layoutPath = "/src/root" + ext;
|
|
756
|
+
break;
|
|
757
|
+
}
|
|
758
|
+
}
|
|
746
759
|
const { render } = await server.ssrLoadModule("olova/server");
|
|
747
|
-
|
|
760
|
+
if (layoutPath) {
|
|
761
|
+
const mod = await server.ssrLoadModule(layoutPath);
|
|
762
|
+
RootLayout = mod.default;
|
|
763
|
+
}
|
|
764
|
+
const { html: ssrHtml, hydrationData } = await render(routePath, RootLayout);
|
|
748
765
|
let fullHtml = ssrHtml;
|
|
749
|
-
|
|
766
|
+
if (layoutPath) {
|
|
767
|
+
const metadata = hydrationData.metadata || {};
|
|
768
|
+
if (metadata.title && !fullHtml.includes("<title>")) {
|
|
769
|
+
fullHtml = fullHtml.replace("</head>", `<title>${metadata.title}</title>
|
|
770
|
+
</head>`);
|
|
771
|
+
}
|
|
772
|
+
if (metadata.description && !fullHtml.includes('name="description"')) {
|
|
773
|
+
fullHtml = fullHtml.replace("</head>", `<meta name="description" content="${metadata.description}" />
|
|
774
|
+
</head>`);
|
|
775
|
+
}
|
|
776
|
+
}
|
|
777
|
+
const hydrationScript = `<script>window.__OLOVA_DATA__ = ${JSON.stringify(hydrationData)}; window.__OLOVA_HYDRATE_MANUAL__ = true;</script>`;
|
|
750
778
|
fullHtml = fullHtml.replace("</body>", `${hydrationScript}
|
|
751
779
|
</body>`);
|
|
752
|
-
|
|
780
|
+
let clientScript;
|
|
781
|
+
if (layoutPath) {
|
|
782
|
+
clientScript = `<script type="module">
|
|
783
|
+
import { hydrate } from '/olova/client';
|
|
784
|
+
import RootLayout from '${layoutPath}';
|
|
785
|
+
hydrate(RootLayout);
|
|
786
|
+
</script>`;
|
|
787
|
+
} else {
|
|
788
|
+
clientScript = `<script type="module">
|
|
789
|
+
import { hydrate } from '/olova/client';
|
|
790
|
+
hydrate();
|
|
791
|
+
</script>`;
|
|
792
|
+
}
|
|
753
793
|
fullHtml = fullHtml.replace("</body>", `${clientScript}
|
|
754
794
|
</body>`);
|
|
755
795
|
const devBuildId = "dev-" + Date.now().toString(36);
|
|
@@ -768,7 +808,7 @@ function virtualHtmlPlugin() {
|
|
|
768
808
|
res.end(html);
|
|
769
809
|
} else {
|
|
770
810
|
const { renderShellWithMetadata } = await server.ssrLoadModule("olova/server");
|
|
771
|
-
const { loadRoute: clientLoadRoute } = await server.ssrLoadModule("
|
|
811
|
+
const { loadRoute: clientLoadRoute } = await server.ssrLoadModule("olova/Router");
|
|
772
812
|
let pageMetadata = {};
|
|
773
813
|
try {
|
|
774
814
|
const result = await clientLoadRoute(routePath);
|
|
@@ -777,8 +817,41 @@ function virtualHtmlPlugin() {
|
|
|
777
817
|
}
|
|
778
818
|
} catch (e) {
|
|
779
819
|
}
|
|
780
|
-
let
|
|
781
|
-
const
|
|
820
|
+
let RootLayout = void 0;
|
|
821
|
+
const srcDir = path3.resolve("src");
|
|
822
|
+
const layoutExtensions = [".tsx", ".jsx"];
|
|
823
|
+
let layoutPath = "";
|
|
824
|
+
for (const ext of layoutExtensions) {
|
|
825
|
+
const p = path3.join(srcDir, "root" + ext);
|
|
826
|
+
if (fs3.existsSync(p)) {
|
|
827
|
+
layoutPath = "/src/root" + ext;
|
|
828
|
+
break;
|
|
829
|
+
}
|
|
830
|
+
}
|
|
831
|
+
if (layoutPath) {
|
|
832
|
+
const mod = await server.ssrLoadModule(layoutPath);
|
|
833
|
+
RootLayout = mod.default;
|
|
834
|
+
}
|
|
835
|
+
let fullHtml;
|
|
836
|
+
if (RootLayout && layoutPath) {
|
|
837
|
+
const App = React.createElement(RootLayout, null, React.createElement("div", null));
|
|
838
|
+
fullHtml = "<!DOCTYPE html>" + renderToString(App);
|
|
839
|
+
} else {
|
|
840
|
+
fullHtml = renderShellWithMetadata(pageMetadata);
|
|
841
|
+
}
|
|
842
|
+
let clientScript;
|
|
843
|
+
if (layoutPath) {
|
|
844
|
+
clientScript = `<script type="module">
|
|
845
|
+
import { hydrate } from '/olova/client';
|
|
846
|
+
import RootLayout from '${layoutPath}';
|
|
847
|
+
hydrate(RootLayout);
|
|
848
|
+
</script>`;
|
|
849
|
+
} else {
|
|
850
|
+
clientScript = `<script type="module">
|
|
851
|
+
import { hydrate } from '/olova/client';
|
|
852
|
+
hydrate();
|
|
853
|
+
</script>`;
|
|
854
|
+
}
|
|
782
855
|
fullHtml = fullHtml.replace("</body>", `${clientScript}
|
|
783
856
|
</body>`);
|
|
784
857
|
const devBuildId = "dev-" + Date.now().toString(36);
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "olovaplugin",
|
|
3
|
-
"version": "1.0.
|
|
3
|
+
"version": "1.0.10",
|
|
4
4
|
"description": "Vite plugins for Olova framework",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "dist/olova-plugins.cjs",
|
|
@@ -18,8 +18,13 @@
|
|
|
18
18
|
}
|
|
19
19
|
}
|
|
20
20
|
},
|
|
21
|
+
"peerDependencies": {
|
|
22
|
+
"vite": "^5.0.0 || ^6.0.0 || ^7.0.0",
|
|
23
|
+
"react": "*",
|
|
24
|
+
"react-dom": "*"
|
|
25
|
+
},
|
|
21
26
|
"scripts": {
|
|
22
|
-
"build": "tsup olova-plugins.ts --format cjs,esm --dts --clean"
|
|
27
|
+
"build": "tsup olova-plugins.ts --format cjs,esm --dts --clean --external vite react react-dom react-dom/server util stream path fs"
|
|
23
28
|
},
|
|
24
29
|
"keywords": [
|
|
25
30
|
"vite",
|
|
@@ -31,14 +36,10 @@
|
|
|
31
36
|
],
|
|
32
37
|
"author": "Sera",
|
|
33
38
|
"license": "MIT",
|
|
34
|
-
"peerDependencies": {
|
|
35
|
-
"vite": "^6.0.0 || ^5.0.0"
|
|
36
|
-
},
|
|
37
39
|
"devDependencies": {
|
|
38
40
|
"@types/node": "^20.0.0",
|
|
39
41
|
"tsup": "^8.0.0",
|
|
40
42
|
"typescript": "^5.0.0",
|
|
41
|
-
"vite": "^
|
|
43
|
+
"vite": "^7.2.4"
|
|
42
44
|
}
|
|
43
|
-
|
|
44
45
|
}
|