@tanstack/router-plugin 1.121.0-alpha.26 → 1.121.0-alpha.28

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 (77) hide show
  1. package/dist/cjs/core/code-splitter/compilers.cjs +66 -40
  2. package/dist/cjs/core/code-splitter/compilers.cjs.map +1 -1
  3. package/dist/cjs/core/code-splitter/compilers.d.cts +3 -3
  4. package/dist/cjs/core/code-splitter/framework-options.cjs.map +1 -1
  5. package/dist/cjs/core/code-splitter/path-ids.cjs.map +1 -1
  6. package/dist/cjs/core/config.cjs +11 -1
  7. package/dist/cjs/core/config.cjs.map +1 -1
  8. package/dist/cjs/core/config.d.cts +49 -4
  9. package/dist/cjs/core/route-autoimport-plugin.cjs +52 -45
  10. package/dist/cjs/core/route-autoimport-plugin.cjs.map +1 -1
  11. package/dist/cjs/core/route-hmr-statement.cjs.map +1 -1
  12. package/dist/cjs/core/router-code-splitter-plugin.cjs +84 -64
  13. package/dist/cjs/core/router-code-splitter-plugin.cjs.map +1 -1
  14. package/dist/cjs/core/router-composed-plugin.cjs +12 -3
  15. package/dist/cjs/core/router-composed-plugin.cjs.map +1 -1
  16. package/dist/cjs/core/router-generator-plugin.cjs +27 -25
  17. package/dist/cjs/core/router-generator-plugin.cjs.map +1 -1
  18. package/dist/cjs/core/router-hmr-plugin.cjs +38 -29
  19. package/dist/cjs/core/router-hmr-plugin.cjs.map +1 -1
  20. package/dist/cjs/core/router-hmr-plugin.d.cts +1 -6
  21. package/dist/cjs/core/utils.cjs +0 -7
  22. package/dist/cjs/core/utils.cjs.map +1 -1
  23. package/dist/cjs/core/utils.d.cts +0 -1
  24. package/dist/cjs/esbuild.cjs.map +1 -1
  25. package/dist/cjs/esbuild.d.cts +20 -0
  26. package/dist/cjs/index.cjs +4 -0
  27. package/dist/cjs/index.cjs.map +1 -1
  28. package/dist/cjs/index.d.cts +1 -0
  29. package/dist/cjs/rspack.cjs.map +1 -1
  30. package/dist/cjs/rspack.d.cts +20 -0
  31. package/dist/cjs/vite.cjs.map +1 -1
  32. package/dist/cjs/vite.d.cts +25 -0
  33. package/dist/cjs/webpack.cjs.map +1 -1
  34. package/dist/cjs/webpack.d.cts +20 -0
  35. package/dist/esm/core/code-splitter/compilers.d.ts +3 -3
  36. package/dist/esm/core/code-splitter/compilers.js +66 -40
  37. package/dist/esm/core/code-splitter/compilers.js.map +1 -1
  38. package/dist/esm/core/code-splitter/framework-options.js.map +1 -1
  39. package/dist/esm/core/code-splitter/path-ids.js.map +1 -1
  40. package/dist/esm/core/config.d.ts +49 -4
  41. package/dist/esm/core/config.js +11 -1
  42. package/dist/esm/core/config.js.map +1 -1
  43. package/dist/esm/core/route-autoimport-plugin.js +53 -46
  44. package/dist/esm/core/route-autoimport-plugin.js.map +1 -1
  45. package/dist/esm/core/route-hmr-statement.js.map +1 -1
  46. package/dist/esm/core/router-code-splitter-plugin.js +86 -66
  47. package/dist/esm/core/router-code-splitter-plugin.js.map +1 -1
  48. package/dist/esm/core/router-composed-plugin.js +11 -2
  49. package/dist/esm/core/router-composed-plugin.js.map +1 -1
  50. package/dist/esm/core/router-generator-plugin.js +28 -26
  51. package/dist/esm/core/router-generator-plugin.js.map +1 -1
  52. package/dist/esm/core/router-hmr-plugin.d.ts +1 -6
  53. package/dist/esm/core/router-hmr-plugin.js +39 -30
  54. package/dist/esm/core/router-hmr-plugin.js.map +1 -1
  55. package/dist/esm/core/utils.d.ts +0 -1
  56. package/dist/esm/core/utils.js +1 -8
  57. package/dist/esm/core/utils.js.map +1 -1
  58. package/dist/esm/esbuild.d.ts +20 -0
  59. package/dist/esm/esbuild.js.map +1 -1
  60. package/dist/esm/index.d.ts +1 -0
  61. package/dist/esm/index.js +4 -0
  62. package/dist/esm/index.js.map +1 -1
  63. package/dist/esm/rspack.d.ts +20 -0
  64. package/dist/esm/vite.d.ts +25 -0
  65. package/dist/esm/vite.js.map +1 -1
  66. package/dist/esm/webpack.d.ts +20 -0
  67. package/package.json +15 -15
  68. package/src/core/code-splitter/compilers.ts +95 -60
  69. package/src/core/config.ts +25 -0
  70. package/src/core/route-autoimport-plugin.ts +59 -53
  71. package/src/core/router-code-splitter-plugin.ts +95 -80
  72. package/src/core/router-composed-plugin.ts +12 -2
  73. package/src/core/router-generator-plugin.ts +32 -32
  74. package/src/core/router-hmr-plugin.ts +42 -37
  75. package/src/core/utils.ts +0 -15
  76. package/src/global.d.ts +7 -0
  77. package/src/index.ts +5 -0
@@ -17,9 +17,9 @@ import {
17
17
  tsrSplit,
18
18
  } from './constants'
19
19
  import { decodeIdentifier } from './code-splitter/path-ids'
20
- import { debug, fileIsInRoutesDirectory } from './utils'
20
+ import { debug } from './utils'
21
21
  import type { CodeSplitGroupings, SplitRouteIdentNodes } from './constants'
22
-
22
+ import type { GetRoutesByFileMapResultValue } from '@tanstack/router-generator'
23
23
  import type { Config } from './config'
24
24
  import type {
25
25
  UnpluginContextMeta,
@@ -27,10 +27,6 @@ import type {
27
27
  TransformResult as UnpluginTransformResult,
28
28
  } from 'unplugin'
29
29
 
30
- function capitalizeFirst(str: string): string {
31
- return str.charAt(0).toUpperCase() + str.slice(1)
32
- }
33
-
34
30
  type BannedBeforeExternalPlugin = {
35
31
  identifier: string
36
32
  pkg: string
@@ -48,11 +44,14 @@ const bannedBeforeExternalPlugins: Array<BannedBeforeExternalPlugin> = [
48
44
  ]
49
45
 
50
46
  class FoundPluginInBeforeCode extends Error {
51
- constructor(externalPlugin: BannedBeforeExternalPlugin, framework: string) {
52
- super(`We detected that the '${externalPlugin.pkg}' was passed before '@tanstack/router-plugin'. Please make sure that '@tanstack/router-plugin' is passed before '${externalPlugin.pkg}' and try again:
47
+ constructor(
48
+ externalPlugin: BannedBeforeExternalPlugin,
49
+ pluginFramework: string,
50
+ ) {
51
+ super(`We detected that the '${externalPlugin.pkg}' was passed before '@tanstack/router-plugin/${pluginFramework}'. Please make sure that '@tanstack/router-plugin' is passed before '${externalPlugin.pkg}' and try again:
53
52
  e.g.
54
53
  plugins: [
55
- TanStackRouter${capitalizeFirst(framework)}(), // Place this before ${externalPlugin.usage}
54
+ tanstackRouter(), // Place this before ${externalPlugin.usage}
56
55
  ${externalPlugin.usage},
57
56
  ]
58
57
  `)
@@ -82,6 +81,7 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
82
81
  const handleCompilingReferenceFile = (
83
82
  code: string,
84
83
  id: string,
84
+ generatorNodeInfo: GetRoutesByFileMapResultValue,
85
85
  ): UnpluginTransformResult => {
86
86
  if (debug) console.info('Compiling Route: ', id)
87
87
 
@@ -102,7 +102,7 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
102
102
  const userShouldSplitFn = getShouldSplitFn()
103
103
 
104
104
  const pluginSplitBehavior = userShouldSplitFn?.({
105
- routeId: fromCode.routeId,
105
+ routeId: generatorNodeInfo.routePath,
106
106
  }) as CodeSplitGroupings | undefined
107
107
 
108
108
  if (pluginSplitBehavior) {
@@ -120,11 +120,12 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
120
120
 
121
121
  const compiledReferenceRoute = compileCodeSplitReferenceRoute({
122
122
  code,
123
- runtimeEnv: isProduction ? 'prod' : 'dev',
124
123
  codeSplitGroupings: splitGroupings,
125
124
  targetFramework: userConfig.target,
126
125
  filename: id,
127
126
  id,
127
+ deleteNodes: new Set(userConfig.codeSplittingOptions?.deleteNodes),
128
+ addHmr: (options.codeSplittingOptions?.addHmr ?? true) && !isProduction,
128
129
  })
129
130
 
130
131
  if (debug) {
@@ -171,83 +172,97 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
171
172
  return result
172
173
  }
173
174
 
174
- return {
175
- name: 'router-code-splitter-plugin',
176
- enforce: 'pre',
177
-
178
- transform(code, id) {
179
- if (!userConfig.autoCodeSplitting) {
180
- return null
181
- }
182
-
183
- const url = pathToFileURL(id)
184
- url.searchParams.delete('v')
185
- id = fileURLToPath(url).replace(/\\/g, '/')
186
-
187
- if (id.includes(tsrSplit)) {
188
- return handleCompilingVirtualFile(code, id)
189
- } else if (
190
- fileIsInRoutesDirectory(id, userConfig.routesDirectory) &&
191
- (code.includes('createRoute(') || code.includes('createFileRoute('))
192
- ) {
193
- for (const externalPlugin of bannedBeforeExternalPlugins) {
194
- if (!externalPlugin.frameworks.includes(framework)) {
195
- continue
196
- }
197
-
198
- if (code.includes(externalPlugin.identifier)) {
199
- throw new FoundPluginInBeforeCode(externalPlugin, framework)
175
+ const includedCode = [
176
+ 'createFileRoute(',
177
+ 'createRootRoute(',
178
+ 'createRootRouteWithContext(',
179
+ ]
180
+ return [
181
+ {
182
+ name: 'tanstack-router:code-splitter:compile-reference-file',
183
+ enforce: 'pre',
184
+
185
+ transform: {
186
+ filter: {
187
+ id: {
188
+ exclude: tsrSplit,
189
+ // this is necessary for webpack / rspack to avoid matching .html files
190
+ include: /\.(m|c)?(j|t)sx?$/,
191
+ },
192
+ code: {
193
+ include: includedCode,
194
+ },
195
+ },
196
+ handler(code, id) {
197
+ const generatorFileInfo = globalThis.TSR_ROUTES_BY_ID_MAP?.get(id)
198
+ if (
199
+ generatorFileInfo &&
200
+ includedCode.some((included) => code.includes(included))
201
+ ) {
202
+ for (const externalPlugin of bannedBeforeExternalPlugins) {
203
+ if (!externalPlugin.frameworks.includes(framework)) {
204
+ continue
205
+ }
206
+
207
+ if (code.includes(externalPlugin.identifier)) {
208
+ throw new FoundPluginInBeforeCode(externalPlugin, framework)
209
+ }
210
+ }
211
+
212
+ return handleCompilingReferenceFile(code, id, generatorFileInfo)
200
213
  }
201
- }
202
-
203
- return handleCompilingReferenceFile(code, id)
204
- }
205
-
206
- return null
207
- },
208
-
209
- transformInclude(id) {
210
- if (!userConfig.autoCodeSplitting) {
211
- return undefined
212
- }
213
214
 
214
- if (
215
- fileIsInRoutesDirectory(id, userConfig.routesDirectory) ||
216
- id.includes(tsrSplit)
217
- ) {
218
- return true
219
- }
220
- return false
221
- },
215
+ return null
216
+ },
217
+ },
222
218
 
223
- vite: {
224
- configResolved(config) {
225
- ROOT = config.root
219
+ vite: {
220
+ configResolved(config) {
221
+ ROOT = config.root
222
+ userConfig = getConfig(options, ROOT)
223
+ },
224
+ applyToEnvironment(environment) {
225
+ if (userConfig.plugin?.vite?.environmentName) {
226
+ return userConfig.plugin.vite.environmentName === environment.name
227
+ }
228
+ return true
229
+ },
230
+ },
226
231
 
232
+ rspack() {
233
+ ROOT = process.cwd()
227
234
  userConfig = getConfig(options, ROOT)
228
235
  },
229
- },
230
236
 
231
- rspack(_compiler) {
232
- ROOT = process.cwd()
233
- userConfig = getConfig(options, ROOT)
234
- },
237
+ webpack(compiler) {
238
+ ROOT = process.cwd()
239
+ userConfig = getConfig(options, ROOT)
235
240
 
236
- webpack(compiler) {
237
- ROOT = process.cwd()
238
- userConfig = getConfig(options, ROOT)
239
-
240
- if (
241
- userConfig.autoCodeSplitting &&
242
- compiler.options.mode === 'production'
243
- ) {
244
- compiler.hooks.done.tap(PLUGIN_NAME, () => {
245
- console.info('✅ ' + PLUGIN_NAME + ': code-splitting done!')
246
- setTimeout(() => {
247
- process.exit(0)
241
+ if (compiler.options.mode === 'production') {
242
+ compiler.hooks.done.tap(PLUGIN_NAME, () => {
243
+ console.info('✅ ' + PLUGIN_NAME + ': code-splitting done!')
244
+ setTimeout(() => {
245
+ process.exit(0)
246
+ })
248
247
  })
249
- })
250
- }
248
+ }
249
+ },
251
250
  },
252
- }
251
+ {
252
+ name: 'tanstack-router:code-splitter:compile-virtual-file',
253
+ enforce: 'pre',
254
+
255
+ transform: {
256
+ filter: {
257
+ id: /tsr-split/,
258
+ },
259
+ handler(code, id) {
260
+ const url = pathToFileURL(id)
261
+ url.searchParams.delete('v')
262
+ id = fileURLToPath(url).replace(/\\/g, '/')
263
+ return handleCompilingVirtualFile(code, id)
264
+ },
265
+ },
266
+ },
267
+ ]
253
268
  }
@@ -1,3 +1,4 @@
1
+ import { getConfig } from '@tanstack/router-generator'
1
2
  import { unpluginRouterGeneratorFactory } from './router-generator-plugin'
2
3
  import { unpluginRouterCodeSplitterFactory } from './router-code-splitter-plugin'
3
4
  import { unpluginRouterHmrFactory } from './router-hmr-plugin'
@@ -8,6 +9,9 @@ import type { UnpluginFactory } from 'unplugin'
8
9
  export const unpluginRouterComposedFactory: UnpluginFactory<
9
10
  Partial<Config> | undefined
10
11
  > = (options = {}, meta) => {
12
+ const ROOT: string = process.cwd()
13
+ const userConfig = getConfig(options, ROOT)
14
+
11
15
  const getPlugin = (pluginFactory: UnpluginFactory<Partial<Config>>) => {
12
16
  const plugin = pluginFactory(options, meta)
13
17
  if (!Array.isArray(plugin)) {
@@ -20,11 +24,17 @@ export const unpluginRouterComposedFactory: UnpluginFactory<
20
24
  const routerCodeSplitter = getPlugin(unpluginRouterCodeSplitterFactory)
21
25
  const routeAutoImport = getPlugin(unpluginRouteAutoImportFactory)
22
26
 
23
- const result = [...routerGenerator, ...routerCodeSplitter, ...routeAutoImport]
27
+ const result = [...routerGenerator]
28
+ if (userConfig.autoCodeSplitting) {
29
+ result.push(...routerCodeSplitter)
30
+ }
31
+ if (userConfig.verboseFileRoutes === false) {
32
+ result.push(...routeAutoImport)
33
+ }
24
34
 
25
35
  const isProduction = process.env.NODE_ENV === 'production'
26
36
 
27
- if (!isProduction && !options.autoCodeSplitting) {
37
+ if (!isProduction && !userConfig.autoCodeSplitting) {
28
38
  const routerHmr = getPlugin(unpluginRouterHmrFactory)
29
39
  result.push(...routerHmr)
30
40
  }
@@ -1,7 +1,8 @@
1
1
  import { isAbsolute, join, normalize } from 'node:path'
2
2
  import { Generator, resolveConfigPath } from '@tanstack/router-generator'
3
-
4
3
  import { getConfig } from './config'
4
+
5
+ import type { GeneratorEvent } from '@tanstack/router-generator'
5
6
  import type { FSWatcher } from 'chokidar'
6
7
  import type { UnpluginFactory } from 'unplugin'
7
8
  import type { Config } from './config'
@@ -31,41 +32,39 @@ export const unpluginRouterGeneratorFactory: UnpluginFactory<
31
32
  })
32
33
  }
33
34
 
34
- const generate = async () => {
35
+ const generate = async (opts?: {
36
+ file: string
37
+ event: 'create' | 'update' | 'delete'
38
+ }) => {
35
39
  if (routeGenerationDisabled()) {
36
40
  return
37
41
  }
38
- try {
39
- await generator.run()
40
- } catch (e) {
41
- console.error(e)
42
+ let generatorEvent: GeneratorEvent | undefined = undefined
43
+ if (opts) {
44
+ const filePath = normalize(opts.file)
45
+ if (filePath === resolveConfigPath({ configDirectory: ROOT })) {
46
+ initConfigAndGenerator()
47
+ return
48
+ }
49
+ generatorEvent = { path: filePath, type: opts.event }
42
50
  }
43
- }
44
51
 
45
- const handleFile = async (
46
- file: string,
47
- event: 'create' | 'update' | 'delete',
48
- ) => {
49
- const filePath = normalize(file)
50
-
51
- if (filePath === resolveConfigPath({ configDirectory: ROOT })) {
52
- initConfigAndGenerator()
53
- return
54
- }
55
52
  try {
56
- await generator.run({ path: filePath, type: event })
53
+ await generator.run(generatorEvent)
54
+ globalThis.TSR_ROUTES_BY_ID_MAP = generator.getRoutesByFileMap()
57
55
  } catch (e) {
58
56
  console.error(e)
59
57
  }
60
58
  }
61
59
 
62
60
  return {
63
- name: 'router-generator-plugin',
61
+ name: 'tanstack:router-generator',
64
62
  enforce: 'pre',
65
63
  async watchChange(id, { event }) {
66
- if (!routeGenerationDisabled()) {
67
- await handleFile(id, event)
68
- }
64
+ await generate({
65
+ file: id,
66
+ event,
67
+ })
69
68
  },
70
69
  async buildStart() {
71
70
  await generate()
@@ -74,12 +73,13 @@ export const unpluginRouterGeneratorFactory: UnpluginFactory<
74
73
  configResolved() {
75
74
  initConfigAndGenerator()
76
75
  },
77
- async buildStart() {
78
- if (this.environment.config.consumer === 'server') {
79
- // When building in environment mode, we only need to generate routes
80
- // for the client environment
81
- return
76
+ applyToEnvironment(environment) {
77
+ if (userConfig.plugin?.vite?.environmentName) {
78
+ return userConfig.plugin.vite.environmentName === environment.name
82
79
  }
80
+ return true
81
+ },
82
+ async buildStart() {
83
83
  await generate()
84
84
  },
85
85
  sharedDuringBuild: true,
@@ -89,7 +89,7 @@ export const unpluginRouterGeneratorFactory: UnpluginFactory<
89
89
 
90
90
  let handle: FSWatcher | null = null
91
91
 
92
- compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, generate)
92
+ compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, () => generate())
93
93
 
94
94
  compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {
95
95
  if (handle) {
@@ -101,7 +101,7 @@ export const unpluginRouterGeneratorFactory: UnpluginFactory<
101
101
  const chokidar = await import('chokidar')
102
102
  handle = chokidar
103
103
  .watch(routesDirectoryPath, { ignoreInitial: true })
104
- .on('add', generate)
104
+ .on('add', (file) => generate({ file, event: 'create' }))
105
105
 
106
106
  await generate()
107
107
  })
@@ -113,11 +113,11 @@ export const unpluginRouterGeneratorFactory: UnpluginFactory<
113
113
  })
114
114
  },
115
115
  webpack(compiler) {
116
- userConfig = getConfig(options, ROOT)
116
+ initConfigAndGenerator()
117
117
 
118
118
  let handle: FSWatcher | null = null
119
119
 
120
- compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, generate)
120
+ compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, () => generate())
121
121
 
122
122
  compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {
123
123
  if (handle) {
@@ -129,7 +129,7 @@ export const unpluginRouterGeneratorFactory: UnpluginFactory<
129
129
  const chokidar = await import('chokidar')
130
130
  handle = chokidar
131
131
  .watch(routesDirectoryPath, { ignoreInitial: true })
132
- .on('add', generate)
132
+ .on('add', (file) => generate({ file, event: 'create' }))
133
133
 
134
134
  await generate()
135
135
  })
@@ -1,15 +1,21 @@
1
1
  import { generateFromAst, logDiff, parseAst } from '@tanstack/router-utils'
2
- import { getConfig } from './config'
3
2
  import { routeHmrStatement } from './route-hmr-statement'
4
- import { debug, fileIsInRoutesDirectory } from './utils'
5
- import type { Config } from './config'
3
+ import { debug } from './utils'
4
+ import { getConfig } from './config'
6
5
  import type { UnpluginFactory } from 'unplugin'
6
+ import type { Config } from './config'
7
7
 
8
8
  /**
9
9
  * This plugin adds HMR support for file routes.
10
10
  * It is only added to the composed plugin in dev when autoCodeSplitting is disabled, since the code splitting plugin
11
11
  * handles HMR for code-split routes itself.
12
12
  */
13
+
14
+ const includeCode = [
15
+ 'createFileRoute(',
16
+ 'createRootRoute(',
17
+ 'createRootRouteWithContext(',
18
+ ]
13
19
  export const unpluginRouterHmrFactory: UnpluginFactory<
14
20
  Partial<Config> | undefined
15
21
  > = (options = {}) => {
@@ -17,49 +23,48 @@ export const unpluginRouterHmrFactory: UnpluginFactory<
17
23
  let userConfig = options as Config
18
24
 
19
25
  return {
20
- name: 'router-hmr-plugin',
26
+ name: 'tanstack-router:hmr',
21
27
  enforce: 'pre',
28
+ transform: {
29
+ filter: {
30
+ // this is necessary for webpack / rspack to avoid matching .html files
31
+ id: /\.(m|c)?(j|t)sx?$/,
32
+ code: {
33
+ include: includeCode,
34
+ },
35
+ },
36
+ handler(code, id) {
37
+ if (!globalThis.TSR_ROUTES_BY_ID_MAP?.has(id)) {
38
+ return null
39
+ }
22
40
 
23
- transform(code, id) {
24
- if (!code.includes('export const Route = createFileRoute(')) {
25
- return null
26
- }
27
-
28
- if (debug) console.info('Adding HMR handling to route ', id)
29
-
30
- const ast = parseAst({ code })
31
- ast.program.body.push(routeHmrStatement)
32
- const result = generateFromAst(ast, {
33
- sourceMaps: true,
34
- filename: id,
35
- sourceFileName: id,
36
- })
37
- if (debug) {
38
- logDiff(code, result.code)
39
- console.log('Output:\n', result.code + '\n\n')
40
- }
41
- return result
42
- },
41
+ if (debug) console.info('Adding HMR handling to route ', id)
43
42
 
44
- transformInclude(id) {
45
- return fileIsInRoutesDirectory(id, userConfig.routesDirectory)
43
+ const ast = parseAst({ code })
44
+ ast.program.body.push(routeHmrStatement)
45
+ const result = generateFromAst(ast, {
46
+ sourceMaps: true,
47
+ filename: id,
48
+ sourceFileName: id,
49
+ })
50
+ if (debug) {
51
+ logDiff(code, result.code)
52
+ console.log('Output:\n', result.code + '\n\n')
53
+ }
54
+ return result
55
+ },
46
56
  },
47
-
48
57
  vite: {
49
58
  configResolved(config) {
50
59
  ROOT = config.root
51
60
  userConfig = getConfig(options, ROOT)
52
61
  },
53
- },
54
-
55
- rspack() {
56
- ROOT = process.cwd()
57
- userConfig = getConfig(options, ROOT)
58
- },
59
-
60
- webpack() {
61
- ROOT = process.cwd()
62
- userConfig = getConfig(options, ROOT)
62
+ applyToEnvironment(environment) {
63
+ if (userConfig.plugin?.vite?.environmentName) {
64
+ return userConfig.plugin.vite.environmentName === environment.name
65
+ }
66
+ return true
67
+ },
63
68
  },
64
69
  }
65
70
  }
package/src/core/utils.ts CHANGED
@@ -1,18 +1,3 @@
1
- import { isAbsolute, join, normalize } from 'node:path'
2
-
3
1
  export const debug =
4
2
  process.env.TSR_VITE_DEBUG &&
5
3
  ['true', 'router-plugin'].includes(process.env.TSR_VITE_DEBUG)
6
-
7
- export function fileIsInRoutesDirectory(
8
- filePath: string,
9
- routesDirectory: string,
10
- ): boolean {
11
- const routesDirectoryPath = isAbsolute(routesDirectory)
12
- ? routesDirectory
13
- : join(process.cwd(), routesDirectory)
14
-
15
- const path = normalize(filePath)
16
-
17
- return path.startsWith(routesDirectoryPath)
18
- }
@@ -0,0 +1,7 @@
1
+ /* eslint-disable no-var */
2
+ import type { GetRoutesByFileMapResult } from '@tanstack/router-generator'
3
+
4
+ declare global {
5
+ var TSR_ROUTES_BY_ID_MAP: GetRoutesByFileMapResult | undefined
6
+ }
7
+ export {}
package/src/index.ts CHANGED
@@ -2,3 +2,8 @@ export { configSchema, getConfig } from './core/config'
2
2
  export { unpluginRouterCodeSplitterFactory } from './core/router-code-splitter-plugin'
3
3
  export { unpluginRouterGeneratorFactory } from './core/router-generator-plugin'
4
4
  export type { Config, ConfigInput, ConfigOutput } from './core/config'
5
+ export {
6
+ tsrSplit,
7
+ splitRouteIdentNodes,
8
+ defaultCodeSplitGroupings,
9
+ } from './core/constants'