@react-router/dev 0.0.0-experimental-df0f1dfda → 0.0.0-experimental-fde52e515
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/CHANGELOG.md +20 -0
- package/bin.js +2 -2
- package/dist/cli/index.js +302 -141
- package/dist/config.js +1 -1
- package/dist/routes.js +1 -1
- package/dist/vite/cloudflare.js +1 -1
- package/dist/vite.js +459 -218
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,25 @@
|
|
|
1
1
|
# `@react-router/dev`
|
|
2
2
|
|
|
3
|
+
## 7.1.5
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- Updated dependencies:
|
|
8
|
+
- `react-router@7.1.5`
|
|
9
|
+
- `@react-router/node@7.1.5`
|
|
10
|
+
- `@react-router/serve@7.1.5`
|
|
11
|
+
|
|
12
|
+
## 7.1.4
|
|
13
|
+
|
|
14
|
+
### Patch Changes
|
|
15
|
+
|
|
16
|
+
- Properly resolve Windows file paths to scan for Vite's dependency optimization when using the `unstable_optimizeDeps` future flag. ([#12637](https://github.com/remix-run/react-router/pull/12637))
|
|
17
|
+
- Fix prerendering when using a custom server - previously we ended up trying to import the users custom server when we actually want to import the virtual server build module ([#12759](https://github.com/remix-run/react-router/pull/12759))
|
|
18
|
+
- Updated dependencies:
|
|
19
|
+
- `react-router@7.1.4`
|
|
20
|
+
- `@react-router/node@7.1.4`
|
|
21
|
+
- `@react-router/serve@7.1.4`
|
|
22
|
+
|
|
3
23
|
## 7.1.3
|
|
4
24
|
|
|
5
25
|
### Patch Changes
|
package/bin.js
CHANGED
|
@@ -5,8 +5,8 @@ let arg = require("arg");
|
|
|
5
5
|
// default `NODE_ENV` so React loads the proper version in it's CJS entry script.
|
|
6
6
|
// We have to do this before importing `run.ts` since that is what imports
|
|
7
7
|
// `react` (indirectly via `react-router`)
|
|
8
|
-
let args = arg({}, { argv: process.argv.slice(2),
|
|
9
|
-
if (args._[0] === "dev") {
|
|
8
|
+
let args = arg({}, { argv: process.argv.slice(2), permissive: true });
|
|
9
|
+
if (args._.length === 0 || args._[0] === "dev") {
|
|
10
10
|
process.env.NODE_ENV = process.env.NODE_ENV ?? "development";
|
|
11
11
|
} else {
|
|
12
12
|
process.env.NODE_ENV = process.env.NODE_ENV ?? "production";
|
package/dist/cli/index.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
#!/usr/bin/env node
|
|
2
2
|
/**
|
|
3
|
-
* @react-router/dev v0.0.0-experimental-
|
|
3
|
+
* @react-router/dev v0.0.0-experimental-fde52e515
|
|
4
4
|
*
|
|
5
5
|
* Copyright (c) Remix Software Inc.
|
|
6
6
|
*
|
|
@@ -924,7 +924,28 @@ var init_cache = __esm({
|
|
|
924
924
|
});
|
|
925
925
|
|
|
926
926
|
// vite/route-chunks.ts
|
|
927
|
-
|
|
927
|
+
function getRouteChunkModuleId(filePath, chunkName) {
|
|
928
|
+
return `${filePath}${routeChunkQueryStrings[chunkName]}`;
|
|
929
|
+
}
|
|
930
|
+
function isRouteChunkModuleId(id) {
|
|
931
|
+
return Object.values(routeChunkQueryStrings).some(
|
|
932
|
+
(queryString) => id.endsWith(queryString)
|
|
933
|
+
);
|
|
934
|
+
}
|
|
935
|
+
function isRouteChunkName(name) {
|
|
936
|
+
return name === mainChunkName || routeChunkExportNames.includes(name);
|
|
937
|
+
}
|
|
938
|
+
function getRouteChunkNameFromModuleId(id) {
|
|
939
|
+
if (!isRouteChunkModuleId(id)) {
|
|
940
|
+
return null;
|
|
941
|
+
}
|
|
942
|
+
let chunkName = id.split(routeChunkQueryStringPrefix)[1].split("&")[0];
|
|
943
|
+
if (!isRouteChunkName(chunkName)) {
|
|
944
|
+
return null;
|
|
945
|
+
}
|
|
946
|
+
return chunkName;
|
|
947
|
+
}
|
|
948
|
+
var routeChunkExportNames, mainChunkName, routeChunkNames, routeChunkQueryStringPrefix, routeChunkQueryStrings;
|
|
928
949
|
var init_route_chunks = __esm({
|
|
929
950
|
"vite/route-chunks.ts"() {
|
|
930
951
|
"use strict";
|
|
@@ -936,6 +957,7 @@ var init_route_chunks = __esm({
|
|
|
936
957
|
"clientLoader",
|
|
937
958
|
"HydrateFallback"
|
|
938
959
|
];
|
|
960
|
+
mainChunkName = "main";
|
|
939
961
|
routeChunkNames = ["main", ...routeChunkExportNames];
|
|
940
962
|
routeChunkQueryStringPrefix = "?route-chunk=";
|
|
941
963
|
routeChunkQueryStrings = {
|
|
@@ -983,7 +1005,235 @@ async function resolveViteConfig({
|
|
|
983
1005
|
async function extractPluginContext(viteConfig) {
|
|
984
1006
|
return viteConfig["__reactRouterPluginContext"];
|
|
985
1007
|
}
|
|
986
|
-
|
|
1008
|
+
function getAddressableRoutes(routes2) {
|
|
1009
|
+
let nonAddressableIds = /* @__PURE__ */ new Set();
|
|
1010
|
+
for (let id in routes2) {
|
|
1011
|
+
let route = routes2[id];
|
|
1012
|
+
if (route.index) {
|
|
1013
|
+
invariant(
|
|
1014
|
+
route.parentId,
|
|
1015
|
+
`Expected index route "${route.id}" to have "parentId" set`
|
|
1016
|
+
);
|
|
1017
|
+
nonAddressableIds.add(route.parentId);
|
|
1018
|
+
}
|
|
1019
|
+
if (typeof route.path !== "string" && !route.index) {
|
|
1020
|
+
nonAddressableIds.add(id);
|
|
1021
|
+
}
|
|
1022
|
+
}
|
|
1023
|
+
return Object.values(routes2).filter(
|
|
1024
|
+
(route) => !nonAddressableIds.has(route.id)
|
|
1025
|
+
);
|
|
1026
|
+
}
|
|
1027
|
+
function getRouteBranch(routes2, routeId) {
|
|
1028
|
+
let branch = [];
|
|
1029
|
+
let currentRouteId = routeId;
|
|
1030
|
+
while (currentRouteId) {
|
|
1031
|
+
let route = routes2[currentRouteId];
|
|
1032
|
+
invariant(route, `Missing route for ${currentRouteId}`);
|
|
1033
|
+
branch.push(route);
|
|
1034
|
+
currentRouteId = route.parentId;
|
|
1035
|
+
}
|
|
1036
|
+
return branch.reverse();
|
|
1037
|
+
}
|
|
1038
|
+
function hasServerBundles(buildManifest) {
|
|
1039
|
+
return Object.keys(buildManifest.serverBundles ?? {}).length > 0;
|
|
1040
|
+
}
|
|
1041
|
+
function getRoutesByServerBundleId(buildManifest) {
|
|
1042
|
+
if (!buildManifest.routeIdToServerBundleId) {
|
|
1043
|
+
return {};
|
|
1044
|
+
}
|
|
1045
|
+
let routesByServerBundleId = {};
|
|
1046
|
+
for (let [routeId, serverBundleId] of Object.entries(
|
|
1047
|
+
buildManifest.routeIdToServerBundleId
|
|
1048
|
+
)) {
|
|
1049
|
+
routesByServerBundleId[serverBundleId] ??= {};
|
|
1050
|
+
let branch = getRouteBranch(buildManifest.routes, routeId);
|
|
1051
|
+
for (let route of branch) {
|
|
1052
|
+
routesByServerBundleId[serverBundleId][route.id] = route;
|
|
1053
|
+
}
|
|
1054
|
+
}
|
|
1055
|
+
return routesByServerBundleId;
|
|
1056
|
+
}
|
|
1057
|
+
async function getBuildManifest(ctx) {
|
|
1058
|
+
let { routes: routes2, serverBundles, appDirectory } = ctx.reactRouterConfig;
|
|
1059
|
+
if (!serverBundles) {
|
|
1060
|
+
return { routes: routes2 };
|
|
1061
|
+
}
|
|
1062
|
+
let { normalizePath } = await import("vite");
|
|
1063
|
+
let serverBuildDirectory = getServerBuildDirectory(ctx);
|
|
1064
|
+
let resolvedAppDirectory = path7.resolve(ctx.rootDirectory, appDirectory);
|
|
1065
|
+
let rootRelativeRoutes = Object.fromEntries(
|
|
1066
|
+
Object.entries(routes2).map(([id, route]) => {
|
|
1067
|
+
let filePath = path7.join(resolvedAppDirectory, route.file);
|
|
1068
|
+
let rootRelativeFilePath = normalizePath(
|
|
1069
|
+
path7.relative(ctx.rootDirectory, filePath)
|
|
1070
|
+
);
|
|
1071
|
+
return [id, { ...route, file: rootRelativeFilePath }];
|
|
1072
|
+
})
|
|
1073
|
+
);
|
|
1074
|
+
let buildManifest = {
|
|
1075
|
+
serverBundles: {},
|
|
1076
|
+
routeIdToServerBundleId: {},
|
|
1077
|
+
routes: rootRelativeRoutes
|
|
1078
|
+
};
|
|
1079
|
+
await Promise.all(
|
|
1080
|
+
getAddressableRoutes(routes2).map(async (route) => {
|
|
1081
|
+
let branch = getRouteBranch(routes2, route.id);
|
|
1082
|
+
let serverBundleId = await serverBundles({
|
|
1083
|
+
branch: branch.map(
|
|
1084
|
+
(route2) => configRouteToBranchRoute({
|
|
1085
|
+
...route2,
|
|
1086
|
+
// Ensure absolute paths are passed to the serverBundles function
|
|
1087
|
+
file: path7.join(resolvedAppDirectory, route2.file)
|
|
1088
|
+
})
|
|
1089
|
+
)
|
|
1090
|
+
});
|
|
1091
|
+
if (typeof serverBundleId !== "string") {
|
|
1092
|
+
throw new Error(`The "serverBundles" function must return a string`);
|
|
1093
|
+
}
|
|
1094
|
+
if (!/^[a-zA-Z0-9-_]+$/.test(serverBundleId)) {
|
|
1095
|
+
throw new Error(
|
|
1096
|
+
`The "serverBundles" function must only return strings containing alphanumeric characters, hyphens and underscores.`
|
|
1097
|
+
);
|
|
1098
|
+
}
|
|
1099
|
+
buildManifest.routeIdToServerBundleId[route.id] = serverBundleId;
|
|
1100
|
+
buildManifest.serverBundles[serverBundleId] ??= {
|
|
1101
|
+
id: serverBundleId,
|
|
1102
|
+
file: normalizePath(
|
|
1103
|
+
path7.join(
|
|
1104
|
+
path7.relative(
|
|
1105
|
+
ctx.rootDirectory,
|
|
1106
|
+
path7.join(serverBuildDirectory, serverBundleId)
|
|
1107
|
+
),
|
|
1108
|
+
ctx.reactRouterConfig.serverBuildFile
|
|
1109
|
+
)
|
|
1110
|
+
)
|
|
1111
|
+
};
|
|
1112
|
+
})
|
|
1113
|
+
);
|
|
1114
|
+
return buildManifest;
|
|
1115
|
+
}
|
|
1116
|
+
function mergeBuildOptions(base, overrides) {
|
|
1117
|
+
let vite2 = getVite();
|
|
1118
|
+
return vite2.mergeConfig({ build: base }, { build: overrides }).build;
|
|
1119
|
+
}
|
|
1120
|
+
async function getEnvironmentOptionsResolvers(ctx, buildManifest) {
|
|
1121
|
+
let { serverBuildFile, serverModuleFormat } = ctx.reactRouterConfig;
|
|
1122
|
+
function getBaseBuildOptions({
|
|
1123
|
+
viteUserConfig
|
|
1124
|
+
}) {
|
|
1125
|
+
return {
|
|
1126
|
+
cssMinify: viteUserConfig.build?.cssMinify ?? true,
|
|
1127
|
+
manifest: true,
|
|
1128
|
+
// The manifest is enabled for all builds to detect SSR-only assets
|
|
1129
|
+
rollupOptions: {
|
|
1130
|
+
preserveEntrySignatures: "exports-only",
|
|
1131
|
+
// Silence Rollup "use client" warnings
|
|
1132
|
+
// Adapted from https://github.com/vitejs/vite-plugin-react/pull/144
|
|
1133
|
+
onwarn(warning, defaultHandler) {
|
|
1134
|
+
if (warning.code === "MODULE_LEVEL_DIRECTIVE" && warning.message.includes("use client")) {
|
|
1135
|
+
return;
|
|
1136
|
+
}
|
|
1137
|
+
let userHandler = viteUserConfig.build?.rollupOptions?.onwarn;
|
|
1138
|
+
if (userHandler) {
|
|
1139
|
+
userHandler(warning, defaultHandler);
|
|
1140
|
+
} else {
|
|
1141
|
+
defaultHandler(warning);
|
|
1142
|
+
}
|
|
1143
|
+
}
|
|
1144
|
+
}
|
|
1145
|
+
};
|
|
1146
|
+
}
|
|
1147
|
+
function getBaseServerBuildOptions({
|
|
1148
|
+
viteUserConfig
|
|
1149
|
+
}) {
|
|
1150
|
+
return mergeBuildOptions(getBaseBuildOptions({ viteUserConfig }), {
|
|
1151
|
+
// We move SSR-only assets to client assets. Note that the
|
|
1152
|
+
// SSR build can also emit code-split JS files (e.g. by
|
|
1153
|
+
// dynamic import) under the same assets directory
|
|
1154
|
+
// regardless of "ssrEmitAssets" option, so we also need to
|
|
1155
|
+
// keep these JS files have to be kept as-is.
|
|
1156
|
+
ssrEmitAssets: true,
|
|
1157
|
+
copyPublicDir: false,
|
|
1158
|
+
// Assets in the public directory are only used by the client
|
|
1159
|
+
rollupOptions: {
|
|
1160
|
+
output: {
|
|
1161
|
+
entryFileNames: serverBuildFile,
|
|
1162
|
+
format: serverModuleFormat
|
|
1163
|
+
}
|
|
1164
|
+
}
|
|
1165
|
+
});
|
|
1166
|
+
}
|
|
1167
|
+
let environmentOptionsResolvers = {
|
|
1168
|
+
client: ({ viteUserConfig }) => ({
|
|
1169
|
+
build: mergeBuildOptions(getBaseBuildOptions({ viteUserConfig }), {
|
|
1170
|
+
rollupOptions: {
|
|
1171
|
+
input: [
|
|
1172
|
+
ctx.entryClientFilePath,
|
|
1173
|
+
...Object.values(ctx.reactRouterConfig.routes).flatMap((route) => {
|
|
1174
|
+
let routeFilePath = path7.resolve(
|
|
1175
|
+
ctx.reactRouterConfig.appDirectory,
|
|
1176
|
+
route.file
|
|
1177
|
+
);
|
|
1178
|
+
let isRootRoute = route.file === ctx.reactRouterConfig.routes.root.file;
|
|
1179
|
+
let code = fse.readFileSync(routeFilePath, "utf-8");
|
|
1180
|
+
return [
|
|
1181
|
+
`${routeFilePath}${BUILD_CLIENT_ROUTE_QUERY_STRING}`,
|
|
1182
|
+
...ctx.reactRouterConfig.future.unstable_splitRouteModules && !isRootRoute ? routeChunkExportNames.map(
|
|
1183
|
+
(exportName) => code.includes(exportName) ? getRouteChunkModuleId(routeFilePath, exportName) : null
|
|
1184
|
+
) : []
|
|
1185
|
+
].filter(isNonNullable);
|
|
1186
|
+
})
|
|
1187
|
+
],
|
|
1188
|
+
output: {
|
|
1189
|
+
entryFileNames({ moduleIds }) {
|
|
1190
|
+
let routeChunkModuleId = moduleIds.find(isRouteChunkModuleId);
|
|
1191
|
+
let routeChunkName = routeChunkModuleId ? getRouteChunkNameFromModuleId(routeChunkModuleId) : null;
|
|
1192
|
+
let routeChunkSuffix = routeChunkName ? `-${(0, import_kebabCase.default)(routeChunkName)}` : "";
|
|
1193
|
+
return `assets/[name]${routeChunkSuffix}-[hash].js`;
|
|
1194
|
+
}
|
|
1195
|
+
}
|
|
1196
|
+
},
|
|
1197
|
+
outDir: getClientBuildDirectory(ctx.reactRouterConfig)
|
|
1198
|
+
})
|
|
1199
|
+
})
|
|
1200
|
+
};
|
|
1201
|
+
if (hasServerBundles(buildManifest)) {
|
|
1202
|
+
for (let [serverBundleId, routes2] of Object.entries(
|
|
1203
|
+
getRoutesByServerBundleId(buildManifest)
|
|
1204
|
+
)) {
|
|
1205
|
+
environmentOptionsResolvers[`ssr-bundle-${serverBundleId}`] = ({
|
|
1206
|
+
viteUserConfig
|
|
1207
|
+
}) => ({
|
|
1208
|
+
build: mergeBuildOptions(
|
|
1209
|
+
getBaseServerBuildOptions({ viteUserConfig }),
|
|
1210
|
+
{
|
|
1211
|
+
outDir: getServerBuildDirectory(ctx, { serverBundleId }),
|
|
1212
|
+
rollupOptions: {
|
|
1213
|
+
input: `${virtual.serverBuild.id}?route-ids=${Object.keys(
|
|
1214
|
+
routes2
|
|
1215
|
+
).join(",")}`
|
|
1216
|
+
}
|
|
1217
|
+
}
|
|
1218
|
+
)
|
|
1219
|
+
});
|
|
1220
|
+
}
|
|
1221
|
+
} else {
|
|
1222
|
+
environmentOptionsResolvers.ssr = ({ viteUserConfig }) => ({
|
|
1223
|
+
build: mergeBuildOptions(getBaseServerBuildOptions({ viteUserConfig }), {
|
|
1224
|
+
outDir: getServerBuildDirectory(ctx),
|
|
1225
|
+
rollupOptions: {
|
|
1226
|
+
input: viteUserConfig.build?.rollupOptions?.input ?? virtual.serverBuild.id
|
|
1227
|
+
}
|
|
1228
|
+
})
|
|
1229
|
+
});
|
|
1230
|
+
}
|
|
1231
|
+
return environmentOptionsResolvers;
|
|
1232
|
+
}
|
|
1233
|
+
function isNonNullable(x) {
|
|
1234
|
+
return x != null;
|
|
1235
|
+
}
|
|
1236
|
+
var import_node_crypto, path7, url, fse, babel2, import_react_router2, import_es_module_lexer, import_pick3, import_jsesc, import_picocolors4, import_kebabCase, BUILD_CLIENT_ROUTE_QUERY_STRING, virtualHmrRuntime, virtualInjectHmrRuntime, virtual, getServerBuildDirectory, getClientBuildDirectory, defaultEntriesDir, defaultEntries, REACT_REFRESH_HEADER;
|
|
987
1237
|
var init_plugin = __esm({
|
|
988
1238
|
"vite/plugin.ts"() {
|
|
989
1239
|
"use strict";
|
|
@@ -994,8 +1244,10 @@ var init_plugin = __esm({
|
|
|
994
1244
|
babel2 = __toESM(require("@babel/core"));
|
|
995
1245
|
import_react_router2 = require("react-router");
|
|
996
1246
|
import_es_module_lexer = require("es-module-lexer");
|
|
1247
|
+
import_pick3 = __toESM(require("lodash/pick"));
|
|
997
1248
|
import_jsesc = __toESM(require("jsesc"));
|
|
998
1249
|
import_picocolors4 = __toESM(require("picocolors"));
|
|
1250
|
+
import_kebabCase = __toESM(require("lodash/kebabCase"));
|
|
999
1251
|
init_typegen();
|
|
1000
1252
|
init_invariant();
|
|
1001
1253
|
init_babel();
|
|
@@ -1009,6 +1261,7 @@ var init_plugin = __esm({
|
|
|
1009
1261
|
init_vite();
|
|
1010
1262
|
init_config();
|
|
1011
1263
|
init_with_props();
|
|
1264
|
+
BUILD_CLIENT_ROUTE_QUERY_STRING = "?__react-router-build-client-route";
|
|
1012
1265
|
virtualHmrRuntime = create("hmr-runtime");
|
|
1013
1266
|
virtualInjectHmrRuntime = create("inject-hmr-runtime");
|
|
1014
1267
|
virtual = {
|
|
@@ -1016,11 +1269,12 @@ var init_plugin = __esm({
|
|
|
1016
1269
|
serverManifest: create("server-manifest"),
|
|
1017
1270
|
browserManifest: create("browser-manifest")
|
|
1018
1271
|
};
|
|
1019
|
-
getServerBuildDirectory = (ctx) => path7.join(
|
|
1272
|
+
getServerBuildDirectory = (ctx, { serverBundleId } = {}) => path7.join(
|
|
1020
1273
|
ctx.reactRouterConfig.buildDirectory,
|
|
1021
1274
|
"server",
|
|
1022
|
-
...
|
|
1275
|
+
...serverBundleId ? [serverBundleId] : []
|
|
1023
1276
|
);
|
|
1277
|
+
getClientBuildDirectory = (reactRouterConfig) => path7.join(reactRouterConfig.buildDirectory, "client");
|
|
1024
1278
|
defaultEntriesDir = path7.resolve(
|
|
1025
1279
|
path7.dirname(require.resolve("@react-router/dev/package.json")),
|
|
1026
1280
|
"dist",
|
|
@@ -1058,121 +1312,6 @@ var build_exports = {};
|
|
|
1058
1312
|
__export(build_exports, {
|
|
1059
1313
|
build: () => build
|
|
1060
1314
|
});
|
|
1061
|
-
function getAddressableRoutes(routes2) {
|
|
1062
|
-
let nonAddressableIds = /* @__PURE__ */ new Set();
|
|
1063
|
-
for (let id in routes2) {
|
|
1064
|
-
let route = routes2[id];
|
|
1065
|
-
if (route.index) {
|
|
1066
|
-
invariant(
|
|
1067
|
-
route.parentId,
|
|
1068
|
-
`Expected index route "${route.id}" to have "parentId" set`
|
|
1069
|
-
);
|
|
1070
|
-
nonAddressableIds.add(route.parentId);
|
|
1071
|
-
}
|
|
1072
|
-
if (typeof route.path !== "string" && !route.index) {
|
|
1073
|
-
nonAddressableIds.add(id);
|
|
1074
|
-
}
|
|
1075
|
-
}
|
|
1076
|
-
return Object.values(routes2).filter(
|
|
1077
|
-
(route) => !nonAddressableIds.has(route.id)
|
|
1078
|
-
);
|
|
1079
|
-
}
|
|
1080
|
-
function getRouteBranch(routes2, routeId) {
|
|
1081
|
-
let branch = [];
|
|
1082
|
-
let currentRouteId = routeId;
|
|
1083
|
-
while (currentRouteId) {
|
|
1084
|
-
let route = routes2[currentRouteId];
|
|
1085
|
-
invariant(route, `Missing route for ${currentRouteId}`);
|
|
1086
|
-
branch.push(route);
|
|
1087
|
-
currentRouteId = route.parentId;
|
|
1088
|
-
}
|
|
1089
|
-
return branch.reverse();
|
|
1090
|
-
}
|
|
1091
|
-
async function getServerBuilds(ctx) {
|
|
1092
|
-
let { rootDirectory } = ctx;
|
|
1093
|
-
const { routes: routes2, serverBuildFile, serverBundles, appDirectory } = ctx.reactRouterConfig;
|
|
1094
|
-
let serverBuildDirectory = getServerBuildDirectory(ctx);
|
|
1095
|
-
if (!serverBundles) {
|
|
1096
|
-
return {
|
|
1097
|
-
serverBuilds: [{ ssr: true }],
|
|
1098
|
-
buildManifest: { routes: routes2 }
|
|
1099
|
-
};
|
|
1100
|
-
}
|
|
1101
|
-
let { normalizePath } = await import("vite");
|
|
1102
|
-
let resolvedAppDirectory = import_node_path2.default.resolve(rootDirectory, appDirectory);
|
|
1103
|
-
let rootRelativeRoutes = Object.fromEntries(
|
|
1104
|
-
Object.entries(routes2).map(([id, route]) => {
|
|
1105
|
-
let filePath = import_node_path2.default.join(resolvedAppDirectory, route.file);
|
|
1106
|
-
let rootRelativeFilePath = normalizePath(
|
|
1107
|
-
import_node_path2.default.relative(rootDirectory, filePath)
|
|
1108
|
-
);
|
|
1109
|
-
return [id, { ...route, file: rootRelativeFilePath }];
|
|
1110
|
-
})
|
|
1111
|
-
);
|
|
1112
|
-
let buildManifest = {
|
|
1113
|
-
serverBundles: {},
|
|
1114
|
-
routeIdToServerBundleId: {},
|
|
1115
|
-
routes: rootRelativeRoutes
|
|
1116
|
-
};
|
|
1117
|
-
let serverBundleBuildConfigById = /* @__PURE__ */ new Map();
|
|
1118
|
-
await Promise.all(
|
|
1119
|
-
getAddressableRoutes(routes2).map(async (route) => {
|
|
1120
|
-
let branch = getRouteBranch(routes2, route.id);
|
|
1121
|
-
let serverBundleId = await serverBundles({
|
|
1122
|
-
branch: branch.map(
|
|
1123
|
-
(route2) => configRouteToBranchRoute({
|
|
1124
|
-
...route2,
|
|
1125
|
-
// Ensure absolute paths are passed to the serverBundles function
|
|
1126
|
-
file: import_node_path2.default.join(resolvedAppDirectory, route2.file)
|
|
1127
|
-
})
|
|
1128
|
-
)
|
|
1129
|
-
});
|
|
1130
|
-
if (typeof serverBundleId !== "string") {
|
|
1131
|
-
throw new Error(`The "serverBundles" function must return a string`);
|
|
1132
|
-
}
|
|
1133
|
-
if (!/^[a-zA-Z0-9-_]+$/.test(serverBundleId)) {
|
|
1134
|
-
throw new Error(
|
|
1135
|
-
`The "serverBundles" function must only return strings containing alphanumeric characters, hyphens and underscores.`
|
|
1136
|
-
);
|
|
1137
|
-
}
|
|
1138
|
-
buildManifest.routeIdToServerBundleId[route.id] = serverBundleId;
|
|
1139
|
-
let relativeServerBundleDirectory = import_node_path2.default.relative(
|
|
1140
|
-
rootDirectory,
|
|
1141
|
-
import_node_path2.default.join(serverBuildDirectory, serverBundleId)
|
|
1142
|
-
);
|
|
1143
|
-
let serverBuildConfig = serverBundleBuildConfigById.get(serverBundleId);
|
|
1144
|
-
if (!serverBuildConfig) {
|
|
1145
|
-
buildManifest.serverBundles[serverBundleId] = {
|
|
1146
|
-
id: serverBundleId,
|
|
1147
|
-
file: normalizePath(
|
|
1148
|
-
import_node_path2.default.join(relativeServerBundleDirectory, serverBuildFile)
|
|
1149
|
-
)
|
|
1150
|
-
};
|
|
1151
|
-
serverBuildConfig = {
|
|
1152
|
-
routes: {},
|
|
1153
|
-
serverBundleId
|
|
1154
|
-
};
|
|
1155
|
-
serverBundleBuildConfigById.set(serverBundleId, serverBuildConfig);
|
|
1156
|
-
}
|
|
1157
|
-
for (let route2 of branch) {
|
|
1158
|
-
serverBuildConfig.routes[route2.id] = route2;
|
|
1159
|
-
}
|
|
1160
|
-
})
|
|
1161
|
-
);
|
|
1162
|
-
let serverBuilds = Array.from(serverBundleBuildConfigById.values()).map(
|
|
1163
|
-
(serverBundleBuildConfig) => {
|
|
1164
|
-
let serverBuild = {
|
|
1165
|
-
ssr: true,
|
|
1166
|
-
serverBundleBuildConfig
|
|
1167
|
-
};
|
|
1168
|
-
return serverBuild;
|
|
1169
|
-
}
|
|
1170
|
-
);
|
|
1171
|
-
return {
|
|
1172
|
-
serverBuilds,
|
|
1173
|
-
buildManifest
|
|
1174
|
-
};
|
|
1175
|
-
}
|
|
1176
1315
|
async function cleanBuildDirectory(viteConfig, ctx) {
|
|
1177
1316
|
let buildDirectory = ctx.reactRouterConfig.buildDirectory;
|
|
1178
1317
|
let isWithinRoot = () => {
|
|
@@ -1183,17 +1322,22 @@ async function cleanBuildDirectory(viteConfig, ctx) {
|
|
|
1183
1322
|
await import_fs_extra.default.remove(buildDirectory);
|
|
1184
1323
|
}
|
|
1185
1324
|
}
|
|
1186
|
-
function getViteManifestPaths(
|
|
1187
|
-
|
|
1188
|
-
|
|
1189
|
-
|
|
1190
|
-
|
|
1191
|
-
|
|
1192
|
-
|
|
1193
|
-
|
|
1194
|
-
|
|
1195
|
-
|
|
1196
|
-
|
|
1325
|
+
function getViteManifestPaths(environmentOptionsResolvers) {
|
|
1326
|
+
return Object.entries(environmentOptionsResolvers).map(
|
|
1327
|
+
([environmentName, resolveOptions]) => {
|
|
1328
|
+
invariant(
|
|
1329
|
+
resolveOptions,
|
|
1330
|
+
`Expected build environment options resolver for ${environmentName}`
|
|
1331
|
+
);
|
|
1332
|
+
let options = resolveOptions({
|
|
1333
|
+
viteCommand: "build",
|
|
1334
|
+
viteUserConfig: {}
|
|
1335
|
+
});
|
|
1336
|
+
let outDir = options.build.outDir;
|
|
1337
|
+
invariant(outDir, `Expected build.outDir for ${environmentName}`);
|
|
1338
|
+
return import_node_path2.default.join(outDir, ".vite/manifest.json");
|
|
1339
|
+
}
|
|
1340
|
+
);
|
|
1197
1341
|
}
|
|
1198
1342
|
async function build(root, {
|
|
1199
1343
|
assetsInlineLimit,
|
|
@@ -1218,10 +1362,17 @@ async function build(root, {
|
|
|
1218
1362
|
}
|
|
1219
1363
|
let { reactRouterConfig } = ctx;
|
|
1220
1364
|
let vite2 = getVite();
|
|
1221
|
-
async function viteBuild({
|
|
1222
|
-
ssr
|
|
1223
|
-
|
|
1224
|
-
|
|
1365
|
+
async function viteBuild(environmentOptionsResolvers2, environmentName) {
|
|
1366
|
+
let ssr = environmentName !== "client";
|
|
1367
|
+
let resolveOptions = environmentOptionsResolvers2[environmentName];
|
|
1368
|
+
invariant(
|
|
1369
|
+
resolveOptions,
|
|
1370
|
+
`Missing environment options resolver for ${environmentName}`
|
|
1371
|
+
);
|
|
1372
|
+
let environmentBuildContext = {
|
|
1373
|
+
name: environmentName,
|
|
1374
|
+
resolveOptions
|
|
1375
|
+
};
|
|
1225
1376
|
await vite2.build({
|
|
1226
1377
|
root,
|
|
1227
1378
|
mode,
|
|
@@ -1236,14 +1387,25 @@ async function build(root, {
|
|
|
1236
1387
|
optimizeDeps: { force },
|
|
1237
1388
|
clearScreen,
|
|
1238
1389
|
logLevel,
|
|
1239
|
-
...
|
|
1390
|
+
...{ __reactRouterEnvironmentBuildContext: environmentBuildContext }
|
|
1240
1391
|
});
|
|
1241
1392
|
}
|
|
1242
1393
|
await cleanBuildDirectory(viteConfig, ctx);
|
|
1243
|
-
|
|
1244
|
-
let
|
|
1245
|
-
|
|
1246
|
-
|
|
1394
|
+
let buildManifest = await getBuildManifest(ctx);
|
|
1395
|
+
let environmentOptionsResolvers = await getEnvironmentOptionsResolvers(
|
|
1396
|
+
ctx,
|
|
1397
|
+
buildManifest
|
|
1398
|
+
);
|
|
1399
|
+
await viteBuild(environmentOptionsResolvers, "client");
|
|
1400
|
+
let serverEnvironmentNames = Object.keys(
|
|
1401
|
+
environmentOptionsResolvers
|
|
1402
|
+
).filter((environmentName) => environmentName !== "client");
|
|
1403
|
+
await Promise.all(
|
|
1404
|
+
serverEnvironmentNames.map(
|
|
1405
|
+
(environmentName) => viteBuild(environmentOptionsResolvers, environmentName)
|
|
1406
|
+
)
|
|
1407
|
+
);
|
|
1408
|
+
let viteManifestPaths = getViteManifestPaths(environmentOptionsResolvers);
|
|
1247
1409
|
await Promise.all(
|
|
1248
1410
|
viteManifestPaths.map(async (viteManifestPath) => {
|
|
1249
1411
|
let manifestExists = await import_fs_extra.default.pathExists(viteManifestPath);
|
|
@@ -1272,7 +1434,6 @@ var init_build = __esm({
|
|
|
1272
1434
|
import_fs_extra = __toESM(require("fs-extra"));
|
|
1273
1435
|
import_picocolors5 = __toESM(require("picocolors"));
|
|
1274
1436
|
init_plugin();
|
|
1275
|
-
init_config();
|
|
1276
1437
|
init_invariant();
|
|
1277
1438
|
init_vite();
|
|
1278
1439
|
}
|
package/dist/config.js
CHANGED
package/dist/routes.js
CHANGED
package/dist/vite/cloudflare.js
CHANGED