@hono/vite-ssg 0.0.1 → 0.1.0

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/README.md CHANGED
@@ -58,15 +58,8 @@ wrangler pages deploy ./dist
58
58
  The options are below.
59
59
 
60
60
  ```ts
61
- type BuildConfig = {
62
- outputDir?: string
63
- publicDir?: string
64
- }
65
-
66
61
  type SSGOptions = {
67
62
  entry?: string
68
- rootDir?: string
69
- build?: BuildConfig
70
63
  }
71
64
  ```
72
65
 
@@ -75,11 +68,6 @@ Default values:
75
68
  ```ts
76
69
  const defaultOptions = {
77
70
  entry: './src/index.tsx',
78
- tempDir: '.hono',
79
- build: {
80
- outputDir: '../dist',
81
- publicDir: '../public',
82
- },
83
71
  }
84
72
  ```
85
73
 
package/dist/ssg.d.ts CHANGED
@@ -1,13 +1,7 @@
1
1
  import { Plugin } from 'vite';
2
2
 
3
- type BuildConfig = {
4
- outputDir?: string;
5
- publicDir?: string;
6
- };
7
3
  type SSGOptions = {
8
4
  entry?: string;
9
- tempDir?: string;
10
- build?: BuildConfig;
11
5
  };
12
6
  declare const defaultOptions: Required<SSGOptions>;
13
7
  declare const ssgBuild: (options?: SSGOptions) => Plugin;
package/dist/ssg.js CHANGED
@@ -1,21 +1,45 @@
1
- import fs from "node:fs/promises";
1
+ import { relative } from "node:path";
2
2
  import { toSSG } from "hono/ssg";
3
3
  import { createServer } from "vite";
4
4
  const defaultOptions = {
5
- entry: "./src/index.tsx",
6
- tempDir: ".hono",
7
- build: {
8
- outputDir: "../dist",
9
- publicDir: "../public"
10
- }
5
+ entry: "./src/index.tsx"
11
6
  };
12
7
  const ssgBuild = (options) => {
8
+ const virtualId = "virtual:ssg-void-entry";
9
+ const resolvedVirtualId = "\0" + virtualId;
13
10
  const entry = options?.entry ?? defaultOptions.entry;
14
- const tempDir = options?.tempDir ?? defaultOptions.tempDir;
11
+ let config;
15
12
  return {
16
13
  name: "@hono/vite-ssg",
17
14
  apply: "build",
18
- config: async () => {
15
+ async config() {
16
+ return {
17
+ build: {
18
+ rollupOptions: {
19
+ input: [virtualId]
20
+ }
21
+ }
22
+ };
23
+ },
24
+ configResolved(resolved) {
25
+ config = resolved;
26
+ },
27
+ resolveId(id) {
28
+ if (id === virtualId) {
29
+ return resolvedVirtualId;
30
+ }
31
+ },
32
+ load(id) {
33
+ if (id === resolvedVirtualId) {
34
+ return 'console.log("suppress empty chunk message")';
35
+ }
36
+ },
37
+ async generateBundle(_outputOptions, bundle) {
38
+ for (const chunk of Object.values(bundle)) {
39
+ if (chunk.type === "chunk" && chunk.moduleIds.includes(resolvedVirtualId)) {
40
+ delete bundle[chunk.fileName];
41
+ }
42
+ }
19
43
  const server = await createServer({
20
44
  plugins: [],
21
45
  build: { ssr: true }
@@ -26,27 +50,26 @@ const ssgBuild = (options) => {
26
50
  if (!app) {
27
51
  throw new Error(`Failed to find a named export "default" from ${entry}`);
28
52
  }
29
- console.log(`Build files into temp directory: ${tempDir}`);
30
- const result = await toSSG(app, fs, { dir: tempDir });
53
+ const outDir = config.build.outDir;
54
+ const result = await toSSG(
55
+ app,
56
+ {
57
+ writeFile: async (path, data) => {
58
+ this.emitFile({
59
+ type: "asset",
60
+ fileName: relative(outDir, path),
61
+ source: data
62
+ });
63
+ },
64
+ async mkdir() {
65
+ return;
66
+ }
67
+ },
68
+ { dir: outDir }
69
+ );
31
70
  if (!result.success) {
32
71
  throw result.error;
33
72
  }
34
- if (result.files) {
35
- for (const file of result.files) {
36
- console.log(`Generated: ${file}`);
37
- }
38
- }
39
- return {
40
- root: tempDir,
41
- publicDir: options?.build?.publicDir ?? defaultOptions.build.publicDir,
42
- build: {
43
- outDir: options?.build?.outputDir ?? defaultOptions.build.outputDir,
44
- rollupOptions: {
45
- input: result.files ? [...result.files] : []
46
- },
47
- emptyOutDir: true
48
- }
49
- };
50
73
  }
51
74
  };
52
75
  };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@hono/vite-ssg",
3
3
  "description": "Vite plugin to generate a static site from your Hono application",
4
- "version": "0.0.1",
4
+ "version": "0.1.0",
5
5
  "types": "dist/index.d.ts",
6
6
  "module": "dist/index.js",
7
7
  "type": "module",
@@ -40,11 +40,12 @@
40
40
  },
41
41
  "homepage": "https://github.com/honojs/vite-plugins",
42
42
  "devDependencies": {
43
- "hono": "4.0.0-rc.2",
43
+ "glob": "^10.3.10",
44
+ "hono": "^4.0.1",
44
45
  "publint": "^0.1.12",
45
46
  "rimraf": "^5.0.1",
46
47
  "tsup": "^7.2.0",
47
- "vite": "^5.0.12",
48
+ "vite": "^5.1.1",
48
49
  "vitest": "^1.2.1"
49
50
  },
50
51
  "peerDependencies": {