@hono/vite-ssg 0.0.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/README.md +92 -0
- package/dist/index.d.ts +6 -0
- package/dist/index.js +5 -0
- package/dist/ssg.d.ts +15 -0
- package/dist/ssg.js +56 -0
- package/package.json +56 -0
package/README.md
ADDED
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
# @hono/vite-ssg
|
|
2
|
+
|
|
3
|
+
`@hono/vite-ssg` is a Vite plugin to generate a static site from your Hono application.
|
|
4
|
+
|
|
5
|
+
## Usage
|
|
6
|
+
|
|
7
|
+
### Installation
|
|
8
|
+
|
|
9
|
+
You can install `vite` and `@hono/vite-ssg` via npm.
|
|
10
|
+
|
|
11
|
+
```plain
|
|
12
|
+
npm i -D vite @hono/vite-ssg
|
|
13
|
+
```
|
|
14
|
+
|
|
15
|
+
Or you can install them with Bun.
|
|
16
|
+
|
|
17
|
+
```plain
|
|
18
|
+
bun add vite @hono/vite-ssg
|
|
19
|
+
```
|
|
20
|
+
|
|
21
|
+
### Settings
|
|
22
|
+
|
|
23
|
+
Add `"type": "module"` to your `package.json`. Then, create `vite.config.ts` and edit it.
|
|
24
|
+
|
|
25
|
+
```ts
|
|
26
|
+
import { defineConfig } from 'vite'
|
|
27
|
+
import ssg from '@hono/vite-ssg'
|
|
28
|
+
|
|
29
|
+
export default defineConfig({
|
|
30
|
+
plugins: [ssg()],
|
|
31
|
+
})
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
### Build
|
|
35
|
+
|
|
36
|
+
Just run `vite build`.
|
|
37
|
+
|
|
38
|
+
```text
|
|
39
|
+
npm exec vite build
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Or
|
|
43
|
+
|
|
44
|
+
```text
|
|
45
|
+
bunx --bun vite build
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### Deploy to Cloudflare Pages
|
|
49
|
+
|
|
50
|
+
Run the `wrangler` command.
|
|
51
|
+
|
|
52
|
+
```text
|
|
53
|
+
wrangler pages deploy ./dist
|
|
54
|
+
```
|
|
55
|
+
|
|
56
|
+
## Options
|
|
57
|
+
|
|
58
|
+
The options are below.
|
|
59
|
+
|
|
60
|
+
```ts
|
|
61
|
+
type BuildConfig = {
|
|
62
|
+
outputDir?: string
|
|
63
|
+
publicDir?: string
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
type SSGOptions = {
|
|
67
|
+
entry?: string
|
|
68
|
+
rootDir?: string
|
|
69
|
+
build?: BuildConfig
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
Default values:
|
|
74
|
+
|
|
75
|
+
```ts
|
|
76
|
+
const defaultOptions = {
|
|
77
|
+
entry: './src/index.tsx',
|
|
78
|
+
tempDir: '.hono',
|
|
79
|
+
build: {
|
|
80
|
+
outputDir: '../dist',
|
|
81
|
+
publicDir: '../public',
|
|
82
|
+
},
|
|
83
|
+
}
|
|
84
|
+
```
|
|
85
|
+
|
|
86
|
+
## Authors
|
|
87
|
+
|
|
88
|
+
- Yusuke Wada <https://github.com/yusukebe>
|
|
89
|
+
|
|
90
|
+
## License
|
|
91
|
+
|
|
92
|
+
MIT
|
package/dist/index.d.ts
ADDED
package/dist/index.js
ADDED
package/dist/ssg.d.ts
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { Plugin } from 'vite';
|
|
2
|
+
|
|
3
|
+
type BuildConfig = {
|
|
4
|
+
outputDir?: string;
|
|
5
|
+
publicDir?: string;
|
|
6
|
+
};
|
|
7
|
+
type SSGOptions = {
|
|
8
|
+
entry?: string;
|
|
9
|
+
tempDir?: string;
|
|
10
|
+
build?: BuildConfig;
|
|
11
|
+
};
|
|
12
|
+
declare const defaultOptions: Required<SSGOptions>;
|
|
13
|
+
declare const ssgBuild: (options?: SSGOptions) => Plugin;
|
|
14
|
+
|
|
15
|
+
export { defaultOptions, ssgBuild };
|
package/dist/ssg.js
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import fs from "node:fs/promises";
|
|
2
|
+
import { toSSG } from "hono/ssg";
|
|
3
|
+
import { createServer } from "vite";
|
|
4
|
+
const defaultOptions = {
|
|
5
|
+
entry: "./src/index.tsx",
|
|
6
|
+
tempDir: ".hono",
|
|
7
|
+
build: {
|
|
8
|
+
outputDir: "../dist",
|
|
9
|
+
publicDir: "../public"
|
|
10
|
+
}
|
|
11
|
+
};
|
|
12
|
+
const ssgBuild = (options) => {
|
|
13
|
+
const entry = options?.entry ?? defaultOptions.entry;
|
|
14
|
+
const tempDir = options?.tempDir ?? defaultOptions.tempDir;
|
|
15
|
+
return {
|
|
16
|
+
name: "@hono/vite-ssg",
|
|
17
|
+
apply: "build",
|
|
18
|
+
config: async () => {
|
|
19
|
+
const server = await createServer({
|
|
20
|
+
plugins: [],
|
|
21
|
+
build: { ssr: true }
|
|
22
|
+
});
|
|
23
|
+
const module = await server.ssrLoadModule(entry);
|
|
24
|
+
server.close();
|
|
25
|
+
const app = module["default"];
|
|
26
|
+
if (!app) {
|
|
27
|
+
throw new Error(`Failed to find a named export "default" from ${entry}`);
|
|
28
|
+
}
|
|
29
|
+
console.log(`Build files into temp directory: ${tempDir}`);
|
|
30
|
+
const result = await toSSG(app, fs, { dir: tempDir });
|
|
31
|
+
if (!result.success) {
|
|
32
|
+
throw result.error;
|
|
33
|
+
}
|
|
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
|
+
}
|
|
51
|
+
};
|
|
52
|
+
};
|
|
53
|
+
export {
|
|
54
|
+
defaultOptions,
|
|
55
|
+
ssgBuild
|
|
56
|
+
};
|
package/package.json
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@hono/vite-ssg",
|
|
3
|
+
"description": "Vite plugin to generate a static site from your Hono application",
|
|
4
|
+
"version": "0.0.1",
|
|
5
|
+
"types": "dist/index.d.ts",
|
|
6
|
+
"module": "dist/index.js",
|
|
7
|
+
"type": "module",
|
|
8
|
+
"scripts": {
|
|
9
|
+
"test": "vitest --run",
|
|
10
|
+
"build": "rimraf dist && tsup && publint",
|
|
11
|
+
"watch": "tsup --watch",
|
|
12
|
+
"prerelease": "yarn build",
|
|
13
|
+
"release": "yarn publish"
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"dist"
|
|
17
|
+
],
|
|
18
|
+
"exports": {
|
|
19
|
+
".": {
|
|
20
|
+
"types": "./dist/index.d.ts",
|
|
21
|
+
"import": "./dist/index.js"
|
|
22
|
+
}
|
|
23
|
+
},
|
|
24
|
+
"typesVersions": {
|
|
25
|
+
"*": {
|
|
26
|
+
"types": [
|
|
27
|
+
"./dist/types"
|
|
28
|
+
]
|
|
29
|
+
}
|
|
30
|
+
},
|
|
31
|
+
"author": "Yusuke Wada <yusuke@kamawada.com> (https://github.com/yusukebe)",
|
|
32
|
+
"license": "MIT",
|
|
33
|
+
"repository": {
|
|
34
|
+
"type": "git",
|
|
35
|
+
"url": "https://github.com/honojs/vite-plugins.git"
|
|
36
|
+
},
|
|
37
|
+
"publishConfig": {
|
|
38
|
+
"registry": "https://registry.npmjs.org",
|
|
39
|
+
"access": "public"
|
|
40
|
+
},
|
|
41
|
+
"homepage": "https://github.com/honojs/vite-plugins",
|
|
42
|
+
"devDependencies": {
|
|
43
|
+
"hono": "4.0.0-rc.2",
|
|
44
|
+
"publint": "^0.1.12",
|
|
45
|
+
"rimraf": "^5.0.1",
|
|
46
|
+
"tsup": "^7.2.0",
|
|
47
|
+
"vite": "^5.0.12",
|
|
48
|
+
"vitest": "^1.2.1"
|
|
49
|
+
},
|
|
50
|
+
"peerDependencies": {
|
|
51
|
+
"hono": ">=4.0.0"
|
|
52
|
+
},
|
|
53
|
+
"engines": {
|
|
54
|
+
"node": ">=18.14.1"
|
|
55
|
+
}
|
|
56
|
+
}
|