@tanstack/router-plugin 1.159.11 → 1.159.14
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/dist/cjs/core/code-splitter/compilers.cjs +467 -0
- package/dist/cjs/core/code-splitter/compilers.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/compilers.d.cts +82 -0
- package/dist/cjs/core/constants.cjs +2 -0
- package/dist/cjs/core/constants.cjs.map +1 -1
- package/dist/cjs/core/constants.d.cts +1 -0
- package/dist/cjs/core/router-code-splitter-plugin.cjs +62 -3
- package/dist/cjs/core/router-code-splitter-plugin.cjs.map +1 -1
- package/dist/esm/core/code-splitter/compilers.d.ts +82 -0
- package/dist/esm/core/code-splitter/compilers.js +469 -2
- package/dist/esm/core/code-splitter/compilers.js.map +1 -1
- package/dist/esm/core/constants.d.ts +1 -0
- package/dist/esm/core/constants.js +2 -0
- package/dist/esm/core/constants.js.map +1 -1
- package/dist/esm/core/router-code-splitter-plugin.js +64 -5
- package/dist/esm/core/router-code-splitter-plugin.js.map +1 -1
- package/package.json +4 -4
- package/src/core/code-splitter/compilers.ts +765 -1
- package/src/core/constants.ts +1 -0
- package/src/core/router-code-splitter-plugin.ts +78 -1
package/src/core/constants.ts
CHANGED
|
@@ -8,12 +8,15 @@ import { logDiff } from '@tanstack/router-utils'
|
|
|
8
8
|
import { getConfig, splitGroupingsSchema } from './config'
|
|
9
9
|
import {
|
|
10
10
|
compileCodeSplitReferenceRoute,
|
|
11
|
+
compileCodeSplitSharedRoute,
|
|
11
12
|
compileCodeSplitVirtualRoute,
|
|
13
|
+
computeSharedBindings,
|
|
12
14
|
detectCodeSplitGroupingsFromRoute,
|
|
13
15
|
} from './code-splitter/compilers'
|
|
14
16
|
import {
|
|
15
17
|
defaultCodeSplitGroupings,
|
|
16
18
|
splitRouteIdentNodes,
|
|
19
|
+
tsrShared,
|
|
17
20
|
tsrSplit,
|
|
18
21
|
} from './constants'
|
|
19
22
|
import { decodeIdentifier } from './code-splitter/path-ids'
|
|
@@ -88,6 +91,10 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
|
|
|
88
91
|
}
|
|
89
92
|
const isProduction = process.env.NODE_ENV === 'production'
|
|
90
93
|
|
|
94
|
+
// Map from normalized route file path → set of shared binding names.
|
|
95
|
+
// Populated by the reference compiler, consumed by virtual and shared compilers.
|
|
96
|
+
const sharedBindingsMap = new Map<string, Set<string>>()
|
|
97
|
+
|
|
91
98
|
const getGlobalCodeSplitGroupings = () => {
|
|
92
99
|
return (
|
|
93
100
|
userConfig.codeSplittingOptions?.defaultBehavior ||
|
|
@@ -138,6 +145,17 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
|
|
|
138
145
|
const splitGroupings: CodeSplitGroupings =
|
|
139
146
|
fromCode.groupings || pluginSplitBehavior || getGlobalCodeSplitGroupings()
|
|
140
147
|
|
|
148
|
+
// Compute shared bindings before compiling the reference route
|
|
149
|
+
const sharedBindings = computeSharedBindings({
|
|
150
|
+
code,
|
|
151
|
+
codeSplitGroupings: splitGroupings,
|
|
152
|
+
})
|
|
153
|
+
if (sharedBindings.size > 0) {
|
|
154
|
+
sharedBindingsMap.set(id, sharedBindings)
|
|
155
|
+
} else {
|
|
156
|
+
sharedBindingsMap.delete(id)
|
|
157
|
+
}
|
|
158
|
+
|
|
141
159
|
const compiledReferenceRoute = compileCodeSplitReferenceRoute({
|
|
142
160
|
code,
|
|
143
161
|
codeSplitGroupings: splitGroupings,
|
|
@@ -149,6 +167,7 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
|
|
|
149
167
|
: undefined,
|
|
150
168
|
addHmr:
|
|
151
169
|
(userConfig.codeSplittingOptions?.addHmr ?? true) && !isProduction,
|
|
170
|
+
sharedBindings: sharedBindings.size > 0 ? sharedBindings : undefined,
|
|
152
171
|
})
|
|
153
172
|
|
|
154
173
|
if (compiledReferenceRoute === null) {
|
|
@@ -189,10 +208,14 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
|
|
|
189
208
|
splitRouteIdentNodes.includes(p as any),
|
|
190
209
|
) as Array<SplitRouteIdentNodes>
|
|
191
210
|
|
|
211
|
+
const baseId = id.split('?')[0]!
|
|
212
|
+
const resolvedSharedBindings = sharedBindingsMap.get(baseId)
|
|
213
|
+
|
|
192
214
|
const result = compileCodeSplitVirtualRoute({
|
|
193
215
|
code,
|
|
194
216
|
filename: id,
|
|
195
217
|
splitTargets: grouping,
|
|
218
|
+
sharedBindings: resolvedSharedBindings,
|
|
196
219
|
})
|
|
197
220
|
|
|
198
221
|
if (debug) {
|
|
@@ -216,7 +239,7 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
|
|
|
216
239
|
transform: {
|
|
217
240
|
filter: {
|
|
218
241
|
id: {
|
|
219
|
-
exclude: tsrSplit,
|
|
242
|
+
exclude: [tsrSplit, tsrShared],
|
|
220
243
|
// this is necessary for webpack / rspack to avoid matching .html files
|
|
221
244
|
include: /\.(m|c)?(j|t)sx?$/,
|
|
222
245
|
},
|
|
@@ -325,6 +348,60 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
|
|
|
325
348
|
return handleCompilingVirtualFile(code, normalizedId)
|
|
326
349
|
},
|
|
327
350
|
},
|
|
351
|
+
|
|
352
|
+
vite: {
|
|
353
|
+
applyToEnvironment(environment) {
|
|
354
|
+
if (userConfig.plugin?.vite?.environmentName) {
|
|
355
|
+
return userConfig.plugin.vite.environmentName === environment.name
|
|
356
|
+
}
|
|
357
|
+
return true
|
|
358
|
+
},
|
|
359
|
+
},
|
|
360
|
+
},
|
|
361
|
+
{
|
|
362
|
+
name: 'tanstack-router:code-splitter:compile-shared-file',
|
|
363
|
+
enforce: 'pre',
|
|
364
|
+
|
|
365
|
+
transform: {
|
|
366
|
+
filter: {
|
|
367
|
+
id: /tsr-shared/,
|
|
368
|
+
},
|
|
369
|
+
handler(code, id) {
|
|
370
|
+
const url = pathToFileURL(id)
|
|
371
|
+
url.searchParams.delete('v')
|
|
372
|
+
const normalizedId = normalizePath(fileURLToPath(url))
|
|
373
|
+
const [baseId] = normalizedId.split('?')
|
|
374
|
+
|
|
375
|
+
if (!baseId) return null
|
|
376
|
+
|
|
377
|
+
const sharedBindings = sharedBindingsMap.get(baseId)
|
|
378
|
+
if (!sharedBindings || sharedBindings.size === 0) return null
|
|
379
|
+
|
|
380
|
+
if (debug) console.info('Compiling Shared Module: ', id)
|
|
381
|
+
|
|
382
|
+
const result = compileCodeSplitSharedRoute({
|
|
383
|
+
code,
|
|
384
|
+
sharedBindings,
|
|
385
|
+
filename: normalizedId,
|
|
386
|
+
})
|
|
387
|
+
|
|
388
|
+
if (debug) {
|
|
389
|
+
logDiff(code, result.code)
|
|
390
|
+
console.log('Output:\n', result.code + '\n\n')
|
|
391
|
+
}
|
|
392
|
+
|
|
393
|
+
return result
|
|
394
|
+
},
|
|
395
|
+
},
|
|
396
|
+
|
|
397
|
+
vite: {
|
|
398
|
+
applyToEnvironment(environment) {
|
|
399
|
+
if (userConfig.plugin?.vite?.environmentName) {
|
|
400
|
+
return userConfig.plugin.vite.environmentName === environment.name
|
|
401
|
+
}
|
|
402
|
+
return true
|
|
403
|
+
},
|
|
404
|
+
},
|
|
328
405
|
},
|
|
329
406
|
]
|
|
330
407
|
}
|