rsbuild-plugin-react-router 0.4.1 → 0.6.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 +72 -240
- package/dist/{451.js → 511.js} +461 -331
- package/dist/build-output-transforms.d.ts +32 -7
- package/dist/classic-mode.d.ts +56 -0
- package/dist/config-imports.d.ts +8 -2
- package/dist/constants.d.ts +3 -0
- package/dist/dev-background-resources.d.ts +3 -3
- package/dist/dev-generation.d.ts +2 -3
- package/dist/dev-hmr.d.ts +8 -2
- package/dist/dev-runtime-controller.d.ts +6 -1
- package/dist/dev-source-maps.d.ts +4 -0
- package/dist/effect-runtime.d.ts +17 -5
- package/dist/entry-paths.d.ts +16 -0
- package/dist/environment-output.d.ts +6 -0
- package/dist/export-utils.d.ts +2 -1
- package/dist/federation.d.ts +2 -0
- package/dist/index.cjs +3675 -2107
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3614 -2214
- package/dist/lazy-compilation-prewarm.d.ts +8 -5
- package/dist/manifest.d.ts +16 -4
- package/dist/mode-plan.d.ts +82 -0
- package/dist/modify-browser-manifest.d.ts +8 -4
- package/dist/performance.d.ts +4 -1
- package/dist/plugin-utils.d.ts +27 -1
- package/dist/prerender-build.d.ts +5 -5
- package/dist/prerender.d.ts +1 -5
- package/dist/react-router-config.d.ts +11 -3
- package/dist/route-artifacts.d.ts +4 -2
- package/dist/route-chunks.d.ts +2 -1
- package/dist/route-component-transform.d.ts +0 -2
- package/dist/route-export-pruning.d.ts +4 -1
- package/dist/route-imports.d.ts +18 -0
- package/dist/route-module-transform-loader.d.ts +14 -0
- package/dist/route-module-transform-loader.js +44 -0
- package/dist/route-module-transform-rules.d.ts +14 -0
- package/dist/route-transform-tasks.d.ts +6 -0
- package/dist/route-watch.d.ts +11 -6
- package/dist/rsc-dev-server.d.ts +26 -0
- package/dist/rsc-prerender.d.ts +54 -0
- package/dist/rsc-route-config.d.ts +6 -0
- package/dist/rsc-route-exports.d.ts +15 -0
- package/dist/rsc-route-transform-loader.cjs +43 -0
- package/dist/rsc-route-transform-loader.d.ts +30 -0
- package/dist/rsc-route-transform-loader.js +16 -0
- package/dist/rsc-route-transform-registration.d.ts +12 -0
- package/dist/rsc-route-transforms.d.ts +21 -0
- package/dist/rsc-support.d.ts +23 -0
- package/dist/rsc-virtual-modules.d.ts +19 -0
- package/dist/server-build-plan.d.ts +2 -1
- package/dist/server-build-resolution.d.ts +1 -2
- package/dist/server-utils.d.ts +4 -5
- package/dist/ssr-asset-relocation.d.ts +98 -0
- package/dist/templates/entry.rsc.client.d.ts +1 -0
- package/dist/templates/entry.rsc.client.js +61 -0
- package/dist/templates/entry.rsc.d.ts +9 -0
- package/dist/templates/entry.rsc.js +38 -0
- package/dist/templates/entry.rsc.ssr.d.ts +4 -0
- package/dist/templates/entry.rsc.ssr.js +24 -0
- package/dist/typegen.d.ts +4 -2
- package/dist/types.d.ts +34 -6
- package/package.json +76 -22
- package/src/build-output-transforms.ts +181 -43
- package/src/classic-mode.ts +253 -0
- package/src/config-imports.ts +153 -6
- package/src/constants.ts +6 -2
- package/src/dev-background-resources.ts +46 -100
- package/src/dev-generation.ts +52 -33
- package/src/dev-hmr.ts +112 -80
- package/src/dev-runtime-artifacts.ts +11 -12
- package/src/dev-runtime-controller.ts +75 -85
- package/src/dev-runtime-session.ts +14 -18
- package/src/dev-server.ts +2 -0
- package/src/dev-source-maps.ts +257 -0
- package/src/effect-runtime.ts +105 -57
- package/src/entry-paths.ts +80 -0
- package/src/environment-output.ts +55 -0
- package/src/export-utils.ts +15 -11
- package/src/federation.ts +38 -0
- package/src/index.ts +666 -519
- package/src/lazy-compilation-prewarm.ts +20 -4
- package/src/manifest.ts +157 -82
- package/src/mode-plan.ts +367 -0
- package/src/modify-browser-manifest.ts +130 -124
- package/src/performance.ts +11 -2
- package/src/plugin-utils.ts +103 -39
- package/src/prerender-build.ts +82 -104
- package/src/prerender.ts +23 -24
- package/src/react-router-config.ts +72 -26
- package/src/route-artifacts.ts +96 -66
- package/src/route-chunks.ts +167 -51
- package/src/route-component-transform.ts +14 -21
- package/src/route-export-pruning.ts +4 -3
- package/src/route-imports.ts +100 -0
- package/src/route-module-transform-loader.ts +149 -0
- package/src/route-module-transform-rules.ts +115 -0
- package/src/route-transform-tasks.ts +44 -29
- package/src/route-watch.ts +166 -188
- package/src/rsc-dev-server.ts +112 -0
- package/src/rsc-prerender.ts +362 -0
- package/src/rsc-route-config.ts +175 -0
- package/src/rsc-route-exports.ts +67 -0
- package/src/rsc-route-transform-loader.ts +65 -0
- package/src/rsc-route-transform-registration.ts +145 -0
- package/src/rsc-route-transforms.ts +995 -0
- package/src/rsc-runtime.d.ts +143 -0
- package/src/rsc-support.ts +116 -0
- package/src/rsc-virtual-modules.ts +113 -0
- package/src/server-build-plan.ts +14 -3
- package/src/server-build-resolution.ts +37 -47
- package/src/server-utils.ts +21 -35
- package/src/ssr-asset-relocation.ts +183 -0
- package/src/ssr-externals.ts +8 -26
- package/src/templates/entry.rsc.client.tsx +168 -0
- package/src/templates/entry.rsc.ssr.tsx +45 -0
- package/src/templates/entry.rsc.tsx +80 -0
- package/src/typegen.ts +40 -23
- package/src/types.ts +43 -6
- package/src/warnings/warn-on-client-source-maps.ts +6 -10
- package/dist/parallel-route-transform-protocol.d.ts +0 -25
- package/dist/parallel-route-transform-worker.d.ts +0 -1
- package/dist/parallel-route-transform-worker.js +0 -38
- package/dist/parallel-route-transforms.d.ts +0 -29
- package/src/parallel-route-transform-protocol.ts +0 -35
- package/src/parallel-route-transform-worker.ts +0 -82
- package/src/parallel-route-transforms.ts +0 -458
|
@@ -1,15 +1,17 @@
|
|
|
1
1
|
import * as Effect from 'effect/Effect';
|
|
2
|
+
import type * as Scope from 'effect/Scope';
|
|
2
3
|
import type { ReactRouterManifestForDev } from './manifest.js';
|
|
3
|
-
type
|
|
4
|
+
import { type PluginEffectRuntime } from './effect-runtime.js';
|
|
5
|
+
export type LazyCompilationPrewarmConfig = {
|
|
4
6
|
entry: boolean;
|
|
5
7
|
routeLimit: number;
|
|
6
8
|
delayMs: number;
|
|
7
9
|
};
|
|
8
|
-
type LazyCompilationPrewarmController = {
|
|
10
|
+
export type LazyCompilationPrewarmController = {
|
|
9
11
|
setServerOrigin(origin: string): void;
|
|
10
12
|
setManifest(manifest: ReactRouterManifestForDev | null): void;
|
|
11
13
|
schedule(): void;
|
|
12
|
-
cancelEffect(): Effect.Effect<void
|
|
14
|
+
cancelEffect(): Effect.Effect<void>;
|
|
13
15
|
};
|
|
14
16
|
export type RspackLazyCompilationTriggerClient = {
|
|
15
17
|
extractModuleKeys(source: string): string[];
|
|
@@ -18,8 +20,9 @@ export type RspackLazyCompilationTriggerClient = {
|
|
|
18
20
|
export declare const normalizeLazyCompilationPrewarmOptions: (options: boolean | undefined) => LazyCompilationPrewarmConfig | null;
|
|
19
21
|
export declare const collectLazyCompilationPrewarmAssets: (manifest: ReactRouterManifestForDev, config: LazyCompilationPrewarmConfig) => string[];
|
|
20
22
|
export declare const createRspackLazyCompilationTriggerClient: (triggerPrefix?: string) => RspackLazyCompilationTriggerClient;
|
|
21
|
-
export declare const createLazyCompilationPrewarmController: ({ config, onError, }: {
|
|
23
|
+
export declare const createLazyCompilationPrewarmController: ({ runtime, config, onError, }: {
|
|
24
|
+
runtime: PluginEffectRuntime;
|
|
22
25
|
config: LazyCompilationPrewarmConfig;
|
|
23
26
|
onError: (error: Error) => void;
|
|
24
27
|
}) => LazyCompilationPrewarmController;
|
|
25
|
-
export
|
|
28
|
+
export declare const acquireLazyCompilationPrewarm: (options: Parameters<typeof createLazyCompilationPrewarmController>[0]) => Effect.Effect<LazyCompilationPrewarmController, never, Scope.Scope>;
|
package/dist/manifest.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import type { Route, PluginOptions, RouteManifestItem } from './types.js';
|
|
2
2
|
import { type RouteChunkCache } from './route-chunks.js';
|
|
3
|
+
import { type RouteModuleAnalysis } from './export-utils.js';
|
|
3
4
|
/**
|
|
4
5
|
* Structural equivalent of `RouteConfigEntry` from `@react-router/dev/routes`,
|
|
5
6
|
* inlined so the public declaration files do not reference a devDependency
|
|
@@ -15,12 +16,20 @@ export interface RouteConfigEntry {
|
|
|
15
16
|
}
|
|
16
17
|
export declare function configRoutesToRouteManifest(appDirectory: string, routes: RouteConfigEntry[], rootId?: string): Record<string, Route>;
|
|
17
18
|
export declare function configRoutesToRouteManifestEntries(appDirectory: string, routes: RouteConfigEntry[], rootId?: string): Array<[string, Route]>;
|
|
18
|
-
type RouteChunkManifestOptions = {
|
|
19
|
+
export type RouteChunkManifestOptions = {
|
|
19
20
|
splitRouteModules?: boolean | 'enforce';
|
|
20
21
|
rootRouteFile?: string;
|
|
21
22
|
isBuild?: boolean;
|
|
22
23
|
cache?: RouteChunkCache;
|
|
23
24
|
};
|
|
25
|
+
export type RouteModuleAnalysisProvider = (routeFilePath: string, route: Route) => Promise<RouteModuleAnalysis | undefined>;
|
|
26
|
+
export type ReactRouterManifestOptions = RouteChunkManifestOptions & {
|
|
27
|
+
routeModuleAnalysis?: RouteModuleAnalysisProvider;
|
|
28
|
+
};
|
|
29
|
+
export declare const createReactRouterManifestOptions: ({ routeChunks, routeModuleAnalysis, }: {
|
|
30
|
+
routeChunks?: RouteChunkManifestOptions;
|
|
31
|
+
routeModuleAnalysis?: RouteModuleAnalysisProvider;
|
|
32
|
+
}) => ReactRouterManifestOptions | undefined;
|
|
24
33
|
export type ReactRouterManifestForDev = {
|
|
25
34
|
version: string;
|
|
26
35
|
url: string;
|
|
@@ -45,8 +54,11 @@ type ReactRouterManifestStatsChunk = {
|
|
|
45
54
|
type ReactRouterManifestStatsEntrypoint = {
|
|
46
55
|
getFiles?: () => Iterable<string>;
|
|
47
56
|
};
|
|
48
|
-
type ReactRouterManifestStatsLookup<T> = Iterable<[
|
|
49
|
-
|
|
57
|
+
type ReactRouterManifestStatsLookup<T> = Iterable<[
|
|
58
|
+
string,
|
|
59
|
+
T | null | undefined
|
|
60
|
+
]> & {
|
|
61
|
+
get?: (name: string) => T | null | undefined;
|
|
50
62
|
};
|
|
51
63
|
type ReactRouterManifestStatsCompilation = {
|
|
52
64
|
namedChunks: ReactRouterManifestStatsLookup<ReactRouterManifestStatsChunk>;
|
|
@@ -64,6 +76,6 @@ export declare const getReactRouterManifestPath: ({ version, isBuild, entryModul
|
|
|
64
76
|
entryModulePath?: string;
|
|
65
77
|
}) => string;
|
|
66
78
|
export declare const getReactRouterManifestChunkNames: (routes: Record<string, Route>, splitRouteModules?: boolean | "enforce") => Set<string>;
|
|
67
|
-
export declare function generateReactRouterManifestForDev(routes: Record<string, Route>,
|
|
79
|
+
export declare function generateReactRouterManifestForDev(routes: Record<string, Route>, _options: PluginOptions, clientStats: ReactRouterManifestStats | undefined, context: string, assetPrefix?: string, manifestOptions?: ReactRouterManifestOptions): Promise<ReactRouterManifestGenerationResult>;
|
|
68
80
|
export declare function getReactRouterManifestForDev(...args: Parameters<typeof generateReactRouterManifestForDev>): Promise<ReactRouterManifestForDev>;
|
|
69
81
|
export {};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import type { RsbuildConfig, RsbuildEntryDescription, RsbuildPluginAPI, Rspack } from '@rsbuild/core';
|
|
2
|
+
import type { RouteConfigEntry } from '@react-router/dev/routes';
|
|
3
|
+
import type { Config, ResolvedReactRouterConfig } from './react-router-config.js';
|
|
4
|
+
import type { RouteChunkCache, RouteChunkConfig } from './route-chunks.js';
|
|
5
|
+
import type { DevHmrPlanOptions } from './dev-hmr.js';
|
|
6
|
+
import type { Route } from './types.js';
|
|
7
|
+
import { type ClassicBuildArtifacts } from './classic-mode.js';
|
|
8
|
+
type CommonModePlan = {
|
|
9
|
+
routeChunkConfig: RouteChunkConfig;
|
|
10
|
+
manifestChunkNames: Set<string>;
|
|
11
|
+
webEntries: Record<string, string | RsbuildEntryDescription>;
|
|
12
|
+
nodeEntries: Record<string, string | RsbuildEntryDescription>;
|
|
13
|
+
createVirtualModules(publicPath: string, jsDistPath: string): Record<string, string>;
|
|
14
|
+
createResolveConfig(rootPath: string): Rspack.Configuration['resolve'];
|
|
15
|
+
server: RsbuildConfig['server'] | undefined;
|
|
16
|
+
webExternalsType: 'module' | undefined;
|
|
17
|
+
webOutput: NonNullable<Rspack.Configuration['output']>;
|
|
18
|
+
webOptimization: NonNullable<Rspack.Configuration['optimization']>;
|
|
19
|
+
nodeExternals: string[] | undefined;
|
|
20
|
+
nodeDependencies: {
|
|
21
|
+
dependencies?: string[];
|
|
22
|
+
};
|
|
23
|
+
};
|
|
24
|
+
export type ClassicModePlan = CommonModePlan & {
|
|
25
|
+
kind: 'classic';
|
|
26
|
+
artifacts: ClassicBuildArtifacts;
|
|
27
|
+
routeChunkOptions: {
|
|
28
|
+
splitRouteModules: Config['splitRouteModules'];
|
|
29
|
+
rootRouteFile: string;
|
|
30
|
+
isBuild: boolean;
|
|
31
|
+
cache: RouteChunkCache;
|
|
32
|
+
};
|
|
33
|
+
};
|
|
34
|
+
export type RscModePlan = CommonModePlan & {
|
|
35
|
+
kind: 'rsc';
|
|
36
|
+
prerenderPaths: string[];
|
|
37
|
+
};
|
|
38
|
+
export type ReactRouterModePlan = ClassicModePlan | RscModePlan;
|
|
39
|
+
type ModePlanContext = {
|
|
40
|
+
allowedActionOriginsForBuild: string[] | undefined;
|
|
41
|
+
api: RsbuildPluginAPI;
|
|
42
|
+
appDirectory: string;
|
|
43
|
+
basename: string;
|
|
44
|
+
customServer: boolean;
|
|
45
|
+
splitRouteModules: Config['splitRouteModules'];
|
|
46
|
+
isBuild: boolean;
|
|
47
|
+
isSpaMode: boolean;
|
|
48
|
+
prerenderConfig: Config['prerender'];
|
|
49
|
+
routeConfig: RouteConfigEntry[];
|
|
50
|
+
routeDiscovery: Config['routeDiscovery'];
|
|
51
|
+
routes: Record<string, Route>;
|
|
52
|
+
rootRouteFile: string;
|
|
53
|
+
ssr: boolean;
|
|
54
|
+
};
|
|
55
|
+
type CreateClassicModePlanOptions = ModePlanContext & {
|
|
56
|
+
assetsBuildDirectory: string;
|
|
57
|
+
devHmr?: DevHmrPlanOptions;
|
|
58
|
+
defaultEntryName: string;
|
|
59
|
+
entryServerPath: string;
|
|
60
|
+
finalEntryClientPath: string;
|
|
61
|
+
future: Config['future'];
|
|
62
|
+
hasServerApp: boolean;
|
|
63
|
+
reactRouterConfig: ResolvedReactRouterConfig;
|
|
64
|
+
routeChunkCache: RouteChunkCache;
|
|
65
|
+
serverAppPath: string;
|
|
66
|
+
shouldDependOnWebCompiler: boolean;
|
|
67
|
+
};
|
|
68
|
+
type CreateRscModePlanOptions = ModePlanContext & {
|
|
69
|
+
buildDirectory: string;
|
|
70
|
+
finalEntryRscClientPath: string;
|
|
71
|
+
finalEntryRscPath: string;
|
|
72
|
+
outputClientPath: string;
|
|
73
|
+
pluginName: string;
|
|
74
|
+
serverBuildFile: string | undefined;
|
|
75
|
+
};
|
|
76
|
+
type CreateReactRouterModePlanOptions = ({
|
|
77
|
+
isRscMode: true;
|
|
78
|
+
} & CreateRscModePlanOptions) | ({
|
|
79
|
+
isRscMode: false;
|
|
80
|
+
} & CreateClassicModePlanOptions);
|
|
81
|
+
export declare const createReactRouterModePlan: (options: CreateReactRouterModePlanOptions) => Promise<ReactRouterModePlan>;
|
|
82
|
+
export {};
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import type { Route, PluginOptions } from './types.js';
|
|
2
2
|
import type { RsbuildPluginAPI, Rspack } from '@rsbuild/core';
|
|
3
|
-
import { createReactRouterManifestStats,
|
|
3
|
+
import { createReactRouterManifestStats, type ReactRouterManifestForDev as ReactRouterManifest, type RouteChunkManifestOptions, type RouteManifestModuleExports, type RouteModuleAnalysisProvider } from './manifest.js';
|
|
4
4
|
type StatsAssetWithIntegrity = {
|
|
5
5
|
name?: string;
|
|
6
6
|
integrity?: unknown;
|
|
@@ -10,6 +10,9 @@ type StatsWithIntegrity = {
|
|
|
10
10
|
};
|
|
11
11
|
type CompilationAssetWithIntegrity = {
|
|
12
12
|
name: string;
|
|
13
|
+
source?: {
|
|
14
|
+
source(): string | Buffer;
|
|
15
|
+
};
|
|
13
16
|
info?: {
|
|
14
17
|
integrity?: unknown;
|
|
15
18
|
};
|
|
@@ -18,12 +21,13 @@ type CompilationWithIntegrityAssets = {
|
|
|
18
21
|
getAssets?: () => readonly CompilationAssetWithIntegrity[];
|
|
19
22
|
} | Pick<Rspack.Compilation, 'getAssets'>;
|
|
20
23
|
type ModifyBrowserManifestOptions = {
|
|
24
|
+
subResourceIntegrity?: boolean;
|
|
21
25
|
future?: {
|
|
22
26
|
unstable_subResourceIntegrity?: boolean;
|
|
23
27
|
};
|
|
24
|
-
subResourceIntegrity?: boolean;
|
|
25
28
|
manifestChunkNames?: ReadonlySet<string>;
|
|
26
|
-
|
|
29
|
+
routeModuleAnalysis?: RouteModuleAnalysisProvider;
|
|
30
|
+
onManifest?: (manifest: ReactRouterManifest, sri: Record<string, string> | true | undefined, moduleExportsByRouteId: RouteManifestModuleExports, context: {
|
|
27
31
|
compilation: Rspack.Compilation;
|
|
28
32
|
manifestStats: ReturnType<typeof createReactRouterManifestStats>;
|
|
29
33
|
}) => void;
|
|
@@ -31,5 +35,5 @@ type ModifyBrowserManifestOptions = {
|
|
|
31
35
|
type ProcessAssetsApi = Pick<RsbuildPluginAPI, 'processAssets'>;
|
|
32
36
|
type AssetPrefixInput = string | (() => string);
|
|
33
37
|
export declare const collectSubresourceIntegrity: (stats: StatsWithIntegrity | undefined, compilation: CompilationWithIntegrityAssets | undefined, assetPrefix?: string) => Record<string, string> | undefined;
|
|
34
|
-
export declare function registerModifyBrowserManifestAssets(api: ProcessAssetsApi, routes: Record<string, Route>, pluginOptions: PluginOptions, appDirectory: string, assetPrefix?: AssetPrefixInput, routeChunkOptions?:
|
|
38
|
+
export declare function registerModifyBrowserManifestAssets(api: ProcessAssetsApi, routes: Record<string, Route>, pluginOptions: PluginOptions, appDirectory: string, assetPrefix?: AssetPrefixInput, routeChunkOptions?: RouteChunkManifestOptions, options?: ModifyBrowserManifestOptions): void;
|
|
35
39
|
export {};
|
package/dist/performance.d.ts
CHANGED
|
@@ -12,12 +12,15 @@ export declare const roundMs: (value: number) => number;
|
|
|
12
12
|
export type ReactRouterPerformanceReport = {
|
|
13
13
|
environment: string;
|
|
14
14
|
compilerLifecycleMs?: number;
|
|
15
|
+
partial?: boolean;
|
|
16
|
+
workerId?: string;
|
|
15
17
|
operations: Record<string, OperationTiming>;
|
|
16
18
|
};
|
|
19
|
+
export declare const formatReactRouterPerformanceReport: (report: ReactRouterPerformanceReport) => string;
|
|
17
20
|
export type ReactRouterPerformanceProfiler = {
|
|
18
21
|
record<T>(environment: string | undefined, operation: string, resource: string, callback: () => Promise<T>): Promise<T>;
|
|
19
22
|
recordSync<T>(environment: string | undefined, operation: string, resource: string, callback: () => T): T;
|
|
20
|
-
flush(environment: string | undefined, details?: Pick<ReactRouterPerformanceReport, 'compilerLifecycleMs'>): void;
|
|
23
|
+
flush(environment: string | undefined, details?: Pick<ReactRouterPerformanceReport, 'compilerLifecycleMs' | 'partial' | 'workerId'>): void;
|
|
21
24
|
};
|
|
22
25
|
export declare const createReactRouterPerformanceProfiler: ({ enabled, log, }: {
|
|
23
26
|
enabled: boolean;
|
package/dist/plugin-utils.d.ts
CHANGED
|
@@ -1,6 +1,32 @@
|
|
|
1
|
+
export declare const resolveAppPackagePath: (specifier: string) => string | undefined;
|
|
2
|
+
export declare const parseVersionMajorMinor: (version: string | undefined) => {
|
|
3
|
+
major: number;
|
|
4
|
+
minor: number;
|
|
5
|
+
} | undefined;
|
|
6
|
+
export declare const getPackageVersion: (packageName: string, resolvePackagePath?: (specifier: string) => string | undefined) => string | undefined;
|
|
7
|
+
export declare const escapeHtml: (value: string) => string;
|
|
1
8
|
export declare function combineURLs(baseURL: string, relativeURL: string): string;
|
|
2
9
|
export declare function normalizeAssetPrefix(assetPrefix?: string): string;
|
|
3
|
-
|
|
10
|
+
/**
|
|
11
|
+
* Resolve the asset prefix Rsbuild applies to emitted asset URLs for the given
|
|
12
|
+
* mode. In development the effective prefix is `dev.assetPrefix` (which Rsbuild
|
|
13
|
+
* defaults from `server.base`, falling back to `output.assetPrefix`); in a
|
|
14
|
+
* production build it is `output.assetPrefix`. Both fields are already resolved
|
|
15
|
+
* on the normalized config, so this mirrors Rsbuild's own precedence rather than
|
|
16
|
+
* re-deriving it from `server.base`.
|
|
17
|
+
*
|
|
18
|
+
* `dev.assetPrefix` may be a boolean on the raw config (`false` disables it);
|
|
19
|
+
* boolean/`'auto'`/empty values normalize to the root prefix `'/'`.
|
|
20
|
+
*/
|
|
21
|
+
export declare function resolveEffectiveAssetPrefix(config: {
|
|
22
|
+
dev?: {
|
|
23
|
+
assetPrefix?: unknown;
|
|
24
|
+
};
|
|
25
|
+
output?: {
|
|
26
|
+
assetPrefix?: unknown;
|
|
27
|
+
};
|
|
28
|
+
isBuild: boolean;
|
|
29
|
+
}): string;
|
|
4
30
|
export declare function createRouteId(file: string): string;
|
|
5
31
|
export declare function findEntryFile(basePath: string): string;
|
|
6
32
|
export declare function generateWithProps(): string;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
import * as Effect from 'effect/Effect';
|
|
2
2
|
import type { RsbuildPluginAPI } from '@rsbuild/core';
|
|
3
3
|
import { getBuildManifest } from './build-manifest.js';
|
|
4
|
-
import {
|
|
4
|
+
import { type ReactRouterManifestForDev as ReactRouterManifest, type ReactRouterManifestStats, type RouteChunkManifestOptions, type RouteModuleAnalysisProvider, type RouteManifestModuleExports } from './manifest.js';
|
|
5
5
|
import type { Config, ResolvedReactRouterConfig } from './react-router-config.js';
|
|
6
6
|
import type { PluginOptions, Route } from './types.js';
|
|
7
|
-
type ReactRouterManifest = Awaited<ReturnType<typeof getReactRouterManifestForDev>>;
|
|
8
7
|
type PrerenderBuildApi = Pick<RsbuildPluginAPI, 'logger' | 'getNormalizedConfig'>;
|
|
9
8
|
type RunReactRouterPrerenderBuildOptions = {
|
|
10
9
|
api: PrerenderBuildApi;
|
|
@@ -24,13 +23,14 @@ type RunReactRouterPrerenderBuildOptions = {
|
|
|
24
23
|
pluginOptions: PluginOptions;
|
|
25
24
|
appDirectory: string;
|
|
26
25
|
assetPrefix: string;
|
|
27
|
-
routeChunkOptions:
|
|
26
|
+
routeChunkOptions: RouteChunkManifestOptions | undefined;
|
|
27
|
+
routeModuleAnalysis?: RouteModuleAnalysisProvider;
|
|
28
28
|
buildManifest: Awaited<ReturnType<typeof getBuildManifest>>;
|
|
29
|
-
|
|
29
|
+
buildEndReactRouterConfig: ResolvedReactRouterConfig;
|
|
30
30
|
buildEnd: Config['buildEnd'];
|
|
31
31
|
};
|
|
32
32
|
export declare const createBuildRequestEffect: <T>(input: string | URL, init: RequestInit | undefined, handle: (request: Request) => Promise<T>) => Effect.Effect<T, Error, never>;
|
|
33
33
|
export declare const withBuildRequest: <T>(input: string | URL, init: RequestInit | undefined, handle: (request: Request) => Promise<T>) => Promise<T>;
|
|
34
|
-
export declare const createBoundedPrerenderTasksEffect: (prerenderPaths:
|
|
34
|
+
export declare const createBoundedPrerenderTasksEffect: <T>(prerenderPaths: T[], concurrency: number, renderPath: (path: T) => Effect.Effect<void, Error, never>) => Effect.Effect<void, Error, never>;
|
|
35
35
|
export declare const runReactRouterPrerenderBuild: (options: RunReactRouterPrerenderBuildOptions) => Promise<void>;
|
|
36
36
|
export {};
|
package/dist/prerender.d.ts
CHANGED
|
@@ -1,13 +1,9 @@
|
|
|
1
1
|
import type { Config } from './react-router-config.js';
|
|
2
|
+
import type { PrerenderConfigObject } from './types.js';
|
|
2
3
|
import type { RouteConfigEntry } from '@react-router/dev/routes';
|
|
3
4
|
import { matchRoutes } from 'react-router';
|
|
4
5
|
type ReactRouterPrerenderConfig = Config['prerender'];
|
|
5
6
|
type MatchRouteObject = Parameters<typeof matchRoutes>[0] extends Array<infer R> ? R : never;
|
|
6
|
-
type PrerenderConfigObject = Extract<NonNullable<ReactRouterPrerenderConfig>, {
|
|
7
|
-
paths: unknown;
|
|
8
|
-
}> & {
|
|
9
|
-
unstable_concurrency?: number;
|
|
10
|
-
};
|
|
11
7
|
type PrerenderConfig = ReactRouterPrerenderConfig | PrerenderConfigObject;
|
|
12
8
|
type PrerenderResolveOptions = {
|
|
13
9
|
logWarning?: boolean;
|
|
@@ -2,17 +2,19 @@ import type { BuildManifest as ReactRouterBuildManifest, Config as ReactRouterCo
|
|
|
2
2
|
import type { NormalizedConfig } from '@rsbuild/core';
|
|
3
3
|
import type { RouteConfigEntry } from '@react-router/dev/routes';
|
|
4
4
|
import * as Effect from 'effect/Effect';
|
|
5
|
+
import type { PrerenderConfigObject, PrerenderPathsConfig } from './types.js';
|
|
5
6
|
export type BuildEndHook = {
|
|
6
7
|
bivarianceHack(args: {
|
|
7
8
|
buildManifest: ReactRouterBuildManifest | undefined;
|
|
8
9
|
reactRouterConfig: ResolvedReactRouterConfig;
|
|
9
|
-
|
|
10
|
+
rsbuildConfig: NormalizedConfig;
|
|
10
11
|
}): void | Promise<void>;
|
|
11
12
|
}['bivarianceHack'];
|
|
12
13
|
type SplitRouteModulesConfig = boolean | 'enforce';
|
|
13
|
-
export type Config = Omit<ReactRouterConfig, 'buildEnd' | 'future' | 'splitRouteModules' | 'subResourceIntegrity'> & {
|
|
14
|
+
export type Config = Omit<ReactRouterConfig, 'buildEnd' | 'future' | 'prerender' | 'splitRouteModules' | 'subResourceIntegrity'> & {
|
|
14
15
|
buildEnd?: BuildEndHook;
|
|
15
16
|
future?: Partial<FutureConfig>;
|
|
17
|
+
prerender?: PrerenderConfig;
|
|
16
18
|
splitRouteModules?: SplitRouteModulesConfig;
|
|
17
19
|
subResourceIntegrity?: boolean;
|
|
18
20
|
};
|
|
@@ -24,6 +26,7 @@ type FutureConfig = {
|
|
|
24
26
|
v8_splitRouteModules: boolean | 'enforce';
|
|
25
27
|
v8_viteEnvironmentApi: boolean;
|
|
26
28
|
};
|
|
29
|
+
type PrerenderConfig = PrerenderPathsConfig | PrerenderConfigObject | undefined;
|
|
27
30
|
type RouteManifestEntry = {
|
|
28
31
|
id: string;
|
|
29
32
|
parentId?: string;
|
|
@@ -35,9 +38,15 @@ type RouteManifestEntry = {
|
|
|
35
38
|
type RouteManifest = Record<string, RouteManifestEntry>;
|
|
36
39
|
type ResolveReactRouterConfigResult = {
|
|
37
40
|
resolved: ResolvedReactRouterConfig;
|
|
41
|
+
userAndPresetConfig: Config;
|
|
38
42
|
presets: NonNullable<Config['presets']>;
|
|
39
43
|
hasConfiguredServerModuleFormat: boolean;
|
|
40
44
|
};
|
|
45
|
+
export declare const getDefaultTrailingSlashAwareDataRequests: (reactRouterVersion?: string | undefined) => boolean;
|
|
46
|
+
export declare const resolveRouteDiscoveryConfig: ({ ssr, userRouteDiscovery, }: {
|
|
47
|
+
ssr: boolean;
|
|
48
|
+
userRouteDiscovery: Config["routeDiscovery"];
|
|
49
|
+
}) => Config["routeDiscovery"];
|
|
41
50
|
export type ResolvedReactRouterConfig = Readonly<{
|
|
42
51
|
appDirectory: string;
|
|
43
52
|
basename: string;
|
|
@@ -57,5 +66,4 @@ export type ResolvedReactRouterConfig = Readonly<{
|
|
|
57
66
|
unstable_routeConfig: RouteConfigEntry[];
|
|
58
67
|
}>;
|
|
59
68
|
export declare const resolveReactRouterConfigEffect: (reactRouterUserConfig: Config) => Effect.Effect<ResolveReactRouterConfigResult, Error, never>;
|
|
60
|
-
export declare const resolveReactRouterConfig: (reactRouterUserConfig: Config) => Promise<ResolveReactRouterConfigResult>;
|
|
61
69
|
export {};
|
|
@@ -27,10 +27,12 @@ type RouteChunkArtifact = {
|
|
|
27
27
|
map: null;
|
|
28
28
|
};
|
|
29
29
|
export declare const HMR_PATCHABLE_ROUTE_FLAGS: readonly ["hasAction", "hasClientAction", "hasClientLoader", "hasClientMiddleware", "hasErrorBoundary", "hasLoader"];
|
|
30
|
-
|
|
31
|
-
export declare const
|
|
30
|
+
type RouteHmrMetadata = Record<(typeof HMR_PATCHABLE_ROUTE_FLAGS)[number], boolean>;
|
|
31
|
+
export declare const buildRouteHmrMetadata: (exportNames: readonly string[]) => RouteHmrMetadata;
|
|
32
|
+
export declare const buildRouteClientEntryCode: ({ exportNames, chunkedExports, sharedChunkedExports, isServer, resourcePath, routeId, devHmr, }: {
|
|
32
33
|
exportNames: readonly string[];
|
|
33
34
|
chunkedExports: readonly string[];
|
|
35
|
+
sharedChunkedExports?: readonly string[];
|
|
34
36
|
isServer: boolean;
|
|
35
37
|
resourcePath: string;
|
|
36
38
|
routeId?: string;
|
package/dist/route-chunks.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
export type RouteChunkExportName = 'clientAction' | 'clientLoader' | 'clientMiddleware' | 'HydrateFallback';
|
|
2
|
-
export type RouteChunkName = 'main' | RouteChunkExportName;
|
|
2
|
+
export type RouteChunkName = 'main' | RouteChunkExportName | (string & {});
|
|
3
3
|
export type RouteChunkConfig = {
|
|
4
4
|
splitRouteModules?: boolean | 'enforce';
|
|
5
5
|
appDirectory: string;
|
|
@@ -15,6 +15,7 @@ export type RouteChunkInfo = {
|
|
|
15
15
|
hasRouteChunks: boolean;
|
|
16
16
|
hasRouteChunkByExportName: Record<RouteChunkExportName, boolean>;
|
|
17
17
|
chunkedExports: RouteChunkExportName[];
|
|
18
|
+
sharedChunkedExports: string[];
|
|
18
19
|
};
|
|
19
20
|
export declare const routeChunkExportNames: RouteChunkExportName[];
|
|
20
21
|
export declare const routeChunkNames: RouteChunkName[];
|
|
@@ -1,5 +1,3 @@
|
|
|
1
1
|
import type { ParseResult } from 'yuku-parser';
|
|
2
2
|
import { type AnyNode } from './route-ast.js';
|
|
3
|
-
export declare function toFunctionExpression(decl: AnyNode): AnyNode;
|
|
4
|
-
export declare function toClassExpression(decl: AnyNode): AnyNode;
|
|
5
3
|
export declare const transformRoute: (ast: ParseResult | AnyNode) => void;
|
|
@@ -2,5 +2,8 @@ import { type ParseResult } from 'yuku-parser';
|
|
|
2
2
|
import { type AnyNode } from './route-ast.js';
|
|
3
3
|
export declare function validateDestructuredExports(id: AnyNode, exportsToRemove: readonly string[]): void;
|
|
4
4
|
export declare function invalidDestructureError(name: string): Error;
|
|
5
|
-
export declare const
|
|
5
|
+
export declare const collectReferencedNames: (node: AnyNode) => Set<string>;
|
|
6
|
+
export declare const removeExports: (ast: ParseResult | AnyNode, exportsToRemove: readonly string[], exportsToRemoveSet?: ReadonlySet<string>, options?: {
|
|
7
|
+
pruneDeadDeclarations?: boolean;
|
|
8
|
+
}) => boolean;
|
|
6
9
|
export declare const removeUnusedImports: (ast: ParseResult | AnyNode) => void;
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
import type { Rspack } from '@rsbuild/core';
|
|
2
|
+
import type { Route } from './types.js';
|
|
3
|
+
type QuerylessRouteImportPlugin = {
|
|
4
|
+
name: string;
|
|
5
|
+
apply(compiler: Rspack.Compiler): void;
|
|
6
|
+
};
|
|
7
|
+
export declare const resolveQuerylessRouteImportRequest: ({ compilerName, context, issuer, rsc, request, routeByFilePath, }: {
|
|
8
|
+
compilerName?: string;
|
|
9
|
+
context?: string;
|
|
10
|
+
issuer?: string;
|
|
11
|
+
rsc?: boolean;
|
|
12
|
+
request?: string;
|
|
13
|
+
routeByFilePath: ReadonlyMap<string, Route>;
|
|
14
|
+
}) => string | undefined;
|
|
15
|
+
export declare const createQuerylessRouteImportPlugin: (routeByFilePath: ReadonlyMap<string, Route>, options?: {
|
|
16
|
+
rsc?: boolean;
|
|
17
|
+
}) => QuerylessRouteImportPlugin;
|
|
18
|
+
export {};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { LoaderDefinition } from '@rspack/core';
|
|
2
|
+
export type RouteModuleTransformLoaderOptions = {
|
|
3
|
+
environmentName: string;
|
|
4
|
+
performanceScopeId: string;
|
|
5
|
+
logPerformance: boolean;
|
|
6
|
+
ssr: boolean;
|
|
7
|
+
isBuild: boolean;
|
|
8
|
+
isSpaMode: boolean;
|
|
9
|
+
rootRoutePath: string | null;
|
|
10
|
+
devHmr: boolean;
|
|
11
|
+
};
|
|
12
|
+
export declare const flushRouteModuleTransformLoaderPerformance: () => void;
|
|
13
|
+
declare const routeModuleTransformLoader: LoaderDefinition<RouteModuleTransformLoaderOptions>;
|
|
14
|
+
export default routeModuleTransformLoader;
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
let performanceFlushTimer;
|
|
2
|
+
import { threadId } from "node:worker_threads";
|
|
3
|
+
import remapping from "@jridgewell/remapping";
|
|
4
|
+
import { createReactRouterPerformanceProfiler, executeRouteTransformTask } from "./511.js";
|
|
5
|
+
let performanceWorkerId = `process-${process.pid}:thread-${threadId}`, performanceProfilersByScope = new Map(), flushRouteModuleTransformLoaderPerformance = ()=>{
|
|
6
|
+
for (let profilers of (performanceFlushTimer && (clearTimeout(performanceFlushTimer), performanceFlushTimer = void 0), performanceProfilersByScope.values()))for (let [environment, profiler] of profilers)profiler.flush('unknown' === environment ? void 0 : environment, {
|
|
7
|
+
partial: !0,
|
|
8
|
+
workerId: performanceWorkerId
|
|
9
|
+
});
|
|
10
|
+
performanceProfilersByScope.clear();
|
|
11
|
+
};
|
|
12
|
+
process.once('beforeExit', flushRouteModuleTransformLoaderPerformance);
|
|
13
|
+
let route_module_transform_loader_routeModuleTransformLoader = async function(source, inputSourceMap) {
|
|
14
|
+
let callback = this.async(), options = this.getOptions(), transform = ()=>executeRouteTransformTask({
|
|
15
|
+
kind: 'routeModule',
|
|
16
|
+
code: String(source),
|
|
17
|
+
resource: this.resource,
|
|
18
|
+
resourcePath: this.resourcePath,
|
|
19
|
+
environmentName: options.environmentName,
|
|
20
|
+
sourceMaps: !!this.sourceMap,
|
|
21
|
+
ssr: options.ssr,
|
|
22
|
+
isBuild: options.isBuild,
|
|
23
|
+
isSpaMode: options.isSpaMode,
|
|
24
|
+
rootRoutePath: options.rootRoutePath,
|
|
25
|
+
devHmr: options.devHmr
|
|
26
|
+
});
|
|
27
|
+
try {
|
|
28
|
+
var scopeId, environment;
|
|
29
|
+
let profilers, environmentKey, profiler, generatedMap, result = options.logPerformance ? await (scopeId = options.performanceScopeId, environment = options.environmentName, !(profilers = performanceProfilersByScope.get(scopeId)) && (profilers = new Map(), performanceProfilersByScope.set(scopeId, profilers)), environmentKey = environment ?? 'unknown', !(profiler = profilers.get(environmentKey)) && (profiler = createReactRouterPerformanceProfiler({
|
|
30
|
+
enabled: !0,
|
|
31
|
+
log: (message)=>console.info(message)
|
|
32
|
+
}), profilers.set(environmentKey, profiler)), profiler).record(options.environmentName, 'route:module', this.resource, transform) : await transform(), outputSourceMap = result.map && inputSourceMap ? (generatedMap = result.map, JSON.parse(remapping([
|
|
33
|
+
generatedMap,
|
|
34
|
+
inputSourceMap
|
|
35
|
+
], ()=>null).toString())) : result.map;
|
|
36
|
+
callback(null, result.code, outputSourceMap ?? void 0);
|
|
37
|
+
} catch (error) {
|
|
38
|
+
callback(error instanceof Error ? error : Error(String(error)));
|
|
39
|
+
} finally{
|
|
40
|
+
options.logPerformance && (performanceFlushTimer && clearTimeout(performanceFlushTimer), performanceFlushTimer = setTimeout(flushRouteModuleTransformLoaderPerformance, 50));
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
export default route_module_transform_loader_routeModuleTransformLoader;
|
|
44
|
+
export { flushRouteModuleTransformLoaderPerformance };
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type { Rspack } from '@rsbuild/core';
|
|
2
|
+
import type { PluginOptions, Route } from './types.js';
|
|
3
|
+
export declare const shouldUseRouteModuleTransformLoader: (parallelRouteTransform: PluginOptions["parallelRouteTransform"]) => boolean;
|
|
4
|
+
export declare const registerRouteModuleTransformRules: (rspackConfig: Rspack.Configuration, { environmentName, ssr, isBuild, isSpaMode, rootRoutePath, devHmr, logPerformance, routeByFilePath, parallelRouteTransform, }: {
|
|
5
|
+
environmentName: string;
|
|
6
|
+
ssr: boolean;
|
|
7
|
+
isBuild: boolean;
|
|
8
|
+
isSpaMode: boolean;
|
|
9
|
+
rootRoutePath: string | null;
|
|
10
|
+
devHmr: boolean;
|
|
11
|
+
logPerformance: boolean;
|
|
12
|
+
routeByFilePath: Map<string, Route>;
|
|
13
|
+
parallelRouteTransform: PluginOptions["parallelRouteTransform"];
|
|
14
|
+
}) => void;
|
|
@@ -46,5 +46,11 @@ export type RouteTransformTask = RouteClientEntryTransformTask | RouteChunkTrans
|
|
|
46
46
|
export type RouteTransformTaskOptions = {
|
|
47
47
|
routeChunkCache?: RouteChunkCache;
|
|
48
48
|
};
|
|
49
|
+
export type RouteTransformRunner = (task: RouteTransformTask) => Promise<RouteTransformResult>;
|
|
50
|
+
export declare const validateSpaModeRouteExports: ({ exportNames, resourcePath, rootRoutePath, }: {
|
|
51
|
+
exportNames: readonly string[];
|
|
52
|
+
resourcePath: string;
|
|
53
|
+
rootRoutePath: string | null;
|
|
54
|
+
}) => void;
|
|
49
55
|
export declare const executeRouteTransformTask: (task: RouteTransformTask, options?: RouteTransformTaskOptions) => Promise<RouteTransformResult>;
|
|
50
56
|
export {};
|
package/dist/route-watch.d.ts
CHANGED
|
@@ -1,5 +1,8 @@
|
|
|
1
1
|
import { type FSWatcher } from 'node:fs';
|
|
2
2
|
import type { RsbuildConfig } from '@rsbuild/core';
|
|
3
|
+
import * as Effect from 'effect/Effect';
|
|
4
|
+
import type * as Scope from 'effect/Scope';
|
|
5
|
+
import { type PluginEffectRuntime } from './effect-runtime.js';
|
|
3
6
|
import type { Route } from './types.js';
|
|
4
7
|
type RouteManifestSnapshotEntry = Pick<Route, 'caseSensitive' | 'file' | 'id' | 'index' | 'parentId' | 'path'>;
|
|
5
8
|
type RouteManifestSnapshotEntryPair = readonly [
|
|
@@ -11,11 +14,8 @@ type WatchFilesConfig = NonNullable<NonNullable<RsbuildConfig['dev']>['watchFile
|
|
|
11
14
|
export type WatchFileConfig = Exclude<WatchFilesConfig, readonly unknown[]> | Extract<WatchFilesConfig, readonly unknown[]>[number];
|
|
12
15
|
type DirectoryWatcher = Pick<FSWatcher, 'close'>;
|
|
13
16
|
type WatchDirectoryEntry = (directory: string, onChange: () => void, onError: (error: unknown) => void) => DirectoryWatcher;
|
|
14
|
-
export
|
|
15
|
-
|
|
16
|
-
export declare const createRouteManifestSnapshot: (routes: RouteManifestSnapshotEntries) => Set<string>;
|
|
17
|
-
export declare const ensureDevRestartMarker: (restartMarkerPath: string) => Promise<void>;
|
|
18
|
-
export declare const createRouteTopologyWatcher: ({ watchDirectory, getRouteTopology, initialRouteTopology, restartMarkerPath, onError, onRouteTopologyChange, watchDirectoryEntry: watchDirectoryOverride, }: {
|
|
17
|
+
export type CreateRouteTopologyWatcherOptions = {
|
|
18
|
+
runtime: PluginEffectRuntime;
|
|
19
19
|
watchDirectory: string;
|
|
20
20
|
getRouteTopology: () => Promise<Set<string>>;
|
|
21
21
|
initialRouteTopology?: Set<string>;
|
|
@@ -23,5 +23,10 @@ export declare const createRouteTopologyWatcher: ({ watchDirectory, getRouteTopo
|
|
|
23
23
|
onError: (error: unknown) => void;
|
|
24
24
|
onRouteTopologyChange?: () => void | Promise<void>;
|
|
25
25
|
watchDirectoryEntry?: WatchDirectoryEntry;
|
|
26
|
-
}
|
|
26
|
+
};
|
|
27
|
+
export declare const mergeWatchFiles: (existing: WatchFilesConfig | undefined, additions: WatchFileConfig[]) => WatchFilesConfig;
|
|
28
|
+
export declare const getRouteRestartMarkerPath: (appDirectory: string) => string;
|
|
29
|
+
export declare const createRouteManifestSnapshot: (routes: RouteManifestSnapshotEntries) => Set<string>;
|
|
30
|
+
export declare const ensureDevRestartMarker: (restartMarkerPath: string) => Promise<void>;
|
|
31
|
+
export declare const acquireRouteTopologyWatcher: (options: CreateRouteTopologyWatcherOptions) => Effect.Effect<() => Effect.Effect<void, Error>, Error, Scope.Scope>;
|
|
27
32
|
export {};
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
import type { RsbuildConfig } from '@rsbuild/core';
|
|
2
|
+
type RscDevServerSetup = NonNullable<NonNullable<RsbuildConfig['server']>['setup']>;
|
|
3
|
+
type RscDevServerSetupOptions = {
|
|
4
|
+
entryName: string;
|
|
5
|
+
pluginName: string;
|
|
6
|
+
};
|
|
7
|
+
/**
|
|
8
|
+
* Decides whether a dev-server request should skip the RSC request handler
|
|
9
|
+
* and fall through to the rest of the middleware chain.
|
|
10
|
+
*
|
|
11
|
+
* Only Rsbuild-internal endpoints (`/__rsbuild_*`, e.g. HMR web socket
|
|
12
|
+
* fallbacks) are bypassed. Everything else — any method, any pathname,
|
|
13
|
+
* with or without a file extension — is handled by the RSC server build,
|
|
14
|
+
* matching production where the RSC server handles every request.
|
|
15
|
+
*
|
|
16
|
+
* Static assets need no bypass here: the RSC middleware is registered via
|
|
17
|
+
* the callback returned from `server.setup`, which Rsbuild invokes only
|
|
18
|
+
* after its built-in middlewares (compiled assets, public dir) are
|
|
19
|
+
* registered. A request that reaches this middleware was already declined
|
|
20
|
+
* by static asset serving.
|
|
21
|
+
*/
|
|
22
|
+
export declare const shouldBypassRscDevRequest: (request: {
|
|
23
|
+
url?: string;
|
|
24
|
+
}) => boolean;
|
|
25
|
+
export declare function createReactRouterRscDevServerSetup({ entryName, pluginName, }: RscDevServerSetupOptions): RscDevServerSetup;
|
|
26
|
+
export {};
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
import type { RsbuildPluginAPI } from '@rsbuild/core';
|
|
2
|
+
import type { Config } from './react-router-config.js';
|
|
3
|
+
/**
|
|
4
|
+
* RSC-mode prerendering.
|
|
5
|
+
*
|
|
6
|
+
* Mirrors React Router's upstream RSC behavior, feeding the shared
|
|
7
|
+
* `prerender` plugin with one request per prerender path (plus
|
|
8
|
+
* `/__spa-fallback.html` when `ssr: false`) and post-processes each HTML
|
|
9
|
+
* response into two artifacts in the client build directory:
|
|
10
|
+
*
|
|
11
|
+
* - `<path>/index.html` — the prerendered document
|
|
12
|
+
* - `<path>.rsc` (`_.rsc` for `/`) — the RSC payload reassembled from the
|
|
13
|
+
* inline `__FLIGHT_DATA` scripts, served for client-side navigations
|
|
14
|
+
*
|
|
15
|
+
* Instead of an HTTP round-trip through a preview server, the RSC server
|
|
16
|
+
* bundle's default-exported `fetch` handler is invoked in-process, matching
|
|
17
|
+
* how classic mode prerenders through `createRequestHandler`.
|
|
18
|
+
*/
|
|
19
|
+
export declare const SPA_FALLBACK_REQUEST_PATH: string;
|
|
20
|
+
type RscPrerenderBuildApi = Pick<RsbuildPluginAPI, 'logger'>;
|
|
21
|
+
type RscPrerenderRequest = {
|
|
22
|
+
requestPath: string;
|
|
23
|
+
artifactPath: string;
|
|
24
|
+
};
|
|
25
|
+
type RunReactRouterRscPrerenderBuildOptions = {
|
|
26
|
+
api: RscPrerenderBuildApi;
|
|
27
|
+
hasWebEnvironment: boolean;
|
|
28
|
+
buildDirectory: string;
|
|
29
|
+
serverBuildFile?: string;
|
|
30
|
+
ssr: boolean;
|
|
31
|
+
prerenderConfig: Config['prerender'];
|
|
32
|
+
prerenderPaths: string[];
|
|
33
|
+
basename: string;
|
|
34
|
+
};
|
|
35
|
+
export declare const normalizeRscPrerenderBasename: (basename: string) => string;
|
|
36
|
+
/**
|
|
37
|
+
* The request paths to prerender: the resolved prerender paths joined with
|
|
38
|
+
* the basename, plus the SPA fallback document when `ssr: false`.
|
|
39
|
+
*/
|
|
40
|
+
export declare const getRscPrerenderRequests: ({ prerenderPaths, ssr, basename, }: {
|
|
41
|
+
prerenderPaths: string[];
|
|
42
|
+
ssr: boolean;
|
|
43
|
+
basename: string;
|
|
44
|
+
}) => RscPrerenderRequest[];
|
|
45
|
+
/**
|
|
46
|
+
* Reassembles the RSC payload from the inline flight data scripts that
|
|
47
|
+
* `react-router`'s HTML stream injects into server-rendered documents.
|
|
48
|
+
* Returns `null` when the document carries no flight data.
|
|
49
|
+
*/
|
|
50
|
+
export declare const extractRscFlightData: (html: string) => string | null;
|
|
51
|
+
export declare const getRscHtmlFilePath: (pathname: string) => string;
|
|
52
|
+
export declare const getRscPayloadFilePath: (pathname: string) => string;
|
|
53
|
+
export declare const runReactRouterRscPrerenderBuild: (options: RunReactRouterRscPrerenderBuildOptions) => Promise<void>;
|
|
54
|
+
export {};
|