@tanstack/router-plugin 1.168.22 → 1.168.23
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 +39 -32
- package/dist/cjs/core/code-splitter/compilers.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/compilers.d.cts +3 -2
- package/dist/cjs/core/code-splitter/plugins/framework-plugins.cjs +10 -12
- package/dist/cjs/core/code-splitter/plugins/framework-plugins.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/plugins/framework-plugins.d.cts +3 -4
- package/dist/cjs/core/code-splitter/plugins/react-refresh-route-components.cjs +34 -16
- package/dist/cjs/core/code-splitter/plugins/react-refresh-route-components.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/plugins.d.cts +8 -1
- package/dist/cjs/core/config.cjs.map +1 -1
- package/dist/cjs/core/router-code-splitter-plugin.cjs +20 -11
- package/dist/cjs/core/router-code-splitter-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-hmr-plugin.cjs +1 -2
- package/dist/cjs/core/router-hmr-plugin.cjs.map +1 -1
- package/dist/cjs/index.d.cts +1 -1
- package/dist/esm/core/code-splitter/compilers.d.ts +3 -2
- package/dist/esm/core/code-splitter/compilers.js +39 -32
- package/dist/esm/core/code-splitter/compilers.js.map +1 -1
- package/dist/esm/core/code-splitter/plugins/framework-plugins.d.ts +3 -4
- package/dist/esm/core/code-splitter/plugins/framework-plugins.js +10 -12
- package/dist/esm/core/code-splitter/plugins/framework-plugins.js.map +1 -1
- package/dist/esm/core/code-splitter/plugins/react-refresh-route-components.js +34 -16
- package/dist/esm/core/code-splitter/plugins/react-refresh-route-components.js.map +1 -1
- package/dist/esm/core/code-splitter/plugins.d.ts +8 -1
- package/dist/esm/core/config.js.map +1 -1
- package/dist/esm/core/router-code-splitter-plugin.js +21 -12
- package/dist/esm/core/router-code-splitter-plugin.js.map +1 -1
- package/dist/esm/core/router-hmr-plugin.js +2 -3
- package/dist/esm/core/router-hmr-plugin.js.map +1 -1
- package/dist/esm/index.d.ts +1 -1
- package/package.json +3 -3
- package/src/core/code-splitter/compilers.ts +12 -2
- package/src/core/code-splitter/plugins/framework-plugins.ts +11 -15
- package/src/core/code-splitter/plugins/react-refresh-route-components.ts +75 -25
- package/src/core/code-splitter/plugins.ts +12 -1
- package/src/core/config.ts +2 -2
- package/src/core/router-code-splitter-plugin.ts +31 -17
- package/src/core/router-hmr-plugin.ts +2 -3
- package/src/index.ts +2 -0
|
@@ -13,7 +13,7 @@ import {
|
|
|
13
13
|
computeSharedBindings,
|
|
14
14
|
detectCodeSplitGroupingsFromRoute,
|
|
15
15
|
} from './code-splitter/compilers'
|
|
16
|
-
import {
|
|
16
|
+
import { getFrameworkHmrCompilerPlugins } from './code-splitter/plugins/framework-plugins'
|
|
17
17
|
import {
|
|
18
18
|
defaultCodeSplitGroupings,
|
|
19
19
|
splitRouteIdentNodes,
|
|
@@ -24,7 +24,8 @@ import { debug, normalizePath, routeFactoryCallCodeFilter } from './utils'
|
|
|
24
24
|
import { createRouterPluginContext } from './router-plugin-context'
|
|
25
25
|
import type { CodeSplitGroupings, SplitRouteIdentNodes } from './constants'
|
|
26
26
|
import type { GetRoutesByFileMapResultValue } from '@tanstack/router-generator'
|
|
27
|
-
import type {
|
|
27
|
+
import type { CodeSplitCompilerPlugin } from './code-splitter/plugins'
|
|
28
|
+
import type { Config, HmrStyle } from './config'
|
|
28
29
|
import type { RouterPluginContext } from './router-plugin-context'
|
|
29
30
|
import type {
|
|
30
31
|
UnpluginFactory,
|
|
@@ -83,6 +84,12 @@ export function createRouterCodeSplitterPlugin(
|
|
|
83
84
|
): ReturnType<UnpluginFactory<Partial<Config | (() => Config)> | undefined>> {
|
|
84
85
|
let ROOT: string = process.cwd()
|
|
85
86
|
let userConfig: Config
|
|
87
|
+
let addHmr: boolean
|
|
88
|
+
let hmrStyle: HmrStyle
|
|
89
|
+
let compilerPlugins: Array<CodeSplitCompilerPlugin>
|
|
90
|
+
let virtualRouteCompilerPlugins: Array<CodeSplitCompilerPlugin>
|
|
91
|
+
|
|
92
|
+
let isProduction = process.env.NODE_ENV === 'production'
|
|
86
93
|
|
|
87
94
|
function initUserConfig() {
|
|
88
95
|
if (typeof options === 'function') {
|
|
@@ -90,8 +97,22 @@ export function createRouterCodeSplitterPlugin(
|
|
|
90
97
|
} else {
|
|
91
98
|
userConfig = getConfig(options, ROOT)
|
|
92
99
|
}
|
|
100
|
+
|
|
101
|
+
addHmr = (userConfig.codeSplittingOptions?.addHmr ?? true) && !isProduction
|
|
102
|
+
hmrStyle = userConfig.plugin?.hmr?.style ?? 'vite'
|
|
103
|
+
compilerPlugins = [
|
|
104
|
+
...(addHmr
|
|
105
|
+
? (getFrameworkHmrCompilerPlugins({
|
|
106
|
+
targetFramework: userConfig.target,
|
|
107
|
+
hmrStyle,
|
|
108
|
+
}) ?? [])
|
|
109
|
+
: []),
|
|
110
|
+
...(userConfig.codeSplittingOptions?.compilerPlugins ?? []),
|
|
111
|
+
]
|
|
112
|
+
virtualRouteCompilerPlugins = compilerPlugins.filter(
|
|
113
|
+
(plugin) => plugin.onVirtualRouteSplitNode,
|
|
114
|
+
)
|
|
93
115
|
}
|
|
94
|
-
const isProduction = process.env.NODE_ENV === 'production'
|
|
95
116
|
// Map from normalized route file path → set of shared binding names.
|
|
96
117
|
// Populated by the reference compiler, consumed by virtual and shared compilers.
|
|
97
118
|
const sharedBindingsMap = new Map<string, Set<string>>()
|
|
@@ -159,10 +180,6 @@ export function createRouterCodeSplitterPlugin(
|
|
|
159
180
|
sharedBindingsMap.delete(id)
|
|
160
181
|
}
|
|
161
182
|
|
|
162
|
-
const addHmr =
|
|
163
|
-
(userConfig.codeSplittingOptions?.addHmr ?? true) && !isProduction
|
|
164
|
-
const hmrStyle = userConfig.plugin?.hmr?.style ?? 'vite'
|
|
165
|
-
|
|
166
183
|
const compiledReferenceRoute = compileCodeSplitReferenceRoute({
|
|
167
184
|
code,
|
|
168
185
|
codeSplitGroupings: splitGroupings,
|
|
@@ -176,14 +193,7 @@ export function createRouterCodeSplitterPlugin(
|
|
|
176
193
|
hmrStyle,
|
|
177
194
|
hmrRouteId: generatorNodeInfo.routeId,
|
|
178
195
|
sharedBindings: sharedBindings.size > 0 ? sharedBindings : undefined,
|
|
179
|
-
compilerPlugins
|
|
180
|
-
...(getReferenceRouteCompilerPlugins({
|
|
181
|
-
targetFramework: userConfig.target,
|
|
182
|
-
addHmr,
|
|
183
|
-
hmrStyle,
|
|
184
|
-
}) ?? []),
|
|
185
|
-
...(userConfig.codeSplittingOptions?.compilerPlugins ?? []),
|
|
186
|
-
],
|
|
196
|
+
compilerPlugins,
|
|
187
197
|
})
|
|
188
198
|
|
|
189
199
|
if (compiledReferenceRoute === null) {
|
|
@@ -232,6 +242,7 @@ export function createRouterCodeSplitterPlugin(
|
|
|
232
242
|
filename: id,
|
|
233
243
|
splitTargets: grouping,
|
|
234
244
|
sharedBindings: resolvedSharedBindings,
|
|
245
|
+
compilerPlugins: virtualRouteCompilerPlugins,
|
|
235
246
|
})
|
|
236
247
|
|
|
237
248
|
if (debug) {
|
|
@@ -276,6 +287,7 @@ export function createRouterCodeSplitterPlugin(
|
|
|
276
287
|
|
|
277
288
|
vite: {
|
|
278
289
|
configResolved(config) {
|
|
290
|
+
isProduction = config.command === 'build'
|
|
279
291
|
ROOT = config.root
|
|
280
292
|
initUserConfig()
|
|
281
293
|
|
|
@@ -319,12 +331,14 @@ export function createRouterCodeSplitterPlugin(
|
|
|
319
331
|
},
|
|
320
332
|
},
|
|
321
333
|
|
|
322
|
-
rspack() {
|
|
334
|
+
rspack(compiler) {
|
|
335
|
+
isProduction = compiler.options.mode === 'production'
|
|
323
336
|
ROOT = process.cwd()
|
|
324
337
|
initUserConfig()
|
|
325
338
|
},
|
|
326
339
|
|
|
327
|
-
webpack() {
|
|
340
|
+
webpack(compiler) {
|
|
341
|
+
isProduction = compiler.options.mode === 'production'
|
|
328
342
|
ROOT = process.cwd()
|
|
329
343
|
initUserConfig()
|
|
330
344
|
},
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { generateFromAst, logDiff, parseAst } from '@tanstack/router-utils'
|
|
2
2
|
import { compileCodeSplitReferenceRoute } from './code-splitter/compilers'
|
|
3
|
-
import {
|
|
3
|
+
import { getFrameworkHmrCompilerPlugins } from './code-splitter/plugins/framework-plugins'
|
|
4
4
|
import { createRouteHmrStatement } from './hmr'
|
|
5
5
|
import { debug, normalizePath, routeFactoryCallCodeFilter } from './utils'
|
|
6
6
|
import { getConfig } from './config'
|
|
@@ -50,9 +50,8 @@ export function createRouterHmrPlugin(
|
|
|
50
50
|
const hmrStyle = userConfig.plugin?.hmr?.style ?? 'vite'
|
|
51
51
|
|
|
52
52
|
if (userConfig.target === 'react') {
|
|
53
|
-
const compilerPlugins =
|
|
53
|
+
const compilerPlugins = getFrameworkHmrCompilerPlugins({
|
|
54
54
|
targetFramework: 'react',
|
|
55
|
-
addHmr: true,
|
|
56
55
|
hmrStyle,
|
|
57
56
|
})
|
|
58
57
|
const compiled = compileCodeSplitReferenceRoute({
|
package/src/index.ts
CHANGED
|
@@ -13,8 +13,10 @@ export type {
|
|
|
13
13
|
export type { RouterPluginContext } from './core/router-plugin-context'
|
|
14
14
|
export { getObjectPropertyKeyName } from './core/utils'
|
|
15
15
|
export type {
|
|
16
|
+
CodeSplitCompilerPlugin,
|
|
16
17
|
ReferenceRouteCompilerPlugin,
|
|
17
18
|
ReferenceRouteCompilerPluginContext,
|
|
19
|
+
VirtualRouteSplitNodeCompilerPluginContext,
|
|
18
20
|
} from './core/code-splitter/plugins'
|
|
19
21
|
export {
|
|
20
22
|
tsrSplit,
|