vite-plugin-kiru 0.29.0-preview.2 → 0.29.1

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/build.dev.ts CHANGED
@@ -9,7 +9,7 @@ await esbuild
9
9
  target: "esnext",
10
10
  format: "esm",
11
11
  outfile: "./dist/index.js",
12
- external: ["kiru"],
12
+ external: ["kiru", "vite"],
13
13
  write: true,
14
14
  plugins: [
15
15
  {
package/dist/index.js CHANGED
@@ -2206,7 +2206,6 @@ import {
2206
2206
  render as kiruServerRender,
2207
2207
  generateStaticPaths as kiruServerGenerateStaticPaths
2208
2208
  } from "kiru/router/server"
2209
- import { renderToString } from "kiru"
2210
2209
  import Document from "${userDoc}"
2211
2210
  import { pages, layouts } from "${VIRTUAL_ROUTES_ID}"
2212
2211
 
@@ -2222,15 +2221,11 @@ export async function generateStaticPaths() {
2222
2221
  }
2223
2222
  function createEntryClientModule() {
2224
2223
  return `
2225
- import { onLoadedDev } from "kiru/router/dev"
2226
2224
  import { initClient } from "kiru/router/client"
2227
2225
  import { dir, baseUrl, pages, layouts } from "${VIRTUAL_ROUTES_ID}"
2228
- import "${resolveUserDocument2()}" // todo: only include this in dev mode
2226
+ import "${resolveUserDocument2()}"
2229
2227
 
2230
2228
  initClient({ dir, baseUrl, pages, layouts })
2231
- if (import.meta.env.DEV) {
2232
- onLoadedDev()
2233
- }
2234
2229
  `;
2235
2230
  }
2236
2231
  return {
@@ -2349,8 +2344,6 @@ function createViteConfig(config, opts) {
2349
2344
  ...config.build,
2350
2345
  ssr,
2351
2346
  manifest: "vite-manifest.json",
2352
- ssrEmitAssets: true,
2353
- ssrManifest: true,
2354
2347
  outDir: desiredOutDir,
2355
2348
  rollupOptions: {
2356
2349
  ...rollup,
@@ -3260,6 +3253,8 @@ async function handleSSR(server, url, projectRoot, resolveUserDocument2) {
3260
3253
  VIRTUAL_ENTRY_SERVER_ID
3261
3254
  );
3262
3255
  const moduleIds = [];
3256
+ const documentModule = resolveUserDocument2().substring(projectRoot.length);
3257
+ moduleIds.push(documentModule);
3263
3258
  const ctx = {
3264
3259
  registerModule: (moduleId) => {
3265
3260
  moduleIds.push(moduleId);
@@ -3267,12 +3262,10 @@ async function handleSSR(server, url, projectRoot, resolveUserDocument2) {
3267
3262
  registerPreloadedPageProps: () => {
3268
3263
  }
3269
3264
  };
3270
- const { status, immediate, stream } = await mod.render(url, ctx);
3271
- let html = injectClientScript(immediate);
3265
+ const { status, body } = await mod.render(url, ctx);
3266
+ let html = injectClientScript(body);
3272
3267
  const importedModules = /* @__PURE__ */ new Set();
3273
3268
  const seen = /* @__PURE__ */ new Set();
3274
- const documentModule = resolveUserDocument2().substring(projectRoot.length);
3275
- moduleIds.push(documentModule);
3276
3269
  const scan = (mod2) => {
3277
3270
  if (importedModules.has(mod2)) return;
3278
3271
  importedModules.add(mod2);
@@ -3307,7 +3300,7 @@ async function handleSSR(server, url, projectRoot, resolveUserDocument2) {
3307
3300
  });
3308
3301
  html = html.replace("<head>", "<head>" + stylesheets.join("\n"));
3309
3302
  }
3310
- return { status, html, stream };
3303
+ return { status, html };
3311
3304
  }
3312
3305
 
3313
3306
  // src/preview-server.ts
@@ -4660,7 +4653,7 @@ async function renderRoute(state, mod, route, srcFilePath, clientEntry, cssLinks
4660
4653
  }
4661
4654
  };
4662
4655
  const result = await mod.render(route, ctx);
4663
- let html = result.immediate;
4656
+ let html = result.body;
4664
4657
  if (clientEntry) {
4665
4658
  const scriptTag = `<script type="module" src="/${clientEntry}"></script>`;
4666
4659
  const headInjected = cssLinks ? html.replace("<head>", "<head>" + cssLinks) : html;
@@ -4765,13 +4758,16 @@ function shouldTransformFile(id, state) {
4765
4758
  }
4766
4759
 
4767
4760
  // src/index.ts
4761
+ import { build } from "vite";
4768
4762
  function kiru(opts = {}) {
4769
4763
  let state;
4770
4764
  let log;
4771
4765
  let virtualModules = {};
4772
- return {
4766
+ let inlineConfig;
4767
+ const mainPlugin = {
4773
4768
  name: "vite-plugin-kiru",
4774
4769
  config(config) {
4770
+ inlineConfig = config;
4775
4771
  return createViteConfig(config, opts);
4776
4772
  },
4777
4773
  configResolved(config) {
@@ -4827,7 +4823,7 @@ function kiru(opts = {}) {
4827
4823
  }
4828
4824
  const accept = req.headers["accept"] || "";
4829
4825
  if (typeof accept === "string" && accept.includes("text/html") && !url.startsWith("/node_modules/") && !url.startsWith("/@") && !url.startsWith(dtHostScriptPath) && !url.startsWith(dtClientPathname)) {
4830
- const { status, html, stream } = await handleSSR(
4826
+ const { status, html } = await handleSSR(
4831
4827
  server,
4832
4828
  url,
4833
4829
  state.projectRoot,
@@ -4835,12 +4831,7 @@ function kiru(opts = {}) {
4835
4831
  );
4836
4832
  res.statusCode = status;
4837
4833
  res.setHeader("Content-Type", "text/html");
4838
- res.write(html);
4839
- if (stream) {
4840
- stream.pipe(res);
4841
- } else {
4842
- res.end();
4843
- }
4834
+ res.end(html);
4844
4835
  return;
4845
4836
  }
4846
4837
  } catch (e) {
@@ -4916,6 +4907,28 @@ function kiru(opts = {}) {
4916
4907
  };
4917
4908
  }
4918
4909
  };
4910
+ return [
4911
+ mainPlugin,
4912
+ {
4913
+ name: "vite-plugin-kiru:ssg",
4914
+ apply: "build",
4915
+ enforce: "post",
4916
+ async closeBundle(error) {
4917
+ if (error || this.environment.config.build.ssr || !state.ssgOptions)
4918
+ return;
4919
+ log(ANSI.cyan("[SSG]"), "Starting SSG build...");
4920
+ await build({
4921
+ ...inlineConfig,
4922
+ configFile: false,
4923
+ build: {
4924
+ ...inlineConfig?.build,
4925
+ ssr: true
4926
+ }
4927
+ });
4928
+ log(ANSI.cyan("[SSG]"), "SSG build complete!");
4929
+ }
4930
+ }
4931
+ ];
4919
4932
  }
4920
4933
  function onHMR(callback) {
4921
4934
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "vite-plugin-kiru",
3
- "version": "0.29.0-preview.2",
3
+ "version": "0.29.1",
4
4
  "description": "",
5
5
  "main": "dist/index.js",
6
6
  "type": "module",
@@ -9,7 +9,7 @@
9
9
  "author": "",
10
10
  "license": "ISC",
11
11
  "peerDependencies": {
12
- "kiru": ">=0.51.0-preview.0"
12
+ "kiru": ">=0.51.0"
13
13
  },
14
14
  "devDependencies": {
15
15
  "@types/node": "^22.17.0",