vite-plugin-kiru 0.32.1 → 0.32.2

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/index.js +30 -19
  2. package/package.json +3 -3
package/dist/index.js CHANGED
@@ -10600,7 +10600,7 @@ function injectClientScript(html) {
10600
10600
  }
10601
10601
  return html + scriptTag;
10602
10602
  }
10603
- async function handleSSR(server, url, projectRoot, resolveUserDocument2) {
10603
+ async function handleSSR(server, url, projectRoot, baseUrl, resolveUserDocument2) {
10604
10604
  const mod = await server.ssrLoadModule(
10605
10605
  VIRTUAL_ENTRY_SERVER_ID
10606
10606
  );
@@ -10648,7 +10648,7 @@ async function handleSSR(server, url, projectRoot, resolveUserDocument2) {
10648
10648
  if (cssModules.length) {
10649
10649
  const stylesheets = cssModules.map((mod2) => {
10650
10650
  const p = mod2.id?.replace(projectRoot, "");
10651
- return `<link rel="stylesheet" type="text/css" href="${p}?temp">`;
10651
+ return `<link rel="stylesheet" type="text/css" href="${path4.join(baseUrl, p).replace(/\\/g, "/")}?temp">`;
10652
10652
  });
10653
10653
  html = html.replace("<head>", "<head>" + stylesheets.join("\n"));
10654
10654
  }
@@ -11899,7 +11899,7 @@ function createPreviewMiddleware(projectRoot, baseOutDir) {
11899
11899
  import path6 from "node:path";
11900
11900
  import fs3 from "node:fs";
11901
11901
  import { pathToFileURL } from "node:url";
11902
- async function generateStaticSite(state, outputOptions, bundle, log) {
11902
+ async function generateStaticSite(state, outputOptions, bundle, log, baseUrl) {
11903
11903
  const { projectRoot, baseOutDir, manifestPath, ssgOptions } = state;
11904
11904
  const outDirAbs = path6.resolve(projectRoot, outputOptions?.dir ?? "dist");
11905
11905
  const ssrEntry = Object.values(bundle).find(
@@ -11926,10 +11926,13 @@ async function generateStaticSite(state, outputOptions, bundle, log) {
11926
11926
  for (let i = 0; i < routes.length; i += maxConcurrentRenders) {
11927
11927
  const chunkKeys = routes.slice(i, i + maxConcurrentRenders);
11928
11928
  renderingChunks.push(
11929
- chunkKeys.reduce((acc, key) => {
11930
- acc[key] = paths[key];
11931
- return acc;
11932
- }, {})
11929
+ chunkKeys.reduce(
11930
+ (acc, key) => {
11931
+ acc[key] = paths[key];
11932
+ return acc;
11933
+ },
11934
+ {}
11935
+ )
11933
11936
  );
11934
11937
  }
11935
11938
  for (const chunk of renderingChunks) {
@@ -11941,7 +11944,8 @@ async function generateStaticSite(state, outputOptions, bundle, log) {
11941
11944
  route,
11942
11945
  srcFilePath,
11943
11946
  clientEntry,
11944
- manifest
11947
+ manifest,
11948
+ baseUrl
11945
11949
  );
11946
11950
  const filePath = getOutputPath(clientOutDirAbs, route);
11947
11951
  log(ANSI.cyan("[SSG]"), "write:", ANSI.black(filePath));
@@ -12021,11 +12025,7 @@ function collectCssForModules(manifest, moduleIds, projectRoot) {
12021
12025
  }
12022
12026
  }
12023
12027
  }
12024
- if (cssFiles.size) {
12025
- const links = Array.from(cssFiles).map((f) => `<link rel="stylesheet" type="text/css" href="/${f}">`).join("");
12026
- return links;
12027
- }
12028
- return "";
12028
+ return Array.from(cssFiles);
12029
12029
  }
12030
12030
  function findClientEntry(dir) {
12031
12031
  if (!fs3.existsSync(dir)) return null;
@@ -12039,7 +12039,7 @@ function findClientEntry(dir) {
12039
12039
  }
12040
12040
  return null;
12041
12041
  }
12042
- async function renderRoute(state, mod, route, srcFilePath, clientEntry, manifest) {
12042
+ async function renderRoute(state, mod, route, srcFilePath, clientEntry, manifest, baseUrl) {
12043
12043
  const moduleIds = [];
12044
12044
  const { projectRoot, ssgOptions } = state;
12045
12045
  const documentPath = path6.resolve(
@@ -12060,13 +12060,18 @@ async function renderRoute(state, mod, route, srcFilePath, clientEntry, manifest
12060
12060
  };
12061
12061
  const result = await mod.render(route, ctx);
12062
12062
  let html = result.body;
12063
- let cssLinks = "";
12063
+ let cssLinks = [];
12064
12064
  if (manifest) {
12065
12065
  cssLinks = collectCssForModules(manifest, moduleIds, projectRoot);
12066
12066
  }
12067
12067
  if (clientEntry) {
12068
- const scriptTag = `<script type="module" src="/${clientEntry}"></script>`;
12069
- const headInjected = cssLinks ? html.replace("<head>", "<head>" + cssLinks) : html;
12068
+ const scriptTag = `<script type="module" src="${path6.join(baseUrl, clientEntry).replace(/\\/g, "/")}"></script>`;
12069
+ const headInjected = cssLinks ? html.replace(
12070
+ "<head>",
12071
+ "<head>" + cssLinks.map(
12072
+ (f) => `<link rel="stylesheet" type="text/css" href="${path6.join(baseUrl, f).replace(/\\/g, "/")}">`
12073
+ ).join("")
12074
+ ) : html;
12070
12075
  html = headInjected.includes("</body>") ? headInjected.replace("</body>", scriptTag + "</body>") : headInjected + scriptTag;
12071
12076
  }
12072
12077
  return html;
@@ -12234,12 +12239,15 @@ ${code}`, "utf-8");
12234
12239
  }
12235
12240
 
12236
12241
  // src/index.ts
12237
- import { build } from "vite";
12242
+ import {
12243
+ build
12244
+ } from "vite";
12238
12245
  function kiru(opts = {}) {
12239
12246
  let state;
12240
12247
  let log;
12241
12248
  let virtualModules = {};
12242
12249
  let inlineConfig;
12250
+ let resolvedConfig;
12243
12251
  const mainPlugin = {
12244
12252
  name: "vite-plugin-kiru",
12245
12253
  config(config) {
@@ -12247,6 +12255,7 @@ function kiru(opts = {}) {
12247
12255
  return createViteConfig(config, opts);
12248
12256
  },
12249
12257
  async configResolved(config) {
12258
+ resolvedConfig = config;
12250
12259
  const initialState = createPluginState(opts);
12251
12260
  state = updatePluginState(initialState, config, opts);
12252
12261
  log = createLogger(state);
@@ -12303,6 +12312,7 @@ function kiru(opts = {}) {
12303
12312
  server,
12304
12313
  url,
12305
12314
  state.projectRoot,
12315
+ resolvedConfig?.base ?? "/",
12306
12316
  () => resolveUserDocument(projectRoot, ssgOptions)
12307
12317
  );
12308
12318
  res.statusCode = status;
@@ -12337,7 +12347,8 @@ function kiru(opts = {}) {
12337
12347
  state,
12338
12348
  outputOptions,
12339
12349
  bundle,
12340
- log
12350
+ log,
12351
+ resolvedConfig?.base ?? "/"
12341
12352
  );
12342
12353
  } catch (e) {
12343
12354
  log(ANSI.red("[SSG]: prerender failed"), e);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-kiru",
3
- "version": "0.32.1",
3
+ "version": "0.32.2",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -17,8 +17,8 @@
17
17
  "rollup": "^4.46.2",
18
18
  "tsx": "^4.20.3",
19
19
  "typescript": "^5.9.2",
20
- "kiru-devtools-client": "^0.0.0",
21
- "kiru-devtools-host": "^1.0.0"
20
+ "kiru-devtools-host": "^1.0.0",
21
+ "kiru-devtools-client": "^0.0.0"
22
22
  },
23
23
  "dependencies": {
24
24
  "glob": "^12.0.0",