@ubean/cli 0.4.1 → 0.4.3

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.
Files changed (2) hide show
  1. package/dist/cli.js +31 -2
  2. package/package.json +13 -13
package/dist/cli.js CHANGED
@@ -501,6 +501,35 @@ function loadScaffoldOps() {
501
501
  recoverScaffold
502
502
  };
503
503
  }
504
+ /**
505
+ * Collect render-blocking CSS URLs from the Vite dev module graph.
506
+ *
507
+ * In dev, CSS imported from JS (virtual uno.css entry, global.css, font css)
508
+ * is only applied once the client entry module graph has fully loaded and
509
+ * executed — SSR HTML paints unstyled for that gap (FOUC). Injecting the same
510
+ * CSS modules as blocking `<link>` tags lets the browser fetch them in
511
+ * parallel with the JS graph, so the first paint is styled.
512
+ *
513
+ * `?direct` tells Vite's transform middleware to return raw CSS
514
+ * (`Content-Type: text/css`) instead of the JS style-injection wrapper.
515
+ * Modules whose URL already carries a query (SFC `<style>` blocks such as
516
+ * `*.vue?vue&type=style&...`) cannot be served this way and are skipped.
517
+ */
518
+ function collectDevCssLinks(moduleGraph) {
519
+ const links = /* @__PURE__ */ new Set();
520
+ for (const mod of moduleGraph.idToModuleMap.values()) {
521
+ const { url, id } = mod;
522
+ if (!url || url.includes("?")) continue;
523
+ if (id?.endsWith(".css") || url.endsWith(".css")) links.add(`${url}?direct`);
524
+ }
525
+ return [...links];
526
+ }
527
+ /** Inject blocking stylesheet links right before `</head>`. */
528
+ function injectStylesheetLinks(html, hrefs) {
529
+ if (!hrefs.length || !html.includes("</head>")) return html;
530
+ const tags = hrefs.map((href) => `<link rel="stylesheet" href="${href}">`).join("");
531
+ return html.replace("</head>", `${tags}</head>`);
532
+ }
504
533
  async function createViteDevServer(options) {
505
534
  const { cwd, config, app: initialApp, layouts: initialLayouts = [] } = options;
506
535
  const host = options.host || "localhost";
@@ -573,8 +602,8 @@ async function createViteDevServer(options) {
573
602
  const contentType = webRes.headers.get("content-type") || "";
574
603
  const skipTransform = (req.url || "").startsWith("/_devtools");
575
604
  if (contentType.includes("text/html") && webRes.body && !skipTransform) {
576
- const html = await webRes.text();
577
- const transformedHtml = await viteServer.transformIndexHtml(req.url || "/", html);
605
+ const htmlWithCss = injectStylesheetLinks(await webRes.text(), collectDevCssLinks(viteServer.moduleGraph));
606
+ const transformedHtml = await viteServer.transformIndexHtml(req.url || "/", htmlWithCss);
578
607
  res.statusCode = webRes.status;
579
608
  res.statusMessage = webRes.statusText;
580
609
  webRes.headers.forEach((value, key) => {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@ubean/cli",
3
- "version": "0.4.1",
3
+ "version": "0.4.3",
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,29 +24,29 @@
24
24
  }
25
25
  },
26
26
  "dependencies": {
27
- "@ubean/app": "0.4.1",
28
- "@ubean/build": "0.4.1",
29
- "@ubean/client": "0.4.1",
30
- "@ubean/config": "0.4.1",
31
- "@ubean/i18n": "0.4.1",
32
- "@ubean/islands": "0.4.1",
33
- "@ubean/preset": "0.4.1",
34
- "@ubean/scan": "0.4.1",
35
- "@ubean/shared": "0.4.1",
27
+ "@ubean/app": "0.4.3",
28
+ "@ubean/build": "0.4.3",
29
+ "@ubean/client": "0.4.3",
30
+ "@ubean/config": "0.4.3",
31
+ "@ubean/i18n": "0.4.3",
32
+ "@ubean/islands": "0.4.3",
33
+ "@ubean/preset": "0.4.3",
34
+ "@ubean/scan": "0.4.3",
35
+ "@ubean/shared": "0.4.3",
36
36
  "citty": "^0.2.2",
37
37
  "kolorist": "^1.8.0",
38
38
  "pathe": "^2.0.3"
39
39
  },
40
40
  "devDependencies": {
41
- "@types/node": "^26.4.1",
41
+ "@types/node": "^26.5.0",
42
42
  "@vitejs/plugin-vue": "^6.0.8",
43
43
  "typescript": "7.0.2",
44
44
  "vite": "npm:@voidzero-dev/vite-plus-core@0.3.0",
45
45
  "vite-plus": "0.3.0"
46
46
  },
47
47
  "peerDependencies": {
48
- "@ubean/content": "0.4.1",
49
- "@ubean/devtools": "0.4.1",
48
+ "@ubean/content": "0.4.3",
49
+ "@ubean/devtools": "0.4.3",
50
50
  "@vitejs/plugin-vue": "^6.0.8",
51
51
  "vite": "npm:@voidzero-dev/vite-plus-core@0.3.0"
52
52
  },