rsbuild-plugin-react-router 0.5.0 → 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 +58 -208
- package/dist/511.js +370 -331
- package/dist/build-output-transforms.d.ts +30 -6
- 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 -1
- 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/index.cjs +3957 -2208
- package/dist/index.d.ts +3 -1
- package/dist/index.js +3470 -1793
- 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/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-transform-tasks.d.ts +5 -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 +30 -1
- package/package.json +69 -14
- package/src/build-output-transforms.ts +155 -21
- 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 -85
- 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/index.ts +661 -496
- 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/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-transform-tasks.ts +39 -25
- 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 +39 -1
- package/src/warnings/warn-on-client-source-maps.ts +6 -10
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { dirname, join } from 'node:path';
|
|
2
|
+
import { fileURLToPath } from 'node:url';
|
|
3
|
+
import type { RsbuildPlugin } from '@rsbuild/core';
|
|
4
|
+
import { resolve } from 'pathe';
|
|
5
|
+
import type { RouteChunkCache, RouteChunkConfig } from './route-chunks.js';
|
|
6
|
+
import type { Route } from './types.js';
|
|
7
|
+
import type { ReactRouterPerformanceProfiler } from './performance.js';
|
|
8
|
+
import { transformRscRouteModule } from './rsc-route-transforms.js';
|
|
9
|
+
|
|
10
|
+
const mdxRoutePattern = /\.mdx?$/i;
|
|
11
|
+
const RSC_ROUTE_TRANSFORM_LOADER = 'react-router-rsc-route-transform';
|
|
12
|
+
|
|
13
|
+
// Structural types for the compiler surface the transform plugin touches.
|
|
14
|
+
// Rspack's own types do not expose the `childCompiler` compilation hook or
|
|
15
|
+
// the custom property the loader reads, so we describe just what we use.
|
|
16
|
+
type RscTransformCarrier<Transform> = {
|
|
17
|
+
__reactRouterRscRouteTransform?: Transform;
|
|
18
|
+
};
|
|
19
|
+
type TapHook<Value> = {
|
|
20
|
+
tap(name: string, handler: (value: Value) => void): void;
|
|
21
|
+
};
|
|
22
|
+
type RscTransformCompiler<Transform> = RscTransformCarrier<Transform> & {
|
|
23
|
+
hooks: {
|
|
24
|
+
thisCompilation: TapHook<{
|
|
25
|
+
hooks: { childCompiler: TapHook<RscTransformCarrier<Transform>> };
|
|
26
|
+
}>;
|
|
27
|
+
};
|
|
28
|
+
};
|
|
29
|
+
|
|
30
|
+
const getRscRouteTransformLoaderPath = (): string =>
|
|
31
|
+
join(
|
|
32
|
+
dirname(fileURLToPath(import.meta.url)),
|
|
33
|
+
import.meta.url.endsWith('.cjs')
|
|
34
|
+
? 'rsc-route-transform-loader.cjs'
|
|
35
|
+
: 'rsc-route-transform-loader.js'
|
|
36
|
+
);
|
|
37
|
+
|
|
38
|
+
export const registerReactRouterRscRouteTransforms = ({
|
|
39
|
+
api,
|
|
40
|
+
isBuild,
|
|
41
|
+
performanceProfiler,
|
|
42
|
+
routeByFilePath,
|
|
43
|
+
routeChunkCache,
|
|
44
|
+
routeChunkConfig,
|
|
45
|
+
}: {
|
|
46
|
+
api: Parameters<RsbuildPlugin['setup']>[0];
|
|
47
|
+
isBuild: boolean;
|
|
48
|
+
performanceProfiler: Pick<ReactRouterPerformanceProfiler, 'record'>;
|
|
49
|
+
routeByFilePath: Map<string, Route>;
|
|
50
|
+
routeChunkCache: RouteChunkCache;
|
|
51
|
+
routeChunkConfig: RouteChunkConfig;
|
|
52
|
+
}): void => {
|
|
53
|
+
const transformRoute = async (
|
|
54
|
+
args: Parameters<Parameters<typeof api.transform>[1]>[0]
|
|
55
|
+
) => {
|
|
56
|
+
const route = routeByFilePath.get(resolve(args.resourcePath));
|
|
57
|
+
if (!route) {
|
|
58
|
+
return { code: args.code };
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return performanceProfiler.record(
|
|
62
|
+
args.environment?.name,
|
|
63
|
+
'rsc:route',
|
|
64
|
+
args.resource,
|
|
65
|
+
() =>
|
|
66
|
+
transformRscRouteModule({
|
|
67
|
+
code: args.code,
|
|
68
|
+
resourcePath: args.resourcePath,
|
|
69
|
+
resourceQuery: args.resourceQuery,
|
|
70
|
+
isRootRoute: route.id === 'root',
|
|
71
|
+
routeId: route.id,
|
|
72
|
+
routeByFilePath,
|
|
73
|
+
routeChunkCache,
|
|
74
|
+
routeChunkConfig,
|
|
75
|
+
isServerEnvironment: args.environment.name === 'node',
|
|
76
|
+
isDev: !isBuild,
|
|
77
|
+
})
|
|
78
|
+
);
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
api.transform(
|
|
82
|
+
{
|
|
83
|
+
test: path =>
|
|
84
|
+
!mdxRoutePattern.test(path) && routeByFilePath.has(resolve(path)),
|
|
85
|
+
order: 'pre',
|
|
86
|
+
},
|
|
87
|
+
transformRoute
|
|
88
|
+
);
|
|
89
|
+
|
|
90
|
+
api.modifyBundlerChain((chain, { CHAIN_ID, environment }) => {
|
|
91
|
+
if (!chain.module.rules.has('mdx')) {
|
|
92
|
+
return;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
chain.plugin(`${RSC_ROUTE_TRANSFORM_LOADER}-${environment.name}`).use(
|
|
96
|
+
class ReactRouterRscRouteTransformPlugin {
|
|
97
|
+
apply(compiler: RscTransformCompiler<typeof transformRoute>) {
|
|
98
|
+
compiler.__reactRouterRscRouteTransform = transformRoute;
|
|
99
|
+
compiler.hooks.thisCompilation.tap(
|
|
100
|
+
RSC_ROUTE_TRANSFORM_LOADER,
|
|
101
|
+
compilation => {
|
|
102
|
+
compilation.hooks.childCompiler.tap(
|
|
103
|
+
RSC_ROUTE_TRANSFORM_LOADER,
|
|
104
|
+
childCompiler => {
|
|
105
|
+
childCompiler.__reactRouterRscRouteTransform = transformRoute;
|
|
106
|
+
}
|
|
107
|
+
);
|
|
108
|
+
}
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
);
|
|
113
|
+
|
|
114
|
+
const mdxRule = chain.module.rules.get('mdx');
|
|
115
|
+
const rscRouteTransformLoaderPath = getRscRouteTransformLoaderPath();
|
|
116
|
+
const use = mdxRule
|
|
117
|
+
.use(RSC_ROUTE_TRANSFORM_LOADER)
|
|
118
|
+
.loader(rscRouteTransformLoaderPath)
|
|
119
|
+
.options({
|
|
120
|
+
environmentName: environment.name,
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
if (mdxRule.uses.has('mdx')) {
|
|
124
|
+
use.before('mdx');
|
|
125
|
+
}
|
|
126
|
+
|
|
127
|
+
if (!mdxRule.uses.has(CHAIN_ID.USE.SWC)) {
|
|
128
|
+
const jsRule = chain.module.rules.get(CHAIN_ID.RULE.JS);
|
|
129
|
+
const jsMainRule = jsRule?.oneOfs.get(CHAIN_ID.ONE_OF.JS_MAIN);
|
|
130
|
+
const jsSwcUse = jsMainRule?.uses.get(CHAIN_ID.USE.SWC);
|
|
131
|
+
if (jsSwcUse) {
|
|
132
|
+
const mdxSwcUse = mdxRule.use(CHAIN_ID.USE.SWC);
|
|
133
|
+
const swcLoader = jsSwcUse.get('loader');
|
|
134
|
+
const swcOptions = jsSwcUse.get('options');
|
|
135
|
+
if (swcLoader) {
|
|
136
|
+
mdxSwcUse.loader(swcLoader);
|
|
137
|
+
}
|
|
138
|
+
if (swcOptions) {
|
|
139
|
+
mdxSwcUse.options(swcOptions);
|
|
140
|
+
}
|
|
141
|
+
mdxSwcUse.before(RSC_ROUTE_TRANSFORM_LOADER);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
});
|
|
145
|
+
};
|