@netlify/vite-plugin-react-router 3.0.0 → 3.1.0-next.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 +6 -25
- package/dist/index.d.mts +1 -1
- package/dist/index.d.ts +1 -1
- package/dist/index.js +55 -5
- package/dist/index.mjs +46 -6
- package/package.json +4 -3
package/README.md
CHANGED
|
@@ -10,33 +10,28 @@ To deploy a React Router 7+ site to Netlify, install this package:
|
|
|
10
10
|
npm install @netlify/vite-plugin-react-router
|
|
11
11
|
```
|
|
12
12
|
|
|
13
|
-
|
|
14
|
-
[Netlify Vite plugin](https://www.npmjs.com/package/@netlify/vite-plugin), which provides full Netlify platform
|
|
15
|
-
emulation directly in your local dev server:
|
|
16
|
-
|
|
17
|
-
```sh
|
|
18
|
-
npm install --save-dev @netlify/vite-plugin
|
|
19
|
-
```
|
|
20
|
-
|
|
21
|
-
and include the Netlify plugin in your `vite.config.ts`:
|
|
13
|
+
Then include the Netlify plugin in your `vite.config.ts`:
|
|
22
14
|
|
|
23
15
|
```typescript
|
|
24
16
|
import { reactRouter } from '@react-router/dev/vite'
|
|
25
17
|
import { defineConfig } from 'vite'
|
|
26
18
|
import tsconfigPaths from 'vite-tsconfig-paths'
|
|
27
19
|
import netlifyReactRouter from '@netlify/vite-plugin-react-router' // <- add this
|
|
28
|
-
import netlify from '@netlify/vite-plugin' // <- add this (optional)
|
|
29
20
|
|
|
30
21
|
export default defineConfig({
|
|
31
22
|
plugins: [
|
|
32
23
|
reactRouter(),
|
|
33
24
|
tsconfigPaths(),
|
|
34
25
|
netlifyReactRouter(), // <- add this
|
|
35
|
-
netlify(), // <- add this (optional)
|
|
36
26
|
],
|
|
37
27
|
})
|
|
38
28
|
```
|
|
39
29
|
|
|
30
|
+
> [!NOTE]
|
|
31
|
+
>
|
|
32
|
+
> This plugin automatically includes [`@netlify/vite-plugin`](https://npmx.dev/@netlify/vite-plugin), which provides
|
|
33
|
+
> full Netlify platform emulation directly in your local dev server.
|
|
34
|
+
|
|
40
35
|
Your app is ready to [deploy to Netlify](https://docs.netlify.com/deploy/create-deploys/).
|
|
41
36
|
|
|
42
37
|
### Deploying to Edge Functions
|
|
@@ -53,7 +48,6 @@ export default defineConfig({
|
|
|
53
48
|
reactRouter(),
|
|
54
49
|
tsconfigPaths(),
|
|
55
50
|
netlifyReactRouter({ edge: true }), // <- deploy to Edge Functions
|
|
56
|
-
netlify(),
|
|
57
51
|
],
|
|
58
52
|
})
|
|
59
53
|
```
|
|
@@ -88,7 +82,6 @@ export default defineConfig({
|
|
|
88
82
|
edge: true,
|
|
89
83
|
excludedPaths: ['/ping', '/api/*', '/webhooks/*'],
|
|
90
84
|
}),
|
|
91
|
-
netlify(),
|
|
92
85
|
],
|
|
93
86
|
})
|
|
94
87
|
```
|
|
@@ -159,12 +152,6 @@ export default function Example() {
|
|
|
159
152
|
}
|
|
160
153
|
```
|
|
161
154
|
|
|
162
|
-
> [!IMPORTANT]
|
|
163
|
-
>
|
|
164
|
-
> Note that in local development, `netlifyRouterContext` requires Netlify platform emulation, which is provided
|
|
165
|
-
> seamlessly by [`@netlify/vite-plugin`](https://www.npmjs.com/package/@netlify/vite-plugin) (or Netlify CLI - up to
|
|
166
|
-
> you).
|
|
167
|
-
|
|
168
155
|
### Middleware context
|
|
169
156
|
|
|
170
157
|
React Router introduced a stable middleware feature in 7.9.0.
|
|
@@ -193,9 +180,3 @@ export default function Home() {
|
|
|
193
180
|
return <h1>Hello world</h1>
|
|
194
181
|
}
|
|
195
182
|
```
|
|
196
|
-
|
|
197
|
-
> [!IMPORTANT]
|
|
198
|
-
>
|
|
199
|
-
> Note that in local development, `netlifyRouterContext` requires Netlify platform emulation, which is provided
|
|
200
|
-
> seamlessly by [`@netlify/vite-plugin`](https://www.npmjs.com/package/@netlify/vite-plugin) (or Netlify CLI - up to
|
|
201
|
-
> you).
|
package/dist/index.d.mts
CHANGED
|
@@ -21,6 +21,6 @@ interface NetlifyPluginOptions {
|
|
|
21
21
|
*/
|
|
22
22
|
excludedPaths?: string[];
|
|
23
23
|
}
|
|
24
|
-
declare function netlifyPlugin(options?: NetlifyPluginOptions): Plugin;
|
|
24
|
+
declare function netlifyPlugin(options?: NetlifyPluginOptions): Plugin[];
|
|
25
25
|
|
|
26
26
|
export { netlifyPlugin as default };
|
package/dist/index.d.ts
CHANGED
|
@@ -60,6 +60,6 @@ interface NetlifyPluginOptions {
|
|
|
60
60
|
*/
|
|
61
61
|
excludedPaths?: string[];
|
|
62
62
|
}
|
|
63
|
-
declare function netlifyPlugin(options?: NetlifyPluginOptions): Plugin;
|
|
63
|
+
declare function netlifyPlugin(options?: NetlifyPluginOptions): Plugin[];
|
|
64
64
|
|
|
65
65
|
export { type GetLoadContextFunction, type RequestHandler, createRequestHandler, netlifyPlugin as default, netlifyRouterContext };
|
package/dist/index.js
CHANGED
|
@@ -1,7 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __create = Object.create;
|
|
2
3
|
var __defProp = Object.defineProperty;
|
|
3
4
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
4
5
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
6
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
5
7
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
6
8
|
var __export = (target, all) => {
|
|
7
9
|
for (var name2 in all)
|
|
@@ -15,6 +17,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
15
17
|
}
|
|
16
18
|
return to;
|
|
17
19
|
};
|
|
20
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
21
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
22
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
23
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
24
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
25
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
26
|
+
mod
|
|
27
|
+
));
|
|
18
28
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
19
29
|
|
|
20
30
|
// src/index.ts
|
|
@@ -109,11 +119,12 @@ function createRequestHandler({
|
|
|
109
119
|
var import_promises = require("fs/promises");
|
|
110
120
|
var import_node_path2 = require("path");
|
|
111
121
|
var import_posix = require("path/posix");
|
|
122
|
+
var import_vite_plugin = __toESM(require("@netlify/vite-plugin"));
|
|
112
123
|
var import_tinyglobby = require("tinyglobby");
|
|
113
124
|
|
|
114
125
|
// package.json
|
|
115
126
|
var name = "@netlify/vite-plugin-react-router";
|
|
116
|
-
var version = "3.0.0";
|
|
127
|
+
var version = "3.1.0-next.0";
|
|
117
128
|
|
|
118
129
|
// src/lib/rollup.ts
|
|
119
130
|
var import_node_path = require("path");
|
|
@@ -149,6 +160,26 @@ var FUNCTION_HANDLER_MODULE_ID = "virtual:netlify-server";
|
|
|
149
160
|
var RESOLVED_FUNCTION_HANDLER_MODULE_ID = `\0${FUNCTION_HANDLER_MODULE_ID}`;
|
|
150
161
|
var SERVER_ENTRY_MODULE_ID = "virtual:netlify-server-entry";
|
|
151
162
|
var toPosixPath = (path) => path.split(import_node_path2.sep).join(import_posix.sep);
|
|
163
|
+
var ALLOWED_USER_EDGE_FUNCTION_HANDLER_FILENAMES = [
|
|
164
|
+
"server.ts",
|
|
165
|
+
"server.mts",
|
|
166
|
+
"server.cts",
|
|
167
|
+
"server.mjs",
|
|
168
|
+
"server.cjs",
|
|
169
|
+
"server.js"
|
|
170
|
+
];
|
|
171
|
+
var findUserEdgeFunctionHandlerFile = async (root) => {
|
|
172
|
+
for (const filename of ALLOWED_USER_EDGE_FUNCTION_HANDLER_FILENAMES) {
|
|
173
|
+
try {
|
|
174
|
+
await (0, import_promises.access)((0, import_node_path2.join)(root, filename));
|
|
175
|
+
return filename;
|
|
176
|
+
} catch {
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
throw new Error(
|
|
180
|
+
"Your Hydrogen site must include a `server.ts` (or js/mjs/cjs/mts/cts) file at the root to deploy to Netlify. See https://github.com/netlify/hydrogen-template."
|
|
181
|
+
);
|
|
182
|
+
};
|
|
152
183
|
var FUNCTION_HANDLER = (
|
|
153
184
|
/* js */
|
|
154
185
|
`
|
|
@@ -207,7 +238,8 @@ function netlifyPlugin(options = {}) {
|
|
|
207
238
|
let resolvedConfig;
|
|
208
239
|
let isProductionSsrBuild = false;
|
|
209
240
|
let currentCommand;
|
|
210
|
-
|
|
241
|
+
let isHydrogenSite = false;
|
|
242
|
+
const reactRouterPlugin = {
|
|
211
243
|
name: "vite-plugin-netlify-react-router",
|
|
212
244
|
config(_config, { command, isSsrBuild }) {
|
|
213
245
|
currentCommand = command;
|
|
@@ -222,7 +254,9 @@ function netlifyPlugin(options = {}) {
|
|
|
222
254
|
rollupOptions: {
|
|
223
255
|
input: mergedInput,
|
|
224
256
|
output: {
|
|
225
|
-
|
|
257
|
+
// NOTE: must use function syntax here to work around Shopify CLI reading
|
|
258
|
+
// the config value literally (i.e. trying to stat `[name].js` as a filename).
|
|
259
|
+
entryFileNames: () => "[name].js"
|
|
226
260
|
}
|
|
227
261
|
}
|
|
228
262
|
},
|
|
@@ -243,6 +277,11 @@ function netlifyPlugin(options = {}) {
|
|
|
243
277
|
}
|
|
244
278
|
},
|
|
245
279
|
async resolveId(source, importer, options2) {
|
|
280
|
+
if (isHydrogenSite && edge) {
|
|
281
|
+
if (source === FUNCTION_HANDLER_MODULE_ID || source === SERVER_ENTRY_MODULE_ID) {
|
|
282
|
+
return;
|
|
283
|
+
}
|
|
284
|
+
}
|
|
246
285
|
if (source === FUNCTION_HANDLER_MODULE_ID) {
|
|
247
286
|
return RESOLVED_FUNCTION_HANDLER_MODULE_ID;
|
|
248
287
|
}
|
|
@@ -263,8 +302,18 @@ function netlifyPlugin(options = {}) {
|
|
|
263
302
|
return edge ? EDGE_FUNCTION_HANDLER : FUNCTION_HANDLER;
|
|
264
303
|
}
|
|
265
304
|
},
|
|
266
|
-
|
|
267
|
-
|
|
305
|
+
configResolved: {
|
|
306
|
+
order: "pre",
|
|
307
|
+
async handler(config) {
|
|
308
|
+
resolvedConfig = config;
|
|
309
|
+
isHydrogenSite = config.plugins.some((plugin) => plugin.name === "hydrogen:main");
|
|
310
|
+
if (isHydrogenSite && edge && isProductionSsrBuild) {
|
|
311
|
+
const userServerFile = await findUserEdgeFunctionHandlerFile(config.root);
|
|
312
|
+
if (config.build?.rollupOptions?.input && typeof config.build.rollupOptions.input === "object" && !Array.isArray(config.build.rollupOptions.input)) {
|
|
313
|
+
config.build.rollupOptions.input[FUNCTION_HANDLER_CHUNK] = userServerFile;
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
}
|
|
268
317
|
},
|
|
269
318
|
// See https://rollupjs.org/plugin-development/#writebundle.
|
|
270
319
|
async writeBundle() {
|
|
@@ -300,6 +349,7 @@ function netlifyPlugin(options = {}) {
|
|
|
300
349
|
}
|
|
301
350
|
}
|
|
302
351
|
};
|
|
352
|
+
return [reactRouterPlugin, ...(0, import_vite_plugin.default)()];
|
|
303
353
|
}
|
|
304
354
|
// Annotate the CommonJS export names for ESM import in node:
|
|
305
355
|
0 && (module.exports = {
|
package/dist/index.mjs
CHANGED
|
@@ -5,14 +5,15 @@ import {
|
|
|
5
5
|
import "./chunk-J5PMA2AP.mjs";
|
|
6
6
|
|
|
7
7
|
// src/plugin.ts
|
|
8
|
-
import { mkdir, writeFile } from "node:fs/promises";
|
|
8
|
+
import { access, mkdir, writeFile } from "node:fs/promises";
|
|
9
9
|
import { dirname, join, relative, resolve, sep } from "node:path";
|
|
10
10
|
import { sep as posixSep } from "node:path/posix";
|
|
11
|
+
import netlifyVitePlugin from "@netlify/vite-plugin";
|
|
11
12
|
import { glob } from "tinyglobby";
|
|
12
13
|
|
|
13
14
|
// package.json
|
|
14
15
|
var name = "@netlify/vite-plugin-react-router";
|
|
15
|
-
var version = "3.0.0";
|
|
16
|
+
var version = "3.1.0-next.0";
|
|
16
17
|
|
|
17
18
|
// src/lib/rollup.ts
|
|
18
19
|
import { basename, extname } from "node:path";
|
|
@@ -48,6 +49,26 @@ var FUNCTION_HANDLER_MODULE_ID = "virtual:netlify-server";
|
|
|
48
49
|
var RESOLVED_FUNCTION_HANDLER_MODULE_ID = `\0${FUNCTION_HANDLER_MODULE_ID}`;
|
|
49
50
|
var SERVER_ENTRY_MODULE_ID = "virtual:netlify-server-entry";
|
|
50
51
|
var toPosixPath = (path) => path.split(sep).join(posixSep);
|
|
52
|
+
var ALLOWED_USER_EDGE_FUNCTION_HANDLER_FILENAMES = [
|
|
53
|
+
"server.ts",
|
|
54
|
+
"server.mts",
|
|
55
|
+
"server.cts",
|
|
56
|
+
"server.mjs",
|
|
57
|
+
"server.cjs",
|
|
58
|
+
"server.js"
|
|
59
|
+
];
|
|
60
|
+
var findUserEdgeFunctionHandlerFile = async (root) => {
|
|
61
|
+
for (const filename of ALLOWED_USER_EDGE_FUNCTION_HANDLER_FILENAMES) {
|
|
62
|
+
try {
|
|
63
|
+
await access(join(root, filename));
|
|
64
|
+
return filename;
|
|
65
|
+
} catch {
|
|
66
|
+
}
|
|
67
|
+
}
|
|
68
|
+
throw new Error(
|
|
69
|
+
"Your Hydrogen site must include a `server.ts` (or js/mjs/cjs/mts/cts) file at the root to deploy to Netlify. See https://github.com/netlify/hydrogen-template."
|
|
70
|
+
);
|
|
71
|
+
};
|
|
51
72
|
var FUNCTION_HANDLER = (
|
|
52
73
|
/* js */
|
|
53
74
|
`
|
|
@@ -106,7 +127,8 @@ function netlifyPlugin(options = {}) {
|
|
|
106
127
|
let resolvedConfig;
|
|
107
128
|
let isProductionSsrBuild = false;
|
|
108
129
|
let currentCommand;
|
|
109
|
-
|
|
130
|
+
let isHydrogenSite = false;
|
|
131
|
+
const reactRouterPlugin = {
|
|
110
132
|
name: "vite-plugin-netlify-react-router",
|
|
111
133
|
config(_config, { command, isSsrBuild }) {
|
|
112
134
|
currentCommand = command;
|
|
@@ -121,7 +143,9 @@ function netlifyPlugin(options = {}) {
|
|
|
121
143
|
rollupOptions: {
|
|
122
144
|
input: mergedInput,
|
|
123
145
|
output: {
|
|
124
|
-
|
|
146
|
+
// NOTE: must use function syntax here to work around Shopify CLI reading
|
|
147
|
+
// the config value literally (i.e. trying to stat `[name].js` as a filename).
|
|
148
|
+
entryFileNames: () => "[name].js"
|
|
125
149
|
}
|
|
126
150
|
}
|
|
127
151
|
},
|
|
@@ -142,6 +166,11 @@ function netlifyPlugin(options = {}) {
|
|
|
142
166
|
}
|
|
143
167
|
},
|
|
144
168
|
async resolveId(source, importer, options2) {
|
|
169
|
+
if (isHydrogenSite && edge) {
|
|
170
|
+
if (source === FUNCTION_HANDLER_MODULE_ID || source === SERVER_ENTRY_MODULE_ID) {
|
|
171
|
+
return;
|
|
172
|
+
}
|
|
173
|
+
}
|
|
145
174
|
if (source === FUNCTION_HANDLER_MODULE_ID) {
|
|
146
175
|
return RESOLVED_FUNCTION_HANDLER_MODULE_ID;
|
|
147
176
|
}
|
|
@@ -162,8 +191,18 @@ function netlifyPlugin(options = {}) {
|
|
|
162
191
|
return edge ? EDGE_FUNCTION_HANDLER : FUNCTION_HANDLER;
|
|
163
192
|
}
|
|
164
193
|
},
|
|
165
|
-
|
|
166
|
-
|
|
194
|
+
configResolved: {
|
|
195
|
+
order: "pre",
|
|
196
|
+
async handler(config) {
|
|
197
|
+
resolvedConfig = config;
|
|
198
|
+
isHydrogenSite = config.plugins.some((plugin) => plugin.name === "hydrogen:main");
|
|
199
|
+
if (isHydrogenSite && edge && isProductionSsrBuild) {
|
|
200
|
+
const userServerFile = await findUserEdgeFunctionHandlerFile(config.root);
|
|
201
|
+
if (config.build?.rollupOptions?.input && typeof config.build.rollupOptions.input === "object" && !Array.isArray(config.build.rollupOptions.input)) {
|
|
202
|
+
config.build.rollupOptions.input[FUNCTION_HANDLER_CHUNK] = userServerFile;
|
|
203
|
+
}
|
|
204
|
+
}
|
|
205
|
+
}
|
|
167
206
|
},
|
|
168
207
|
// See https://rollupjs.org/plugin-development/#writebundle.
|
|
169
208
|
async writeBundle() {
|
|
@@ -199,6 +238,7 @@ function netlifyPlugin(options = {}) {
|
|
|
199
238
|
}
|
|
200
239
|
}
|
|
201
240
|
};
|
|
241
|
+
return [reactRouterPlugin, ...netlifyVitePlugin()];
|
|
202
242
|
}
|
|
203
243
|
export {
|
|
204
244
|
createRequestHandler,
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@netlify/vite-plugin-react-router",
|
|
3
|
-
"version": "3.0.0",
|
|
3
|
+
"version": "3.1.0-next.0",
|
|
4
4
|
"description": "React Router 7+ Vite plugin for Netlify",
|
|
5
5
|
"type": "commonjs",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -52,8 +52,9 @@
|
|
|
52
52
|
},
|
|
53
53
|
"homepage": "https://github.com/netlify/remix-compute#readme",
|
|
54
54
|
"dependencies": {
|
|
55
|
-
"@netlify/edge-functions": "^3.0.
|
|
56
|
-
"@netlify/functions": "^5.1.
|
|
55
|
+
"@netlify/edge-functions": "^3.0.4",
|
|
56
|
+
"@netlify/functions": "^5.1.3",
|
|
57
|
+
"@netlify/vite-plugin": "^2.10.11",
|
|
57
58
|
"isbot": "^5.1.25",
|
|
58
59
|
"tinyglobby": "^0.2.10"
|
|
59
60
|
},
|