@ubean/cli 0.4.3 → 0.4.5
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/cli.js +42 -5
- package/package.json +12 -12
package/dist/cli.js
CHANGED
|
@@ -10,6 +10,7 @@ import { pathToFileURL } from "node:url";
|
|
|
10
10
|
import { generateOpenApiTypesFromServer, generateTypes } from "@ubean/build/codegen";
|
|
11
11
|
import { prerender } from "@ubean/build/prerender";
|
|
12
12
|
import { buildProduction } from "@ubean/build/production";
|
|
13
|
+
import { createStaticSsgRenderer } from "@ubean/build/static-render";
|
|
13
14
|
import { NODE_REQUIREMENTS, createCapabilitySet, diagnoseCapabilities, registerBuiltinPresets, resolvePresetByName } from "@ubean/preset";
|
|
14
15
|
import { scanProject } from "@ubean/scan";
|
|
15
16
|
import { applyServerConfig, createUbeanApp } from "@ubean/app";
|
|
@@ -19,7 +20,6 @@ import { createServer as createServer$1 } from "vite";
|
|
|
19
20
|
import vue from "@vitejs/plugin-vue";
|
|
20
21
|
import { ubeanPlugin } from "@ubean/build/vite";
|
|
21
22
|
import { VUE_PLUGIN_INCLUDE, ubeanVite } from "@ubean/build/vue";
|
|
22
|
-
import { createVueRenderer } from "@ubean/client/ssr";
|
|
23
23
|
import { getVueLocaleParam, toVueRouterLocalePath } from "@ubean/i18n";
|
|
24
24
|
import { ubeanIslandsPlugin } from "@ubean/islands/vite";
|
|
25
25
|
import { findAvailablePort, findUserViteConfig, waitForPort } from "@ubean/shared/node";
|
|
@@ -403,7 +403,22 @@ const buildCommand = {
|
|
|
403
403
|
const hasPrerenderRules = Object.values(config.routeRules || {}).some((r) => r?.prerender === true);
|
|
404
404
|
if (config.prerender.enabled || hasPrerenderRules) {
|
|
405
405
|
logger$9.info("Prerendering static pages...");
|
|
406
|
-
|
|
406
|
+
let fetcher;
|
|
407
|
+
let notFoundRoute = false;
|
|
408
|
+
let expandRoutes;
|
|
409
|
+
if (config.mode === "ssg") {
|
|
410
|
+
const staticRenderer = await createStaticSsgRenderer(cwd, manifest, {
|
|
411
|
+
pages: result.pages,
|
|
412
|
+
notFoundPage: result.notFoundPage ?? null,
|
|
413
|
+
i18n: config.i18n
|
|
414
|
+
});
|
|
415
|
+
if (staticRenderer) {
|
|
416
|
+
fetcher = staticRenderer.fetcher;
|
|
417
|
+
expandRoutes = staticRenderer.expandRoutes;
|
|
418
|
+
notFoundRoute = Boolean(result.notFoundPage);
|
|
419
|
+
logger$9.info("Using static SSG renderer (direct render, no HTTP pipeline)");
|
|
420
|
+
}
|
|
421
|
+
} else fetcher = await createSsrFetcher(cwd, manifest);
|
|
407
422
|
await prerender({
|
|
408
423
|
cwd,
|
|
409
424
|
outputDir: config.build.outputDir,
|
|
@@ -411,7 +426,9 @@ const buildCommand = {
|
|
|
411
426
|
prerender: config.prerender,
|
|
412
427
|
routeRules: config.routeRules,
|
|
413
428
|
contentRoutes,
|
|
414
|
-
fetcher
|
|
429
|
+
fetcher,
|
|
430
|
+
notFoundRoute,
|
|
431
|
+
expandRoutes
|
|
415
432
|
});
|
|
416
433
|
}
|
|
417
434
|
if (config.mode === "ssg" && !process.env.UBEAN_KEEP_SSR) {
|
|
@@ -501,6 +518,23 @@ function loadScaffoldOps() {
|
|
|
501
518
|
recoverScaffold
|
|
502
519
|
};
|
|
503
520
|
}
|
|
521
|
+
/** Vite's browser-facing prefix for virtual module ids (see `wrapId`). */
|
|
522
|
+
const VALID_ID_PREFIX = "/@id/";
|
|
523
|
+
/** Vite's URL-safe encoding of the `\0` virtual-module marker. */
|
|
524
|
+
const NULL_BYTE_PLACEHOLDER = "__x00__";
|
|
525
|
+
/**
|
|
526
|
+
* Encode a module-graph URL into a browser-servable path.
|
|
527
|
+
*
|
|
528
|
+
* Virtual module ids carry a raw `\0` marker in the module graph (e.g.
|
|
529
|
+
* UnoCSS's `\0/__uno.css`). A literal NUL is invalid inside HTML — parse5
|
|
530
|
+
* rejects it with `unexpected-null-character`, which surfaces as a warning
|
|
531
|
+
* in `transformIndexHtml`. Mirror Vite's own import-analysis rewriting
|
|
532
|
+
* (`wrapId`: `/@id/` prefix + `\0` → `__x00__`) so the href stays valid
|
|
533
|
+
* and resolvable by the dev server.
|
|
534
|
+
*/
|
|
535
|
+
function toDevCssHref(url) {
|
|
536
|
+
return url.includes("\0") ? `${VALID_ID_PREFIX}${url.replace(/\0/g, NULL_BYTE_PLACEHOLDER)}` : url;
|
|
537
|
+
}
|
|
504
538
|
/**
|
|
505
539
|
* Collect render-blocking CSS URLs from the Vite dev module graph.
|
|
506
540
|
*
|
|
@@ -520,7 +554,7 @@ function collectDevCssLinks(moduleGraph) {
|
|
|
520
554
|
for (const mod of moduleGraph.idToModuleMap.values()) {
|
|
521
555
|
const { url, id } = mod;
|
|
522
556
|
if (!url || url.includes("?")) continue;
|
|
523
|
-
if (id?.endsWith(".css") || url.endsWith(".css")) links.add(`${url}?direct`);
|
|
557
|
+
if (id?.endsWith(".css") || url.endsWith(".css")) links.add(`${toDevCssHref(url)}?direct`);
|
|
524
558
|
}
|
|
525
559
|
return [...links];
|
|
526
560
|
}
|
|
@@ -658,6 +692,7 @@ async function createViteDevServer(options) {
|
|
|
658
692
|
let viteDevtoolsPlugins = [];
|
|
659
693
|
if (devtoolsEnabled) try {
|
|
660
694
|
const { DevTools } = await import("@vitejs/devtools");
|
|
695
|
+
// @vitejs/devtools 也解析到含 @vitejs+devtools peer 上下文的 vite-plus-core
|
|
661
696
|
viteDevtoolsPlugins = await DevTools({ builtinDevTools: false });
|
|
662
697
|
} catch {}
|
|
663
698
|
const userViteConfig = findUserViteConfig(cwd);
|
|
@@ -692,6 +727,7 @@ async function createViteDevServer(options) {
|
|
|
692
727
|
viteServer = await createServer$1({
|
|
693
728
|
root: cwd,
|
|
694
729
|
configFile: userViteConfig ?? false,
|
|
730
|
+
resolve: { dedupe: ["vue", "vue-router"] },
|
|
695
731
|
server: {
|
|
696
732
|
middlewareMode: { server: httpServer },
|
|
697
733
|
hmr: { port: actualPort + 1e3 }
|
|
@@ -715,10 +751,11 @@ async function createViteDevServer(options) {
|
|
|
715
751
|
"#ubean-client-entry"
|
|
716
752
|
] },
|
|
717
753
|
ssr: {
|
|
718
|
-
noExternal: ["ubean"],
|
|
754
|
+
noExternal: ["ubean", /^@ubean\//],
|
|
719
755
|
external: ["@ubean/i18n"]
|
|
720
756
|
}
|
|
721
757
|
});
|
|
758
|
+
const { createVueRenderer } = await viteServer.ssrLoadModule("@ubean/client/ssr");
|
|
722
759
|
function enhanceAppWithVite(app, layouts = []) {
|
|
723
760
|
app.options.layouts = layouts;
|
|
724
761
|
const routeLoaders = {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@ubean/cli",
|
|
3
|
-
"version": "0.4.
|
|
3
|
+
"version": "0.4.5",
|
|
4
4
|
"description": "CLI for ubean (ubean-next binary: dev, build, prepare, init, preview, page, env, config, devtools, api/layout/middleware/cron/plugin scaffolds) plus the Vite dev server runner",
|
|
5
5
|
"bin": {
|
|
6
6
|
"ubean-next": "./bin/ubean-next.mjs"
|
|
@@ -24,15 +24,15 @@
|
|
|
24
24
|
}
|
|
25
25
|
},
|
|
26
26
|
"dependencies": {
|
|
27
|
-
"@ubean/app": "0.4.
|
|
28
|
-
"@ubean/build": "0.4.
|
|
29
|
-
"@ubean/client": "0.4.
|
|
30
|
-
"@ubean/config": "0.4.
|
|
31
|
-
"@ubean/i18n": "0.4.
|
|
32
|
-
"@ubean/islands": "0.4.
|
|
33
|
-
"@ubean/preset": "0.4.
|
|
34
|
-
"@ubean/scan": "0.4.
|
|
35
|
-
"@ubean/shared": "0.4.
|
|
27
|
+
"@ubean/app": "0.4.5",
|
|
28
|
+
"@ubean/build": "0.4.5",
|
|
29
|
+
"@ubean/client": "0.4.5",
|
|
30
|
+
"@ubean/config": "0.4.5",
|
|
31
|
+
"@ubean/i18n": "0.4.5",
|
|
32
|
+
"@ubean/islands": "0.4.5",
|
|
33
|
+
"@ubean/preset": "0.4.5",
|
|
34
|
+
"@ubean/scan": "0.4.5",
|
|
35
|
+
"@ubean/shared": "0.4.5",
|
|
36
36
|
"citty": "^0.2.2",
|
|
37
37
|
"kolorist": "^1.8.0",
|
|
38
38
|
"pathe": "^2.0.3"
|
|
@@ -45,8 +45,8 @@
|
|
|
45
45
|
"vite-plus": "0.3.0"
|
|
46
46
|
},
|
|
47
47
|
"peerDependencies": {
|
|
48
|
-
"@ubean/content": "0.4.
|
|
49
|
-
"@ubean/devtools": "0.4.
|
|
48
|
+
"@ubean/content": "0.4.5",
|
|
49
|
+
"@ubean/devtools": "0.4.5",
|
|
50
50
|
"@vitejs/plugin-vue": "^6.0.8",
|
|
51
51
|
"vite": "npm:@voidzero-dev/vite-plus-core@0.3.0"
|
|
52
52
|
},
|