next-single-file 1.0.1 → 1.0.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 (3) hide show
  1. package/README.md +10 -3
  2. package/dist/cli.js +9 -6
  3. package/package.json +4 -4
package/README.md CHANGED
@@ -1,7 +1,7 @@
1
1
  # next-single-file
2
2
 
3
3
  [![npm version](https://img.shields.io/npm/v/next-single-file?color=black)](https://www.npmjs.com/package/next-single-file)
4
- [![npm downloads](https://img.shields.io/npm/dm/next-single-file?color=blac)](https://www.npmjs.com/package/next-single-file)
4
+ [![npm downloads](https://img.shields.io/npm/dm/next-single-file?color=black)](https://www.npmjs.com/package/next-single-file)
5
5
  [![Next.js](https://img.shields.io/badge/Next.js-16-black?logo=next.js)](https://nextjs.org)
6
6
  [![Bun](https://img.shields.io/badge/runtime-bun-black?logo=bun)](https://bun.sh)
7
7
 
@@ -56,17 +56,24 @@ const nextConfig = {
56
56
  module.exports = nextConfig;
57
57
  ```
58
58
 
59
+ > [!WARNING]
60
+ > **Purely Client-Side Runtime**
61
+ > This tool generates a standalone bundle with no backend.
62
+ > - **Server Logic:** Features like Server Actions, `cookies()`, and Middleware are not supported.
63
+ > - **Dynamic Routes:** You must use `generateStaticParams` for any dynamic paths (e.g., `[id].tsx`) to ensure they are pre-rendered into the `out/` directory before bundling.
64
+ > - **RSC:** React Server Components are supported only insofar as they can be statically rendered to HTML at build time.
65
+
59
66
  ### 2. Build Your Next.js App
60
67
 
61
68
  ```bash
62
- npm run build
63
- # or
69
+ # Any pkg manager is fine
64
70
  bun run build
65
71
  ```
66
72
 
67
73
  ### 3. Generate Single HTML File
68
74
 
69
75
  ```bash
76
+ # npx works too, you need bun installed on your system though
70
77
  bunx next-single-file --input out --output dist/index.html
71
78
  ```
72
79
 
package/dist/cli.js CHANGED
@@ -2,8 +2,8 @@
2
2
  // @bun
3
3
 
4
4
  // src/parser.ts
5
- import { readdir, readFile } from "node:fs/promises";
6
- import { join, relative, extname } from "node:path";
5
+ import { readdir, readFile } from "fs/promises";
6
+ import { join, relative, extname } from "path";
7
7
  async function walk(dir) {
8
8
  const files = [];
9
9
  const entries = await readdir(dir, { withFileTypes: true });
@@ -412,14 +412,14 @@ function extractMeta(html) {
412
412
  function escapeScriptTag(js) {
413
413
  return js.replace(/<\/script>/gi, "<\\/script>");
414
414
  }
415
+ function minifyHtml(html) {
416
+ return html.replace(/<!--[\s\S]*?-->/g, "").replace(/>\s+</g, "><").replace(/\s{2,}/g, " ").trim();
417
+ }
415
418
  function bundleToSingleHtml(inlined, routerShim) {
416
419
  const indexRoute = inlined.routes.find((r) => r.path === "/");
417
420
  if (!indexRoute) {
418
421
  throw new Error("No index route found");
419
422
  }
420
- const anyRoute = inlined.routes[0];
421
- if (!anyRoute)
422
- throw new Error("No routes found");
423
423
  const htmlAttrs = extractHtmlAttrs(indexRoute.htmlContent);
424
424
  const bodyAttrs = extractBodyAttrs(indexRoute.htmlContent);
425
425
  const title = extractTitle(indexRoute.headContent);
@@ -445,7 +445,7 @@ function bundleToSingleHtml(inlined, routerShim) {
445
445
  };
446
446
  }
447
447
  `;
448
- return `<!DOCTYPE html><!--${inlined.buildId}-->
448
+ const finalHtml = `<!DOCTYPE html><!--${inlined.buildId}-->
449
449
  <html${htmlAttrs}>
450
450
  <head>
451
451
  <meta charset="utf-8">
@@ -473,6 +473,7 @@ ${escapeScriptTag(routerShim)}
473
473
  </script>
474
474
  </body>
475
475
  </html>`;
476
+ return minifyHtml(finalHtml);
476
477
  }
477
478
 
478
479
  // index.ts
@@ -511,3 +512,5 @@ await $`mkdir -p ${outputFile.split("/").slice(0, -1).join("/") || "."}`.quiet()
511
512
  await Bun.write(outputFile, html);
512
513
  console.log(`\u2705 Done! Output: ${outputFile}`);
513
514
  console.log(` Size: ${(html.length / 1024).toFixed(1)} KB`);
515
+ console.log("Star us: https://github.com/simples-tools/next-single-file");
516
+ console.log("Report bugs: https://github.com/simples-tools/next-single-file/issues");
package/package.json CHANGED
@@ -1,15 +1,15 @@
1
1
  {
2
2
  "name": "next-single-file",
3
- "version": "1.0.1",
3
+ "version": "1.0.2",
4
4
  "description": "Convert Next.js static export to a single HTML file with hash routing",
5
5
  "bin": {
6
- "next-single-file": "./dist/cli.js"
6
+ "next-single-file": "dist/cli.js"
7
7
  },
8
8
  "repository": {
9
9
  "type": "git",
10
- "url": "https://github.com/simples-tools/next-single-file"
10
+ "url": "git+https://github.com/simples-tools/next-single-file.git"
11
11
  },
12
- "author": "@brrock <github.com/brrock>",
12
+ "author": "@brrock <github.com/brrock>",
13
13
  "files": [
14
14
  "dist/cli.js"
15
15
  ],