@octanejs/tanstack-start 0.1.27 → 0.1.29

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.
Files changed (38) hide show
  1. package/README.md +19 -1
  2. package/THIRD_PARTY_NOTICES.md +6 -5
  3. package/package.json +18 -6
  4. package/src/client-only-server-strip-loader.js +7 -0
  5. package/src/client-only-server-strip.js +34 -25
  6. package/src/internal/README.md +7 -7
  7. package/src/internal/start-plugin-core/rsbuild/import-protection.d.ts +27 -0
  8. package/src/internal/start-plugin-core/rsbuild/import-protection.js +1193 -0
  9. package/src/internal/start-plugin-core/rsbuild/index.d.ts +9 -0
  10. package/src/internal/start-plugin-core/rsbuild/index.js +3 -0
  11. package/src/internal/start-plugin-core/rsbuild/normalized-client-build.d.ts +20 -0
  12. package/src/internal/start-plugin-core/rsbuild/normalized-client-build.js +261 -0
  13. package/src/internal/start-plugin-core/rsbuild/planning.d.ts +56 -0
  14. package/src/internal/start-plugin-core/rsbuild/planning.js +173 -0
  15. package/src/internal/start-plugin-core/rsbuild/plugin.d.ts +7 -0
  16. package/src/internal/start-plugin-core/rsbuild/plugin.js +504 -0
  17. package/src/internal/start-plugin-core/rsbuild/post-build.d.ts +10 -0
  18. package/src/internal/start-plugin-core/rsbuild/post-build.js +59 -0
  19. package/src/internal/start-plugin-core/rsbuild/schema.d.ts +2441 -0
  20. package/src/internal/start-plugin-core/rsbuild/schema.js +28 -0
  21. package/src/internal/start-plugin-core/rsbuild/server-middleware.d.ts +32 -0
  22. package/src/internal/start-plugin-core/rsbuild/server-middleware.js +139 -0
  23. package/src/internal/start-plugin-core/rsbuild/start-compiler-host.d.ts +36 -0
  24. package/src/internal/start-plugin-core/rsbuild/start-compiler-host.js +322 -0
  25. package/src/internal/start-plugin-core/rsbuild/start-compiler-metadata-loader.d.ts +10 -0
  26. package/src/internal/start-plugin-core/rsbuild/start-compiler-metadata-loader.js +12 -0
  27. package/src/internal/start-plugin-core/rsbuild/start-compiler-metadata.d.ts +14 -0
  28. package/src/internal/start-plugin-core/rsbuild/start-compiler-metadata.js +5 -0
  29. package/src/internal/start-plugin-core/rsbuild/start-router-plugin.d.ts +19 -0
  30. package/src/internal/start-plugin-core/rsbuild/start-router-plugin.js +69 -0
  31. package/src/internal/start-plugin-core/rsbuild/swc-rsc.d.ts +17 -0
  32. package/src/internal/start-plugin-core/rsbuild/swc-rsc.js +118 -0
  33. package/src/internal/start-plugin-core/rsbuild/types.d.ts +17 -0
  34. package/src/internal/start-plugin-core/rsbuild/types.js +0 -0
  35. package/src/internal/start-plugin-core/rsbuild/virtual-modules.d.ts +60 -0
  36. package/src/internal/start-plugin-core/rsbuild/virtual-modules.js +359 -0
  37. package/src/plugin-rsbuild.d.ts +25 -0
  38. package/src/plugin-rsbuild.js +79 -0
@@ -0,0 +1,9 @@
1
+ export { RSBUILD_ENVIRONMENT_NAMES } from './planning.js';
2
+ export type { TanStackStartRsbuildPluginCoreOptions } from './types.js';
3
+ export type { TanStackStartRsbuildInputConfig } from './schema.js';
4
+ export type {
5
+ StartCompilerImportTransform,
6
+ StartCompilerTransformCandidate,
7
+ StartCompilerTransformContext,
8
+ } from '../types.js';
9
+ export { tanStackStartRsbuild } from './plugin.js';
@@ -0,0 +1,3 @@
1
+ import { RSBUILD_ENVIRONMENT_NAMES } from './planning.js';
2
+ import { tanStackStartRsbuild } from './plugin.js';
3
+ export { RSBUILD_ENVIRONMENT_NAMES, tanStackStartRsbuild };
@@ -0,0 +1,20 @@
1
+ import { RsbuildPluginAPI, Rspack } from '@rsbuild/core';
2
+ import { NormalizedClientBuild } from '../types.js';
3
+ type RspackCompilation = Rspack.Compilation;
4
+ /**
5
+ * Normalize an rspack compilation into a NormalizedClientBuild.
6
+ *
7
+ * Iterates ALL chunks in the compilation (initial + async), not just
8
+ * entrypoint chunks, to ensure route-split async chunks are included.
9
+ */
10
+ export declare function normalizeRspackClientBuild(
11
+ compilation: RspackCompilation,
12
+ ): NormalizedClientBuild;
13
+ /**
14
+ * Registers a processAssets hook to capture the client build stats
15
+ * after compilation. Returns a getter for the captured build.
16
+ */
17
+ export declare function registerClientBuildCapture(api: RsbuildPluginAPI): {
18
+ getClientBuild: () => NormalizedClientBuild | undefined;
19
+ };
20
+ export {};
@@ -0,0 +1,261 @@
1
+ import { tssHydrate } from '../hydration-constants.js';
2
+ import { getCssAssetSource } from '../start-manifest-plugin/inlineCss.js';
3
+ import { RSBUILD_ENVIRONMENT_NAMES } from './planning.js';
4
+ import { tsrSplit } from '#tanstack-start/router-plugin';
5
+ //#region src/rsbuild/normalized-client-build.ts
6
+ /**
7
+ * Extract route file paths from rspack module identifiers.
8
+ *
9
+ * In rspack, module identifiers contain query params similar to Vite's moduleIds.
10
+ * We look for the `tsr-split` query to identify route-split chunks.
11
+ */
12
+ function getRouteFilePathsFromModules(modules) {
13
+ let routeFilePaths;
14
+ let seen;
15
+ for (const mod of modules) {
16
+ const identifier = mod.identifier();
17
+ const lastBangIndex = identifier.lastIndexOf('!');
18
+ const resourcePart = lastBangIndex >= 0 ? identifier.slice(lastBangIndex + 1) : identifier;
19
+ const queryIndex = resourcePart.indexOf('?');
20
+ if (queryIndex < 0) continue;
21
+ const query = resourcePart.slice(queryIndex + 1);
22
+ if (!query.includes(tsrSplit)) continue;
23
+ if (!new URLSearchParams(query).has(tsrSplit)) continue;
24
+ const routeFilePath = mod.nameForCondition() ?? resourcePart.slice(0, queryIndex);
25
+ if (seen?.has(routeFilePath)) continue;
26
+ if (!routeFilePaths || !seen) {
27
+ routeFilePaths = [];
28
+ seen = /* @__PURE__ */ new Set();
29
+ }
30
+ routeFilePaths.push(routeFilePath);
31
+ seen.add(routeFilePath);
32
+ }
33
+ return routeFilePaths ?? [];
34
+ }
35
+ function getHydrationIdsFromModules(modules) {
36
+ let hydrationIds;
37
+ let seen;
38
+ for (const mod of modules) {
39
+ const identifier = mod.identifier();
40
+ const lastBangIndex = identifier.lastIndexOf('!');
41
+ const resourcePart = lastBangIndex >= 0 ? identifier.slice(lastBangIndex + 1) : identifier;
42
+ const queryIndex = resourcePart.indexOf('?');
43
+ if (queryIndex < 0) continue;
44
+ const query = resourcePart.slice(queryIndex + 1);
45
+ if (!query.includes('tss-hydrate')) continue;
46
+ const hydrationId = new URLSearchParams(query).get(tssHydrate);
47
+ if (!hydrationId || seen?.has(hydrationId)) continue;
48
+ if (!hydrationIds || !seen) {
49
+ hydrationIds = [];
50
+ seen = /* @__PURE__ */ new Set();
51
+ }
52
+ hydrationIds.push(hydrationId);
53
+ seen.add(hydrationId);
54
+ }
55
+ return hydrationIds ?? [];
56
+ }
57
+ /**
58
+ * Returns true for Rspack/webpack HMR runtime chunks that should never be
59
+ * surfaced to the Start manifest. These files are emitted on every rebuild
60
+ * (e.g. `index.<hash>.hot-update.mjs`) and must not be treated as the entry
61
+ * chunk, route preloads, or sibling imports.
62
+ */
63
+ function isHotUpdateAsset(file) {
64
+ return file.includes('.hot-update.');
65
+ }
66
+ /**
67
+ * True for any JS/MJS asset that should be included in the manifest.
68
+ * Excludes HMR runtime patches.
69
+ */
70
+ function isManifestJsAsset(file) {
71
+ if (!file.endsWith('.js') && !file.endsWith('.mjs')) return false;
72
+ return !isHotUpdateAsset(file);
73
+ }
74
+ /**
75
+ * Get all JS file names from a chunk.
76
+ */
77
+ function getChunkJsFiles(chunk) {
78
+ const jsFiles = [];
79
+ for (const file of chunk.files) if (isManifestJsAsset(file)) jsFiles.push(file);
80
+ return jsFiles;
81
+ }
82
+ /**
83
+ * Compute dynamicImports for a chunk by traversing its chunk groups'
84
+ * childrenIterable (async/dynamic import edges).
85
+ *
86
+ * In rspack, a chunk belongs to one or more ChunkGroups. Each ChunkGroup
87
+ * has childrenIterable — child ChunkGroups representing dynamic import()
88
+ * points. The JS files from those child groups' chunks are the
89
+ * dynamicImports (analogous to Rollup's OutputChunk.dynamicImports).
90
+ */
91
+ function computeDynamicImports(chunk) {
92
+ const dynamicImportFiles = [];
93
+ const seen = /* @__PURE__ */ new Set();
94
+ for (const group of chunk.groupsIterable)
95
+ for (const childGroup of group.childrenIterable)
96
+ for (const childChunk of childGroup.chunks)
97
+ for (const file of childChunk.files)
98
+ if (isManifestJsAsset(file) && !seen.has(file)) {
99
+ seen.add(file);
100
+ dynamicImportFiles.push(file);
101
+ }
102
+ return dynamicImportFiles;
103
+ }
104
+ /**
105
+ * Compute static imports (sibling chunks) for an async chunk.
106
+ *
107
+ * In rspack/webpack, an async chunk's ChunkGroup contains ALL chunks needed to
108
+ * satisfy that dynamic import — the async chunk itself plus any shared/vendor
109
+ * chunks it statically imports. This is analogous to Rollup's
110
+ * `OutputChunk.imports` for async chunks.
111
+ *
112
+ * We collect JS files from all sibling chunks in the group (excluding the
113
+ * current chunk's own file) to populate the `imports` field.
114
+ */
115
+ function computeAsyncChunkImports(chunk, currentFile) {
116
+ const imports = [];
117
+ const seen = /* @__PURE__ */ new Set();
118
+ seen.add(currentFile);
119
+ for (const group of chunk.groupsIterable)
120
+ for (const siblingChunk of group.chunks)
121
+ for (const file of siblingChunk.files)
122
+ if (isManifestJsAsset(file) && !seen.has(file)) {
123
+ seen.add(file);
124
+ imports.push(file);
125
+ }
126
+ return imports;
127
+ }
128
+ /**
129
+ * Normalize an rspack compilation into a NormalizedClientBuild.
130
+ *
131
+ * Iterates ALL chunks in the compilation (initial + async), not just
132
+ * entrypoint chunks, to ensure route-split async chunks are included.
133
+ */
134
+ function normalizeRspackClientBuild(compilation) {
135
+ const chunksByFileName = /* @__PURE__ */ new Map();
136
+ const chunkFileNamesByRouteFilePath = /* @__PURE__ */ new Map();
137
+ const cssFilesBySourcePath = /* @__PURE__ */ new Map();
138
+ const cssContentByFileName = /* @__PURE__ */ new Map();
139
+ let entryChunkFileName;
140
+ const entrypoint = compilation.entrypoints.get('index');
141
+ const initialJsFileNames = [];
142
+ const entryChunkSet = /* @__PURE__ */ new Set();
143
+ if (entrypoint)
144
+ for (const chunk of entrypoint.chunks) {
145
+ entryChunkSet.add(chunk);
146
+ for (const file of chunk.files) if (isManifestJsAsset(file)) initialJsFileNames.push(file);
147
+ }
148
+ for (const chunk of compilation.chunks) {
149
+ const modules = compilation.chunkGraph.getChunkModules(chunk);
150
+ const routeFilePaths = getRouteFilePathsFromModules(modules);
151
+ const hydrationIds = getHydrationIdsFromModules(modules);
152
+ const cssFiles = [];
153
+ const seenCssFiles = /* @__PURE__ */ new Set();
154
+ for (const auxFile of chunk.auxiliaryFiles)
155
+ if (auxFile.endsWith('.css') && !seenCssFiles.has(auxFile)) {
156
+ seenCssFiles.add(auxFile);
157
+ cssFiles.push(auxFile);
158
+ }
159
+ for (const mainFile of chunk.files)
160
+ if (mainFile.endsWith('.css') && !seenCssFiles.has(mainFile)) {
161
+ seenCssFiles.add(mainFile);
162
+ cssFiles.push(mainFile);
163
+ }
164
+ if (cssFiles.length > 0)
165
+ for (const mod of modules) {
166
+ const sourcePath = mod.nameForCondition();
167
+ if (!sourcePath) continue;
168
+ const existing = cssFilesBySourcePath.get(sourcePath);
169
+ cssFilesBySourcePath.set(
170
+ sourcePath,
171
+ existing ? appendUniqueStrings(existing, cssFiles) : cssFiles.slice(),
172
+ );
173
+ }
174
+ const isEntryChunk = chunk.name === 'index' && entryChunkSet.has(chunk);
175
+ const jsFiles = getChunkJsFiles(chunk);
176
+ if (jsFiles.length === 0) continue;
177
+ const dynamicImports = computeDynamicImports(chunk);
178
+ for (const file of jsFiles) {
179
+ const normalizedChunk = {
180
+ fileName: file,
181
+ isEntry: isEntryChunk,
182
+ imports: isEntryChunk
183
+ ? initialJsFileNames.filter((f) => f !== file)
184
+ : computeAsyncChunkImports(chunk, file),
185
+ dynamicImports,
186
+ css: [],
187
+ routeFilePaths,
188
+ hydrationIds,
189
+ };
190
+ chunksByFileName.set(file, normalizedChunk);
191
+ if (isEntryChunk && !entryChunkFileName) entryChunkFileName = file;
192
+ for (const routeFilePath of routeFilePaths) {
193
+ let chunkFileNames = chunkFileNamesByRouteFilePath.get(routeFilePath);
194
+ if (!chunkFileNames) {
195
+ chunkFileNames = [];
196
+ chunkFileNamesByRouteFilePath.set(routeFilePath, chunkFileNames);
197
+ }
198
+ chunkFileNames.push(file);
199
+ }
200
+ }
201
+ for (const cssFile of cssFiles)
202
+ for (const file of jsFiles) {
203
+ const existing = chunksByFileName.get(file);
204
+ if (existing && !existing.css.includes(cssFile)) existing.css.push(cssFile);
205
+ }
206
+ }
207
+ if (!entryChunkFileName) throw new Error('No entry file found in rspack client build');
208
+ for (const asset of compilation.getAssets()) {
209
+ if (!asset.name.endsWith('.css')) continue;
210
+ const css = getCssAssetSource(asset.source.source());
211
+ if (css !== void 0) cssContentByFileName.set(asset.name, css);
212
+ }
213
+ const rscEntrypoint = compilation.entrypoints.get('rsc');
214
+ if (rscEntrypoint && entryChunkFileName) {
215
+ const mainEntryChunk = chunksByFileName.get(entryChunkFileName);
216
+ if (mainEntryChunk)
217
+ for (const rscChunk of rscEntrypoint.chunks) {
218
+ const allFiles = [...rscChunk.files, ...rscChunk.auxiliaryFiles];
219
+ for (const file of allFiles)
220
+ if (file.endsWith('.css') && !mainEntryChunk.css.includes(file))
221
+ mainEntryChunk.css.push(file);
222
+ }
223
+ }
224
+ return {
225
+ entryChunkFileName,
226
+ chunksByFileName,
227
+ chunkFileNamesByRouteFilePath,
228
+ cssFilesBySourcePath,
229
+ cssContentByFileName,
230
+ };
231
+ }
232
+ function appendUniqueStrings(target, source) {
233
+ const seen = new Set(target);
234
+ let result;
235
+ for (const value of source) {
236
+ if (seen.has(value)) continue;
237
+ seen.add(value);
238
+ if (!result) result = target.slice();
239
+ result.push(value);
240
+ }
241
+ return result ?? target;
242
+ }
243
+ /**
244
+ * Registers a processAssets hook to capture the client build stats
245
+ * after compilation. Returns a getter for the captured build.
246
+ */
247
+ function registerClientBuildCapture(api) {
248
+ let clientBuild;
249
+ api.processAssets(
250
+ {
251
+ stage: 'report',
252
+ environments: [RSBUILD_ENVIRONMENT_NAMES.client],
253
+ },
254
+ (context) => {
255
+ clientBuild = normalizeRspackClientBuild(context.compilation);
256
+ },
257
+ );
258
+ return { getClientBuild: () => clientBuild };
259
+ }
260
+ //#endregion
261
+ export { registerClientBuildCapture };
@@ -0,0 +1,56 @@
1
+ import { ENTRY_POINTS } from '../constants.js';
2
+ import { EnvironmentConfig } from '@rsbuild/core';
3
+ import { ResolvedStartEntryPlan } from '../planning.js';
4
+ import { RsbuildEnvironmentOverrides } from './types.js';
5
+ import { ScriptFormat } from '@tanstack/router-core';
6
+ export declare const RSBUILD_ENVIRONMENT_NAMES: {
7
+ readonly client: 'client';
8
+ readonly server: 'ssr';
9
+ };
10
+ /**
11
+ * Rspack layer names for the rsbuild RSC layered model.
12
+ * These match the canonical names from `rspack.experiments.rsc.Layers`.
13
+ */
14
+ export declare const RSBUILD_RSC_LAYERS: {
15
+ /** React Server Components layer — uses `react-server` resolve condition */
16
+ readonly rsc: 'react-server-components';
17
+ /** Server-Side Rendering layer — standard Node resolve */
18
+ readonly ssr: 'server-side-rendering';
19
+ };
20
+ export declare const RSBUILD_CLIENT_ASSETS_DIR = 'assets';
21
+ export type RsbuildEnvironmentName =
22
+ (typeof RSBUILD_ENVIRONMENT_NAMES)[keyof typeof RSBUILD_ENVIRONMENT_NAMES];
23
+ type RsbuildDistPath = NonNullable<EnvironmentConfig['output']>['distPath'];
24
+ export interface RsbuildResolvedEntryAliases {
25
+ client: string;
26
+ server: string;
27
+ start: string;
28
+ router: string;
29
+ alias: Record<(typeof ENTRY_POINTS)[keyof typeof ENTRY_POINTS], string>;
30
+ }
31
+ export declare function createRsbuildResolvedEntryAliases(opts: {
32
+ entryPaths: ResolvedStartEntryPlan['entryPaths'];
33
+ }): RsbuildResolvedEntryAliases;
34
+ export interface RsbuildEnvironmentPlanResult {
35
+ environments: Record<string, EnvironmentConfig>;
36
+ alias: Record<string, string>;
37
+ }
38
+ export declare function createRsbuildEnvironmentPlan(opts: {
39
+ root: string;
40
+ entryAliases: RsbuildResolvedEntryAliases;
41
+ clientOutputDirectory: string;
42
+ serverOutputDirectory: string;
43
+ publicBase: string;
44
+ serverFnProviderEnv: string;
45
+ environmentOverrides?: RsbuildEnvironmentOverrides;
46
+ scriptFormat?: ScriptFormat;
47
+ rsc?: boolean | undefined;
48
+ dev?: boolean | undefined;
49
+ }): RsbuildEnvironmentPlanResult;
50
+ export declare function resolveRsbuildOutputDirectory(opts: {
51
+ distPath: RsbuildDistPath | undefined;
52
+ rootDistPath: RsbuildDistPath | undefined;
53
+ fallback: string;
54
+ subdirectory: string;
55
+ }): string;
56
+ export {};
@@ -0,0 +1,173 @@
1
+ import { ENTRY_POINTS } from '../constants.js';
2
+ import { join } from 'pathe';
3
+ import { createRequire } from 'node:module';
4
+ import { mergeRsbuildConfig } from '@rsbuild/core';
5
+ //#region src/rsbuild/planning.ts
6
+ var require = createRequire(import.meta.url);
7
+ var RSBUILD_ENVIRONMENT_NAMES = {
8
+ client: 'client',
9
+ server: 'ssr',
10
+ };
11
+ /**
12
+ * Rspack layer names for the rsbuild RSC layered model.
13
+ * These match the canonical names from `rspack.experiments.rsc.Layers`.
14
+ */
15
+ var RSBUILD_RSC_LAYERS = {
16
+ /** React Server Components layer — uses `react-server` resolve condition */
17
+ rsc: 'react-server-components',
18
+ /** Server-Side Rendering layer — standard Node resolve */
19
+ ssr: 'server-side-rendering',
20
+ };
21
+ var RSBUILD_CLIENT_ASSETS_DIR = 'assets';
22
+ function createRsbuildResolvedEntryAliases(opts) {
23
+ const client = normalizeEntryPath(opts.entryPaths.client);
24
+ const server = normalizeEntryPath(opts.entryPaths.server);
25
+ const start = normalizeEntryPath(opts.entryPaths.start);
26
+ const router = normalizeEntryPath(opts.entryPaths.router);
27
+ return {
28
+ client,
29
+ server,
30
+ start,
31
+ router,
32
+ alias: {
33
+ [ENTRY_POINTS.client]: client,
34
+ [ENTRY_POINTS.server]: server,
35
+ [ENTRY_POINTS.start]: start,
36
+ [ENTRY_POINTS.router]: router,
37
+ },
38
+ };
39
+ }
40
+ function createRsbuildEnvironmentPlan(opts) {
41
+ const alias = {
42
+ ...opts.entryAliases.alias,
43
+ ...(opts.rsc
44
+ ? {
45
+ 'react-server-dom-rspack/server$': resolveFromRoot(
46
+ 'react-server-dom-rspack/server.node',
47
+ opts.root,
48
+ ),
49
+ }
50
+ : {}),
51
+ };
52
+ const environmentOverrides = opts.environmentOverrides ?? {};
53
+ const clientOutputModule = (opts.scriptFormat ?? 'module') === 'module';
54
+ const userClientOutputModule =
55
+ environmentOverrides.client?.output?.module ?? environmentOverrides.all?.output?.module;
56
+ if (typeof userClientOutputModule === 'boolean' && userClientOutputModule !== clientOutputModule)
57
+ throw new Error(
58
+ 'TanStack Start rsbuild.client.output controls environments.client.output.module. Remove environments.client.output.module or set rsbuild.client.output to match it.',
59
+ );
60
+ return {
61
+ environments: {
62
+ [RSBUILD_ENVIRONMENT_NAMES.client]: mergeRsbuildConfig(
63
+ {
64
+ source: {
65
+ entry: {
66
+ index: {
67
+ import: opts.entryAliases.client,
68
+ html: false,
69
+ },
70
+ },
71
+ },
72
+ output: {
73
+ target: 'web',
74
+ module: clientOutputModule,
75
+ distPath: {
76
+ root: opts.clientOutputDirectory,
77
+ js: `${RSBUILD_CLIENT_ASSETS_DIR}/js`,
78
+ jsAsync: `${RSBUILD_CLIENT_ASSETS_DIR}/js/async`,
79
+ css: `${RSBUILD_CLIENT_ASSETS_DIR}/css`,
80
+ cssAsync: `${RSBUILD_CLIENT_ASSETS_DIR}/css/async`,
81
+ svg: `${RSBUILD_CLIENT_ASSETS_DIR}/svg`,
82
+ font: `${RSBUILD_CLIENT_ASSETS_DIR}/font`,
83
+ wasm: `${RSBUILD_CLIENT_ASSETS_DIR}/wasm`,
84
+ image: `${RSBUILD_CLIENT_ASSETS_DIR}/image`,
85
+ media: `${RSBUILD_CLIENT_ASSETS_DIR}/media`,
86
+ assets: `${RSBUILD_CLIENT_ASSETS_DIR}/assets`,
87
+ },
88
+ assetPrefix: opts.publicBase,
89
+ },
90
+ resolve: { alias },
91
+ performance: {
92
+ chunkSplit: {
93
+ strategy: 'custom',
94
+ override: { chunks: 'async' },
95
+ },
96
+ },
97
+ },
98
+ environmentOverrides.all,
99
+ environmentOverrides.client,
100
+ ),
101
+ [RSBUILD_ENVIRONMENT_NAMES.server]: mergeRsbuildConfig(
102
+ {
103
+ source: {
104
+ entry: {
105
+ index: {
106
+ import: opts.entryAliases.server,
107
+ html: false,
108
+ ...(opts.rsc ? { layer: RSBUILD_RSC_LAYERS.ssr } : {}),
109
+ },
110
+ },
111
+ },
112
+ output: {
113
+ target: 'node',
114
+ ...(opts.dev ? { module: false } : {}),
115
+ distPath: { root: opts.serverOutputDirectory },
116
+ },
117
+ resolve: { alias },
118
+ ...(opts.rsc ? { splitChunks: { preset: 'single-vendor' } } : {}),
119
+ },
120
+ environmentOverrides.all,
121
+ environmentOverrides.server,
122
+ ),
123
+ ...(opts.serverFnProviderEnv !== RSBUILD_ENVIRONMENT_NAMES.server && !opts.rsc
124
+ ? {
125
+ [opts.serverFnProviderEnv]: mergeRsbuildConfig(
126
+ {
127
+ source: {
128
+ entry: {
129
+ index: {
130
+ import: opts.entryAliases.server,
131
+ html: false,
132
+ },
133
+ },
134
+ },
135
+ output: {
136
+ target: 'node',
137
+ ...(opts.dev ? { module: false } : {}),
138
+ distPath: { root: `${opts.serverOutputDirectory}/${opts.serverFnProviderEnv}` },
139
+ },
140
+ resolve: { alias },
141
+ },
142
+ environmentOverrides.all,
143
+ environmentOverrides.provider,
144
+ ),
145
+ }
146
+ : {}),
147
+ },
148
+ alias,
149
+ };
150
+ }
151
+ function resolveRsbuildOutputDirectory(opts) {
152
+ if (typeof opts.distPath === 'string') return opts.distPath;
153
+ if (typeof opts.distPath?.root === 'string') return opts.distPath.root;
154
+ if (typeof opts.rootDistPath === 'string') return join(opts.rootDistPath, opts.subdirectory);
155
+ if (typeof opts.rootDistPath?.root === 'string')
156
+ return join(opts.rootDistPath.root, opts.subdirectory);
157
+ return opts.fallback;
158
+ }
159
+ function normalizeEntryPath(path) {
160
+ return path.includes('\\') ? path.replaceAll('\\', '/') : path;
161
+ }
162
+ function resolveFromRoot(specifier, root) {
163
+ return require.resolve(specifier, { paths: [root] });
164
+ }
165
+ //#endregion
166
+ export {
167
+ RSBUILD_CLIENT_ASSETS_DIR,
168
+ RSBUILD_ENVIRONMENT_NAMES,
169
+ RSBUILD_RSC_LAYERS,
170
+ createRsbuildEnvironmentPlan,
171
+ createRsbuildResolvedEntryAliases,
172
+ resolveRsbuildOutputDirectory,
173
+ };
@@ -0,0 +1,7 @@
1
+ import { TanStackStartRsbuildPluginCoreOptions } from './types.js';
2
+ import { RsbuildPlugin } from '@rsbuild/core';
3
+ import { TanStackStartRsbuildInputConfig } from './schema.js';
4
+ export declare function tanStackStartRsbuild(
5
+ corePluginOpts: TanStackStartRsbuildPluginCoreOptions,
6
+ startPluginOpts?: TanStackStartRsbuildInputConfig,
7
+ ): RsbuildPlugin;