react-router-hono-server 2.2.0 → 2.3.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 +30 -8
- package/dist/adapters/node.js +2 -2
- package/dist/dev.js +17 -2
- package/package.json +1 -3
package/README.md
CHANGED
|
@@ -645,17 +645,39 @@ Cloudflare requires a different approach to WebSockets, based on Durable Objects
|
|
|
645
645
|
>
|
|
646
646
|
> Work in progress on Cloudflare team: https://github.com/flarelabs-net/vite-plugin-cloudflare
|
|
647
647
|
|
|
648
|
-
|
|
648
|
+
## Pre-rendering
|
|
649
|
+
You should be able to use pre-rendering with this package.
|
|
650
|
+
|
|
651
|
+
> [!TIP]
|
|
652
|
+
> Check this [example](./examples/node/with-pre-render/) to see how to use it.
|
|
653
|
+
|
|
654
|
+
> [!IMPORTANT]
|
|
655
|
+
> You need to add the `serverBuildFile` option to your `react-router.config.ts` file.
|
|
656
|
+
>
|
|
657
|
+
> The file path is fixed to `assets/server-build.js`.
|
|
658
|
+
|
|
659
|
+
Add the prerender option to your `react-router.config.ts`
|
|
660
|
+
|
|
661
|
+
```ts
|
|
662
|
+
import type { Config } from "@react-router/dev/config";
|
|
663
|
+
|
|
664
|
+
export default {
|
|
665
|
+
serverBuildFile: "assets/server-build.js", // 🚨 Dont forget this
|
|
666
|
+
prerender: ["/"],
|
|
667
|
+
} satisfies Config;
|
|
668
|
+
```
|
|
669
|
+
|
|
670
|
+
## Migrate from v1
|
|
649
671
|
_You should not expect any breaking changes._
|
|
650
672
|
|
|
651
|
-
|
|
673
|
+
### Install the latest version
|
|
652
674
|
|
|
653
675
|
```bash
|
|
654
676
|
npm install react-router-hono-server@latest
|
|
655
677
|
```
|
|
656
678
|
|
|
657
|
-
|
|
658
|
-
|
|
679
|
+
### Create the server file
|
|
680
|
+
#### Option 1 - You previously had all your server code in `app/entry.server.tsx`
|
|
659
681
|
```bash
|
|
660
682
|
touch app/server.ts
|
|
661
683
|
```
|
|
@@ -664,7 +686,7 @@ or
|
|
|
664
686
|
npx react-router-hono-server reveal file
|
|
665
687
|
```
|
|
666
688
|
|
|
667
|
-
|
|
689
|
+
#### Option 2 - You previously had your server code in a `server` folder
|
|
668
690
|
```bash
|
|
669
691
|
mkdir app/server
|
|
670
692
|
touch app/server/index.ts
|
|
@@ -674,7 +696,7 @@ or
|
|
|
674
696
|
npx react-router-hono-server reveal folder
|
|
675
697
|
```
|
|
676
698
|
|
|
677
|
-
|
|
699
|
+
### Move your server code
|
|
678
700
|
Move your previous server code to the new file you created in the previous step.
|
|
679
701
|
|
|
680
702
|
> [!NOTE]
|
|
@@ -693,7 +715,7 @@ We now use the Vite virtual import `virtual:react-router/server-build` to load t
|
|
|
693
715
|
> export default await createHonoServer({/* other options */});
|
|
694
716
|
> ```
|
|
695
717
|
|
|
696
|
-
|
|
718
|
+
### Update your `vite.config.ts`
|
|
697
719
|
|
|
698
720
|
> [!IMPORTANT]
|
|
699
721
|
> `devServer` is now `reactRouterHonoServer`.
|
|
@@ -710,7 +732,7 @@ If you used this hook for Sentry, check this [example](./examples/node/with-sent
|
|
|
710
732
|
|
|
711
733
|
If you used a custom `buildDirectory` option, check this [example](./examples/node/custom-build/react-router.config.ts) to see how to migrate.
|
|
712
734
|
|
|
713
|
-
|
|
735
|
+
### Update your package.json scripts
|
|
714
736
|
```json
|
|
715
737
|
"scripts": {
|
|
716
738
|
"build": "react-router build",
|
package/dist/adapters/node.js
CHANGED
|
@@ -17,10 +17,10 @@ import { createRequestHandler } from "react-router";
|
|
|
17
17
|
async function createHonoServer(options) {
|
|
18
18
|
const mergedOptions = {
|
|
19
19
|
...options,
|
|
20
|
-
listeningListener: (info) => {
|
|
20
|
+
listeningListener: options?.listeningListener || ((info) => {
|
|
21
21
|
console.log(`\u{1F680} Server started on port ${info.port}`);
|
|
22
22
|
console.log(`\u{1F30D} http://127.0.0.1:${info.port}`);
|
|
23
|
-
},
|
|
23
|
+
}),
|
|
24
24
|
port: options?.port || Number(process.env.PORT) || 3e3,
|
|
25
25
|
defaultLogger: options?.defaultLogger ?? true
|
|
26
26
|
};
|
package/dist/dev.js
CHANGED
|
@@ -56,12 +56,25 @@ Please add it to your plugins: import { cloudflareDevProxy } from "@react-router
|
|
|
56
56
|
if (!pluginConfig.isSsrBuild) {
|
|
57
57
|
return baseConfig;
|
|
58
58
|
}
|
|
59
|
+
let reactRouterBuildFile = pluginConfig.serverBuildFile;
|
|
60
|
+
if (reactRouterBuildFile === "index.js") {
|
|
61
|
+
reactRouterBuildFile = "assets/server-build.js";
|
|
62
|
+
}
|
|
59
63
|
return {
|
|
60
64
|
...baseConfig,
|
|
61
65
|
build: {
|
|
62
66
|
target: "esnext",
|
|
63
67
|
rollupOptions: {
|
|
64
|
-
input: pluginConfig.serverEntryPoint
|
|
68
|
+
input: pluginConfig.serverEntryPoint,
|
|
69
|
+
output: {
|
|
70
|
+
entryFileNames: "index.js",
|
|
71
|
+
chunkFileNames: (chunk) => {
|
|
72
|
+
if (chunk.name === "server-build") {
|
|
73
|
+
return reactRouterBuildFile;
|
|
74
|
+
}
|
|
75
|
+
return "assets/[name]-[hash].js";
|
|
76
|
+
}
|
|
77
|
+
}
|
|
65
78
|
}
|
|
66
79
|
}
|
|
67
80
|
};
|
|
@@ -115,6 +128,7 @@ function resolvePluginConfig(config, options) {
|
|
|
115
128
|
const isSsrBuild = reactRouterConfig.isSsrBuild;
|
|
116
129
|
const assetsDir = config.build?.assetsDir || "assets";
|
|
117
130
|
const serverEntryPoint = options.serverEntryPoint || findDefaultServerEntry(appDirectory);
|
|
131
|
+
const serverBuildFile = reactRouterConfig.reactRouterConfig.serverBuildFile;
|
|
118
132
|
return {
|
|
119
133
|
rootDirectory,
|
|
120
134
|
buildDirectory,
|
|
@@ -122,7 +136,8 @@ function resolvePluginConfig(config, options) {
|
|
|
122
136
|
isSsrBuild,
|
|
123
137
|
assetsDir,
|
|
124
138
|
serverEntryPoint,
|
|
125
|
-
dev: options.dev
|
|
139
|
+
dev: options.dev,
|
|
140
|
+
serverBuildFile
|
|
126
141
|
};
|
|
127
142
|
}
|
|
128
143
|
var warned = false;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-router-hono-server",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.3.0",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"description": "The Vite plugin you need to create a Hono server for your React Router app in less than 10 seconds.",
|
|
6
6
|
"exports": {
|
|
@@ -45,8 +45,6 @@
|
|
|
45
45
|
"test:cov": "vitest run --coverage",
|
|
46
46
|
"build": "tsup",
|
|
47
47
|
"build:watch": "npm run build -- --watch",
|
|
48
|
-
"example:dev": "npm run dev -w react-router-example",
|
|
49
|
-
"dev": "npm-run-all -s build -p example:dev build:watch",
|
|
50
48
|
"prepublishOnly": "npm run build",
|
|
51
49
|
"check": "biome check .",
|
|
52
50
|
"check:fix": "biome check --fix .",
|