honox 0.1.43 → 0.1.45
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 +108 -66
- package/dist/server/server.js +25 -8
- package/dist/server/utils/file.js +1 -1
- package/package.json +3 -2
package/README.md
CHANGED
|
@@ -499,7 +499,7 @@ Configure react in `vite.config.ts`.
|
|
|
499
499
|
|
|
500
500
|
```ts
|
|
501
501
|
// vite.config.ts
|
|
502
|
-
import build from '@hono/vite-build/cloudflare-
|
|
502
|
+
import build from '@hono/vite-build/cloudflare-workers'
|
|
503
503
|
import honox from 'honox/vite'
|
|
504
504
|
import { defineConfig } from 'vite'
|
|
505
505
|
|
|
@@ -571,7 +571,7 @@ Configure react in `vite.config.ts`.
|
|
|
571
571
|
|
|
572
572
|
```ts
|
|
573
573
|
// vite.config.ts
|
|
574
|
-
import build from '@hono/vite-build/cloudflare-
|
|
574
|
+
import build from '@hono/vite-build/cloudflare-workers'
|
|
575
575
|
import honox from 'honox/vite'
|
|
576
576
|
import { defineConfig } from 'vite'
|
|
577
577
|
|
|
@@ -767,7 +767,7 @@ Finally, add `vite.config.ts` configuration to output assets for the production.
|
|
|
767
767
|
```ts
|
|
768
768
|
import honox from 'honox/vite'
|
|
769
769
|
import { defineConfig } from 'vite'
|
|
770
|
-
import build from '@hono/vite-build/cloudflare-
|
|
770
|
+
import build from '@hono/vite-build/cloudflare-workers'
|
|
771
771
|
import tailwindcss from '@tailwindcss/vite'
|
|
772
772
|
|
|
773
773
|
export default defineConfig({
|
|
@@ -839,20 +839,22 @@ export default function Top() {
|
|
|
839
839
|
|
|
840
840
|
### Cloudflare Bindings
|
|
841
841
|
|
|
842
|
-
If you want to use Cloudflare's Bindings in your development environment, create `wrangler.
|
|
842
|
+
If you want to use Cloudflare's Bindings in your development environment, create `wrangler.jsonc` and configure it properly.
|
|
843
843
|
|
|
844
|
-
```
|
|
845
|
-
|
|
846
|
-
|
|
847
|
-
|
|
848
|
-
|
|
849
|
-
|
|
850
|
-
|
|
851
|
-
|
|
852
|
-
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
844
|
+
```jsonc
|
|
845
|
+
// wrangler.jsonc
|
|
846
|
+
{
|
|
847
|
+
"$schema": "node_modules/wrangler/config-schema.json",
|
|
848
|
+
"name": "my-project-name",
|
|
849
|
+
"main": "./dist/index.js",
|
|
850
|
+
"compatibility_date": "2025-08-03",
|
|
851
|
+
"compatibility_flags": [
|
|
852
|
+
"nodejs_compat"
|
|
853
|
+
],
|
|
854
|
+
"assets": {
|
|
855
|
+
"directory": "./dist"
|
|
856
|
+
}
|
|
857
|
+
}
|
|
856
858
|
```
|
|
857
859
|
|
|
858
860
|
In `vite.config.ts`, use the Cloudflare Adapter in `@hono/vite-dev-server`.
|
|
@@ -873,52 +875,12 @@ export default defineConfig({
|
|
|
873
875
|
})
|
|
874
876
|
```
|
|
875
877
|
|
|
876
|
-
## Deployment
|
|
877
|
-
|
|
878
|
-
Since a HonoX instance is essentially a Hono instance, it can be deployed on any platform that Hono supports.
|
|
879
|
-
|
|
880
|
-
### Cloudflare Pages
|
|
881
|
-
|
|
882
|
-
Add the `wrangler.toml`:
|
|
883
|
-
|
|
884
|
-
```toml
|
|
885
|
-
# wrangler.toml
|
|
886
|
-
name = "my-project-name"
|
|
887
|
-
compatibility_date = "2024-04-01"
|
|
888
|
-
compatibility_flags = [ "nodejs_compat" ]
|
|
889
|
-
pages_build_output_dir = "./dist"
|
|
890
|
-
```
|
|
891
|
-
|
|
892
|
-
Setup the `vite.config.ts`:
|
|
893
|
-
|
|
894
|
-
```ts
|
|
895
|
-
// vite.config.ts
|
|
896
|
-
import { defineConfig } from 'vite'
|
|
897
|
-
import honox from 'honox/vite'
|
|
898
|
-
import build from '@hono/vite-build/cloudflare-pages'
|
|
899
|
-
|
|
900
|
-
export default defineConfig({
|
|
901
|
-
plugins: [honox(), build()],
|
|
902
|
-
})
|
|
903
|
-
```
|
|
904
|
-
|
|
905
|
-
Build command (including a client):
|
|
906
|
-
|
|
907
|
-
```txt
|
|
908
|
-
vite build --mode client && vite build
|
|
909
|
-
```
|
|
910
|
-
|
|
911
|
-
Deploy with the following commands after the build. Ensure you have [Wrangler](https://developers.cloudflare.com/workers/wrangler/) installed:
|
|
912
|
-
|
|
913
|
-
```txt
|
|
914
|
-
wrangler pages deploy
|
|
915
|
-
```
|
|
916
|
-
|
|
917
878
|
### SSG - Static Site Generation
|
|
918
879
|
|
|
919
880
|
Using Hono's SSG feature, you can generate static HTML for each route.
|
|
920
881
|
|
|
921
882
|
```ts
|
|
883
|
+
// vite.config.ts
|
|
922
884
|
import { defineConfig } from 'vite'
|
|
923
885
|
import honox from 'honox/vite'
|
|
924
886
|
import ssg from '@hono/vite-ssg'
|
|
@@ -961,31 +923,111 @@ export default defineConfig(({ mode }) => {
|
|
|
961
923
|
|
|
962
924
|
Build command (including a client):
|
|
963
925
|
|
|
964
|
-
```
|
|
926
|
+
```sh
|
|
965
927
|
vite build --mode client && vite build
|
|
966
928
|
```
|
|
967
929
|
|
|
968
|
-
|
|
930
|
+
## Deployment
|
|
969
931
|
|
|
970
|
-
|
|
971
|
-
wrangler pages deploy ./dist
|
|
972
|
-
```
|
|
932
|
+
[`@hono/vite-build`]: https://www.npmjs.com/package/@hono/vite-build
|
|
973
933
|
|
|
974
|
-
|
|
934
|
+
HonoX consists of a Hono instance and Vite configuration, so it can be deployed on any platform that Hono supports.
|
|
935
|
+
[`@hono/vite-build`] provides build configurations for Cloudflare Workers, Node.js, Bun, and many other platforms.
|
|
936
|
+
|
|
937
|
+
### Cloudflare Workers
|
|
938
|
+
|
|
939
|
+
If you create a project using the `create-hono` command and select `x-basic`, the configuration for deploying to Cloudflare Workers is already included by default.
|
|
940
|
+
|
|
941
|
+
Add the `wrangler.jsonc`:
|
|
942
|
+
|
|
943
|
+
```jsonc
|
|
944
|
+
// wrangler.jsonc
|
|
945
|
+
{
|
|
946
|
+
"$schema": "node_modules/wrangler/config-schema.json",
|
|
947
|
+
"name": "my-project-name",
|
|
948
|
+
"main": "./dist/index.js",
|
|
949
|
+
"compatibility_date": "2025-08-03",
|
|
950
|
+
"compatibility_flags": [
|
|
951
|
+
"nodejs_compat"
|
|
952
|
+
],
|
|
953
|
+
"assets": {
|
|
954
|
+
"directory": "./dist"
|
|
955
|
+
}
|
|
956
|
+
}
|
|
957
|
+
```
|
|
975
958
|
|
|
976
|
-
|
|
959
|
+
Setup the `vite.config.ts`:
|
|
977
960
|
|
|
978
961
|
```ts
|
|
979
962
|
// vite.config.ts
|
|
963
|
+
import build from '@hono/vite-build/cloudflare-workers'
|
|
964
|
+
import adapter from '@hono/vite-dev-server/cloudflare'
|
|
965
|
+
import tailwindcss from '@tailwindcss/vite'
|
|
966
|
+
import honox from 'honox/vite'
|
|
980
967
|
import { defineConfig } from 'vite'
|
|
968
|
+
|
|
969
|
+
export default defineConfig({
|
|
970
|
+
plugins: [
|
|
971
|
+
honox({
|
|
972
|
+
devServer: { adapter },
|
|
973
|
+
client: { input: ['./app/style.css'] }
|
|
974
|
+
}),
|
|
975
|
+
tailwindcss(),
|
|
976
|
+
build()
|
|
977
|
+
]
|
|
978
|
+
})
|
|
979
|
+
```
|
|
980
|
+
|
|
981
|
+
Build command (including a client):
|
|
982
|
+
|
|
983
|
+
```sh
|
|
984
|
+
vite build --mode client && vite build
|
|
985
|
+
```
|
|
986
|
+
|
|
987
|
+
Deploy with the following commands after the build. Ensure you have [Wrangler](https://developers.cloudflare.com/workers/wrangler/) installed:
|
|
988
|
+
|
|
989
|
+
```sh
|
|
990
|
+
wrangler deploy
|
|
991
|
+
```
|
|
992
|
+
|
|
993
|
+
### On-Premises or Other Platforms
|
|
994
|
+
|
|
995
|
+
You can build the HonoX app for on-premises environments or various other platforms. See the [`@hono/vite-build`] README for a full list of supported platforms. For example, you can make it for the Bun:
|
|
996
|
+
|
|
997
|
+
```ts
|
|
998
|
+
// vite.config.ts
|
|
999
|
+
import build from '@hono/vite-build/bun' // Change to Bun
|
|
1000
|
+
import adapter from '@hono/vite-dev-server/bun' // Change to Bun
|
|
1001
|
+
import tailwindcss from '@tailwindcss/vite'
|
|
981
1002
|
import honox from 'honox/vite'
|
|
982
|
-
import
|
|
1003
|
+
import { defineConfig } from 'vite'
|
|
983
1004
|
|
|
984
1005
|
export default defineConfig({
|
|
985
|
-
plugins: [
|
|
1006
|
+
plugins: [
|
|
1007
|
+
honox({
|
|
1008
|
+
devServer: { adapter },
|
|
1009
|
+
client: { input: ['./app/style.css'] }
|
|
1010
|
+
}),
|
|
1011
|
+
tailwindcss(),
|
|
1012
|
+
build()
|
|
1013
|
+
]
|
|
986
1014
|
})
|
|
987
1015
|
```
|
|
988
1016
|
|
|
1017
|
+
Build command (including a client):
|
|
1018
|
+
|
|
1019
|
+
```sh
|
|
1020
|
+
vite build --mode client && vite build
|
|
1021
|
+
```
|
|
1022
|
+
|
|
1023
|
+
Run the server with Bun:
|
|
1024
|
+
|
|
1025
|
+
```sh
|
|
1026
|
+
cd ./dist && bun index.js
|
|
1027
|
+
```
|
|
1028
|
+
|
|
1029
|
+
**Note**: When running on-premises, make sure to change the working directory to the output directory (e.g., `cd ./dist`). Otherwise, JavaScript, CSS, and static assets may not be resolved correctly.
|
|
1030
|
+
|
|
989
1031
|
## Examples
|
|
990
1032
|
|
|
991
1033
|
- https://github.com/yusukebe/honox-examples
|
package/dist/server/server.js
CHANGED
|
@@ -17,7 +17,7 @@ const createApp = (options) => {
|
|
|
17
17
|
const getRootPath = (dir) => filePathToPath(dir.replace(rootRegExp, ""));
|
|
18
18
|
const app = options.app ?? new Hono();
|
|
19
19
|
const trailingSlash = options.trailingSlash ?? false;
|
|
20
|
-
const
|
|
20
|
+
const appliedMiddlewaresByDirectory = /* @__PURE__ */ new Map();
|
|
21
21
|
app.use(async function ShareContext(c, next) {
|
|
22
22
|
await contextStorage.run(c, () => next());
|
|
23
23
|
});
|
|
@@ -85,24 +85,41 @@ const createApp = (options) => {
|
|
|
85
85
|
const findMiddleware = (directory) => Object.keys(MIDDLEWARE_FILE).find(
|
|
86
86
|
(x) => new RegExp(escapeDir(directory) + "/_middleware.tsx?").test(x)
|
|
87
87
|
);
|
|
88
|
+
const isMiddlewareAppliedToAncestor = (middlewarePath, currentDir) => {
|
|
89
|
+
const dirParts = currentDir.split("/");
|
|
90
|
+
const ancestorDirs = [];
|
|
91
|
+
for (let i = dirParts.length - 1; i > 0; i--) {
|
|
92
|
+
ancestorDirs.push(dirParts.slice(0, i).join("/"));
|
|
93
|
+
}
|
|
94
|
+
return ancestorDirs.some(
|
|
95
|
+
(ancestorDir) => appliedMiddlewaresByDirectory.get(ancestorDir)?.has(middlewarePath)
|
|
96
|
+
);
|
|
97
|
+
};
|
|
88
98
|
let middlewareFile = findMiddleware(dir);
|
|
89
99
|
if (!middlewareFile) {
|
|
90
100
|
const dirParts = dir.split("/");
|
|
91
101
|
for (let i = dirParts.length - 1; i >= 0; i--) {
|
|
92
102
|
const parentDir = dirParts.slice(0, i).join("/");
|
|
93
|
-
|
|
94
|
-
|
|
103
|
+
if (!parentDir.includes(root)) {
|
|
104
|
+
break;
|
|
105
|
+
}
|
|
106
|
+
const parentMiddleware = findMiddleware(parentDir);
|
|
107
|
+
if (!parentMiddleware) continue;
|
|
108
|
+
if (isMiddlewareAppliedToAncestor(parentMiddleware, dir)) continue;
|
|
109
|
+
middlewareFile = parentMiddleware;
|
|
110
|
+
break;
|
|
95
111
|
}
|
|
96
112
|
}
|
|
97
113
|
if (middlewareFile) {
|
|
98
114
|
const middleware = MIDDLEWARE_FILE[middlewareFile];
|
|
99
115
|
const middlewareDir = middlewareFile.replace("/_middleware.tsx", "").replace("/_middleware.ts", "");
|
|
100
|
-
const shouldApply = middlewareDir === dir ||
|
|
116
|
+
const shouldApply = middlewareDir === dir || dir.startsWith(middlewareDir + "/");
|
|
101
117
|
if (middleware.default && shouldApply) {
|
|
102
|
-
if (!appliedMiddleware.has(middlewareFile)) {
|
|
103
|
-
appliedMiddleware.add(middlewareFile);
|
|
104
|
-
}
|
|
105
118
|
subApp.use(...middleware.default);
|
|
119
|
+
if (!appliedMiddlewaresByDirectory.has(dir)) {
|
|
120
|
+
appliedMiddlewaresByDirectory.set(dir, /* @__PURE__ */ new Set());
|
|
121
|
+
}
|
|
122
|
+
appliedMiddlewaresByDirectory.get(dir)?.add(middlewareFile);
|
|
106
123
|
}
|
|
107
124
|
}
|
|
108
125
|
for (const [filename, route] of Object.entries(content)) {
|
|
@@ -151,7 +168,7 @@ const createApp = (options) => {
|
|
|
151
168
|
}
|
|
152
169
|
let rootPath = getRootPath(dir);
|
|
153
170
|
if (trailingSlash) {
|
|
154
|
-
rootPath =
|
|
171
|
+
rootPath = rootPath.endsWith("/") ? rootPath : rootPath + "/";
|
|
155
172
|
}
|
|
156
173
|
app.route(rootPath, subApp);
|
|
157
174
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
const filePathToPath = (filePath) => {
|
|
2
2
|
filePath = filePath.replace(/\.tsx?$/g, "").replace(/\.mdx?$/g, "").replace(/^\/?index$/, "/").replace(/\/index$/, "").replace(/\[\.{3}.+\]/, "*").replace(/\((.+?)\)/g, "").replace(/\[(.+?)\]/g, ":$1").replace(/\/\/+/g, "/");
|
|
3
|
-
return
|
|
3
|
+
return filePath.startsWith("/") ? filePath : "/" + filePath;
|
|
4
4
|
};
|
|
5
5
|
const groupByDirectory = (files) => {
|
|
6
6
|
const organizedFiles = {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "honox",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.45",
|
|
4
4
|
"main": "dist/index.js",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"scripts": {
|
|
@@ -113,7 +113,7 @@
|
|
|
113
113
|
"@babel/parser": "7.25.6",
|
|
114
114
|
"@babel/traverse": "7.25.6",
|
|
115
115
|
"@babel/types": "7.25.6",
|
|
116
|
-
"@hono/vite-dev-server": "0.
|
|
116
|
+
"@hono/vite-dev-server": "^0.20.1",
|
|
117
117
|
"jsonc-parser": "3.3.1",
|
|
118
118
|
"precinct": "12.1.2"
|
|
119
119
|
},
|
|
@@ -144,6 +144,7 @@
|
|
|
144
144
|
"vite-tsconfig-paths": "^5.1.4",
|
|
145
145
|
"vitest": "^3.0.3"
|
|
146
146
|
},
|
|
147
|
+
"packageManager": "bun@1.2.20",
|
|
147
148
|
"engines": {
|
|
148
149
|
"node": ">=18.14.1"
|
|
149
150
|
},
|