@cloudwerk/vite-plugin 0.6.5 → 0.6.7
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/index.js +21 -14
- package/package.json +3 -3
package/dist/index.js
CHANGED
|
@@ -198,7 +198,7 @@ function generateServerEntry(manifest, scanResult, options, entryOptions) {
|
|
|
198
198
|
import { Hono } from 'hono'
|
|
199
199
|
import { ssgParams } from 'hono/ssg'
|
|
200
200
|
import { contextMiddleware, createHandlerAdapter, createMiddlewareAdapter, setRouteConfig, NotFoundError, RedirectError } from '@cloudwerk/core/runtime'
|
|
201
|
-
import { setActiveRenderer } from '@cloudwerk/ui'
|
|
201
|
+
import { setActiveRenderer${rendererName === "react" ? ", initReactRenderer" : ""} } from '@cloudwerk/ui'
|
|
202
202
|
|
|
203
203
|
// Page and Route Imports
|
|
204
204
|
${imports.join("\n")}
|
|
@@ -327,7 +327,7 @@ async function renderErrorPage(error, errorModule, layoutModules, layoutLoaderDa
|
|
|
327
327
|
element = await Promise.resolve(Layout(layoutProps))
|
|
328
328
|
}
|
|
329
329
|
|
|
330
|
-
return renderWithHydration(element, 500)
|
|
330
|
+
return await renderWithHydration(element, 500)
|
|
331
331
|
}
|
|
332
332
|
|
|
333
333
|
/**
|
|
@@ -354,7 +354,7 @@ async function renderNotFoundPage(notFoundModule, layoutModules, layoutLoaderDat
|
|
|
354
354
|
element = await Promise.resolve(Layout(layoutProps))
|
|
355
355
|
}
|
|
356
356
|
|
|
357
|
-
return renderWithHydration(element, 404)
|
|
357
|
+
return await renderWithHydration(element, 404)
|
|
358
358
|
}
|
|
359
359
|
|
|
360
360
|
// ============================================================================
|
|
@@ -428,7 +428,7 @@ function registerPage(app, pattern, pageModule, layoutModules, middlewareModules
|
|
|
428
428
|
}
|
|
429
429
|
|
|
430
430
|
// Render the page with hydration script injection
|
|
431
|
-
return renderWithHydration(element)
|
|
431
|
+
return await renderWithHydration(element)
|
|
432
432
|
} catch (error) {
|
|
433
433
|
// Handle NotFoundError (check both instanceof and name for module duplication)
|
|
434
434
|
if (error instanceof NotFoundError || error?.name === 'NotFoundError') {
|
|
@@ -460,9 +460,12 @@ function registerPage(app, pattern, pageModule, layoutModules, middlewareModules
|
|
|
460
460
|
* - CSS links are injected before </head>
|
|
461
461
|
* - Vite client (dev) and hydration script are injected before </body>
|
|
462
462
|
*/
|
|
463
|
-
function renderWithHydration(element, status = 200) {
|
|
464
|
-
//
|
|
465
|
-
|
|
463
|
+
async function renderWithHydration(element, status = 200) {
|
|
464
|
+
// Render element to HTML string using the active renderer
|
|
465
|
+
${rendererName === "react" ? `// React: use renderToString from react-dom/server
|
|
466
|
+
const { renderToString } = await import('react-dom/server')
|
|
467
|
+
let html = '<!DOCTYPE html>' + renderToString(element)` : `// Hono JSX elements have toString() for synchronous rendering
|
|
468
|
+
let html = '<!DOCTYPE html>' + String(element)`}
|
|
466
469
|
|
|
467
470
|
// Inject CSS links before </head> if present
|
|
468
471
|
if (CSS_LINKS) {
|
|
@@ -528,7 +531,8 @@ function registerRoute(app, pattern, routeModule, middlewareModules) {
|
|
|
528
531
|
// ============================================================================
|
|
529
532
|
|
|
530
533
|
// Initialize renderer
|
|
531
|
-
|
|
534
|
+
${rendererName === "react" ? `await initReactRenderer()
|
|
535
|
+
` : ""}setActiveRenderer('${rendererName}')
|
|
532
536
|
|
|
533
537
|
// Create Hono app
|
|
534
538
|
const app = new Hono({ strict: false })
|
|
@@ -2210,14 +2214,17 @@ function cloudwerkPlugin(options = {}) {
|
|
|
2210
2214
|
* This enables Vite's built-in static file serving for the public directory.
|
|
2211
2215
|
*/
|
|
2212
2216
|
async config(userConfig) {
|
|
2213
|
-
if (userConfig.publicDir !== void 0) {
|
|
2214
|
-
return {};
|
|
2215
|
-
}
|
|
2216
2217
|
const root = userConfig.root ?? process.cwd();
|
|
2217
2218
|
const cloudwerkConfig = await loadConfig(root);
|
|
2218
|
-
|
|
2219
|
-
|
|
2220
|
-
|
|
2219
|
+
const renderer = options.renderer ?? cloudwerkConfig.ui?.renderer ?? "hono-jsx";
|
|
2220
|
+
const config = {};
|
|
2221
|
+
if (renderer === "react") {
|
|
2222
|
+
config.esbuild = { jsxImportSource: "react" };
|
|
2223
|
+
}
|
|
2224
|
+
if (userConfig.publicDir === void 0) {
|
|
2225
|
+
config.publicDir = options.publicDir ?? cloudwerkConfig.publicDir ?? "public";
|
|
2226
|
+
}
|
|
2227
|
+
return config;
|
|
2221
2228
|
},
|
|
2222
2229
|
/**
|
|
2223
2230
|
* Resolve configuration and build initial manifest.
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@cloudwerk/vite-plugin",
|
|
3
|
-
"version": "0.6.
|
|
3
|
+
"version": "0.6.7",
|
|
4
4
|
"description": "Vite plugin for Cloudwerk file-based routing with virtual entry generation",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -19,8 +19,8 @@
|
|
|
19
19
|
],
|
|
20
20
|
"dependencies": {
|
|
21
21
|
"@swc/core": "^1.3.100",
|
|
22
|
-
"@cloudwerk/core": "^0.15.
|
|
23
|
-
"@cloudwerk/ui": "^0.15.
|
|
22
|
+
"@cloudwerk/core": "^0.15.3",
|
|
23
|
+
"@cloudwerk/ui": "^0.15.3"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
26
26
|
"vite": "^5.0.0 || ^6.0.0",
|