@tanstack/router-plugin 1.166.9 → 1.166.11

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 (80) hide show
  1. package/dist/cjs/_virtual/_rolldown/runtime.cjs +23 -0
  2. package/dist/cjs/core/code-splitter/compilers.cjs +866 -1324
  3. package/dist/cjs/core/code-splitter/compilers.cjs.map +1 -1
  4. package/dist/cjs/core/code-splitter/framework-options.cjs +39 -41
  5. package/dist/cjs/core/code-splitter/framework-options.cjs.map +1 -1
  6. package/dist/cjs/core/code-splitter/path-ids.cjs +26 -31
  7. package/dist/cjs/core/code-splitter/path-ids.cjs.map +1 -1
  8. package/dist/cjs/core/code-splitter/plugins/framework-plugins.cjs +11 -14
  9. package/dist/cjs/core/code-splitter/plugins/framework-plugins.cjs.map +1 -1
  10. package/dist/cjs/core/code-splitter/plugins/react-refresh-route-components.cjs +31 -65
  11. package/dist/cjs/core/code-splitter/plugins/react-refresh-route-components.cjs.map +1 -1
  12. package/dist/cjs/core/config.cjs +36 -46
  13. package/dist/cjs/core/config.cjs.map +1 -1
  14. package/dist/cjs/core/constants.cjs +16 -15
  15. package/dist/cjs/core/constants.cjs.map +1 -1
  16. package/dist/cjs/core/route-autoimport-plugin.cjs +81 -115
  17. package/dist/cjs/core/route-autoimport-plugin.cjs.map +1 -1
  18. package/dist/cjs/core/route-hmr-statement.cjs +34 -56
  19. package/dist/cjs/core/route-hmr-statement.cjs.map +1 -1
  20. package/dist/cjs/core/router-code-splitter-plugin.cjs +236 -306
  21. package/dist/cjs/core/router-code-splitter-plugin.cjs.map +1 -1
  22. package/dist/cjs/core/router-composed-plugin.cjs +28 -34
  23. package/dist/cjs/core/router-composed-plugin.cjs.map +1 -1
  24. package/dist/cjs/core/router-generator-plugin.cjs +101 -133
  25. package/dist/cjs/core/router-generator-plugin.cjs.map +1 -1
  26. package/dist/cjs/core/router-hmr-plugin.cjs +81 -81
  27. package/dist/cjs/core/router-hmr-plugin.cjs.map +1 -1
  28. package/dist/cjs/core/utils.cjs +23 -30
  29. package/dist/cjs/core/utils.cjs.map +1 -1
  30. package/dist/cjs/esbuild.cjs +47 -18
  31. package/dist/cjs/esbuild.cjs.map +1 -1
  32. package/dist/cjs/index.cjs +11 -13
  33. package/dist/cjs/rspack.cjs +58 -19
  34. package/dist/cjs/rspack.cjs.map +1 -1
  35. package/dist/cjs/vite.cjs +52 -20
  36. package/dist/cjs/vite.cjs.map +1 -1
  37. package/dist/cjs/webpack.cjs +46 -19
  38. package/dist/cjs/webpack.cjs.map +1 -1
  39. package/dist/esm/core/code-splitter/compilers.js +859 -1307
  40. package/dist/esm/core/code-splitter/compilers.js.map +1 -1
  41. package/dist/esm/core/code-splitter/framework-options.js +40 -42
  42. package/dist/esm/core/code-splitter/framework-options.js.map +1 -1
  43. package/dist/esm/core/code-splitter/path-ids.js +27 -33
  44. package/dist/esm/core/code-splitter/path-ids.js.map +1 -1
  45. package/dist/esm/core/code-splitter/plugins/framework-plugins.js +11 -14
  46. package/dist/esm/core/code-splitter/plugins/framework-plugins.js.map +1 -1
  47. package/dist/esm/core/code-splitter/plugins/react-refresh-route-components.js +29 -48
  48. package/dist/esm/core/code-splitter/plugins/react-refresh-route-components.js.map +1 -1
  49. package/dist/esm/core/config.js +35 -48
  50. package/dist/esm/core/config.js.map +1 -1
  51. package/dist/esm/core/constants.js +17 -19
  52. package/dist/esm/core/constants.js.map +1 -1
  53. package/dist/esm/core/route-autoimport-plugin.js +78 -98
  54. package/dist/esm/core/route-autoimport-plugin.js.map +1 -1
  55. package/dist/esm/core/route-hmr-statement.js +32 -39
  56. package/dist/esm/core/route-hmr-statement.js.map +1 -1
  57. package/dist/esm/core/router-code-splitter-plugin.js +234 -305
  58. package/dist/esm/core/router-code-splitter-plugin.js.map +1 -1
  59. package/dist/esm/core/router-composed-plugin.js +25 -32
  60. package/dist/esm/core/router-composed-plugin.js.map +1 -1
  61. package/dist/esm/core/router-generator-plugin.js +100 -111
  62. package/dist/esm/core/router-generator-plugin.js.map +1 -1
  63. package/dist/esm/core/router-hmr-plugin.js +79 -80
  64. package/dist/esm/core/router-hmr-plugin.js.map +1 -1
  65. package/dist/esm/core/utils.js +21 -15
  66. package/dist/esm/core/utils.js.map +1 -1
  67. package/dist/esm/esbuild.js +37 -18
  68. package/dist/esm/esbuild.js.map +1 -1
  69. package/dist/esm/index.js +2 -11
  70. package/dist/esm/rspack.js +49 -20
  71. package/dist/esm/rspack.js.map +1 -1
  72. package/dist/esm/vite.js +42 -21
  73. package/dist/esm/vite.js.map +1 -1
  74. package/dist/esm/webpack.js +37 -20
  75. package/dist/esm/webpack.js.map +1 -1
  76. package/package.json +6 -6
  77. package/src/core/code-splitter/compilers.ts +1 -1
  78. package/src/core/route-autoimport-plugin.ts +1 -1
  79. package/dist/cjs/index.cjs.map +0 -1
  80. package/dist/esm/index.js.map +0 -1
@@ -1,309 +1,239 @@
1
- "use strict";
2
- Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
3
- const node_url = require("node:url");
4
- const routerUtils = require("@tanstack/router-utils");
5
- const config = require("./config.cjs");
6
- const compilers = require("./code-splitter/compilers.cjs");
7
- const frameworkPlugins = require("./code-splitter/plugins/framework-plugins.cjs");
8
- const constants = require("./constants.cjs");
9
- const pathIds = require("./code-splitter/path-ids.cjs");
10
- const utils = require("./utils.cjs");
11
- const PLUGIN_NAME = "unplugin:router-code-splitter";
12
- const CODE_SPLITTER_PLUGIN_NAME = "tanstack-router:code-splitter:compile-reference-file";
13
- const TRANSFORMATION_PLUGINS_BY_FRAMEWORK = {
14
- react: [
15
- {
16
- // Babel-based React plugin
17
- pluginNames: ["vite:react-babel", "vite:react-refresh"],
18
- pkg: "@vitejs/plugin-react",
19
- usage: "react()"
20
- },
21
- {
22
- // SWC-based React plugin
23
- pluginNames: ["vite:react-swc", "vite:react-swc:resolve-runtime"],
24
- pkg: "@vitejs/plugin-react-swc",
25
- usage: "reactSwc()"
26
- },
27
- {
28
- // OXC-based React plugin (deprecated but should still be handled)
29
- pluginNames: ["vite:react-oxc:config", "vite:react-oxc:refresh-runtime"],
30
- pkg: "@vitejs/plugin-react-oxc",
31
- usage: "reactOxc()"
32
- }
33
- ],
34
- solid: [
35
- {
36
- pluginNames: ["solid"],
37
- pkg: "vite-plugin-solid",
38
- usage: "solid()"
39
- }
40
- ]
1
+ require("../_virtual/_rolldown/runtime.cjs");
2
+ const require_config = require("./config.cjs");
3
+ const require_constants = require("./constants.cjs");
4
+ const require_path_ids = require("./code-splitter/path-ids.cjs");
5
+ const require_compilers = require("./code-splitter/compilers.cjs");
6
+ const require_utils = require("./utils.cjs");
7
+ const require_framework_plugins = require("./code-splitter/plugins/framework-plugins.cjs");
8
+ let node_url = require("node:url");
9
+ let _tanstack_router_utils = require("@tanstack/router-utils");
10
+ //#region src/core/router-code-splitter-plugin.ts
11
+ /**
12
+ * It is important to familiarize yourself with how the code-splitting works in this plugin.
13
+ * https://github.com/TanStack/router/pull/3355
14
+ */
15
+ var PLUGIN_NAME = "unplugin:router-code-splitter";
16
+ var CODE_SPLITTER_PLUGIN_NAME = "tanstack-router:code-splitter:compile-reference-file";
17
+ /**
18
+ * JSX transformation plugins grouped by framework.
19
+ * These plugins must come AFTER the TanStack Router plugin in the Vite config.
20
+ */
21
+ var TRANSFORMATION_PLUGINS_BY_FRAMEWORK = {
22
+ react: [
23
+ {
24
+ pluginNames: ["vite:react-babel", "vite:react-refresh"],
25
+ pkg: "@vitejs/plugin-react",
26
+ usage: "react()"
27
+ },
28
+ {
29
+ pluginNames: ["vite:react-swc", "vite:react-swc:resolve-runtime"],
30
+ pkg: "@vitejs/plugin-react-swc",
31
+ usage: "reactSwc()"
32
+ },
33
+ {
34
+ pluginNames: ["vite:react-oxc:config", "vite:react-oxc:refresh-runtime"],
35
+ pkg: "@vitejs/plugin-react-oxc",
36
+ usage: "reactOxc()"
37
+ }
38
+ ],
39
+ solid: [{
40
+ pluginNames: ["solid"],
41
+ pkg: "vite-plugin-solid",
42
+ usage: "solid()"
43
+ }]
41
44
  };
42
- const unpluginRouterCodeSplitterFactory = (options = {}, { framework: _framework }) => {
43
- let ROOT = process.cwd();
44
- let userConfig;
45
- function initUserConfig() {
46
- if (typeof options === "function") {
47
- userConfig = options();
48
- } else {
49
- userConfig = config.getConfig(options, ROOT);
50
- }
51
- }
52
- const isProduction = process.env.NODE_ENV === "production";
53
- const sharedBindingsMap = /* @__PURE__ */ new Map();
54
- const getGlobalCodeSplitGroupings = () => {
55
- return userConfig.codeSplittingOptions?.defaultBehavior || constants.defaultCodeSplitGroupings;
56
- };
57
- const getShouldSplitFn = () => {
58
- return userConfig.codeSplittingOptions?.splitBehavior;
59
- };
60
- const handleCompilingReferenceFile = (code, id, generatorNodeInfo) => {
61
- if (utils.debug) console.info("Compiling Route: ", id);
62
- const fromCode = compilers.detectCodeSplitGroupingsFromRoute({
63
- code
64
- });
65
- if (fromCode.groupings) {
66
- const res = config.splitGroupingsSchema.safeParse(fromCode.groupings);
67
- if (!res.success) {
68
- const message = res.error.errors.map((e) => e.message).join(". ");
69
- throw new Error(
70
- `The groupings for the route "${id}" are invalid.
71
- ${message}`
72
- );
73
- }
74
- }
75
- const userShouldSplitFn = getShouldSplitFn();
76
- const pluginSplitBehavior = userShouldSplitFn?.({
77
- routeId: generatorNodeInfo.routePath
78
- });
79
- if (pluginSplitBehavior) {
80
- const res = config.splitGroupingsSchema.safeParse(pluginSplitBehavior);
81
- if (!res.success) {
82
- const message = res.error.errors.map((e) => e.message).join(". ");
83
- throw new Error(
84
- `The groupings returned when using \`splitBehavior\` for the route "${id}" are invalid.
85
- ${message}`
86
- );
87
- }
88
- }
89
- const splitGroupings = fromCode.groupings || pluginSplitBehavior || getGlobalCodeSplitGroupings();
90
- const sharedBindings = compilers.computeSharedBindings({
91
- code,
92
- codeSplitGroupings: splitGroupings
93
- });
94
- if (sharedBindings.size > 0) {
95
- sharedBindingsMap.set(id, sharedBindings);
96
- } else {
97
- sharedBindingsMap.delete(id);
98
- }
99
- const addHmr = (userConfig.codeSplittingOptions?.addHmr ?? true) && !isProduction;
100
- const compiledReferenceRoute = compilers.compileCodeSplitReferenceRoute({
101
- code,
102
- codeSplitGroupings: splitGroupings,
103
- targetFramework: userConfig.target,
104
- filename: id,
105
- id,
106
- deleteNodes: userConfig.codeSplittingOptions?.deleteNodes ? new Set(userConfig.codeSplittingOptions.deleteNodes) : void 0,
107
- addHmr,
108
- sharedBindings: sharedBindings.size > 0 ? sharedBindings : void 0,
109
- compilerPlugins: frameworkPlugins.getReferenceRouteCompilerPlugins({
110
- targetFramework: userConfig.target,
111
- addHmr
112
- })
113
- });
114
- if (compiledReferenceRoute === null) {
115
- if (utils.debug) {
116
- console.info(
117
- `No changes made to route "${id}", skipping code-splitting.`
118
- );
119
- }
120
- return null;
121
- }
122
- if (utils.debug) {
123
- routerUtils.logDiff(code, compiledReferenceRoute.code);
124
- console.log("Output:\n", compiledReferenceRoute.code + "\n\n");
125
- }
126
- return compiledReferenceRoute;
127
- };
128
- const handleCompilingVirtualFile = (code, id) => {
129
- if (utils.debug) console.info("Splitting Route: ", id);
130
- const [_, ...pathnameParts] = id.split("?");
131
- const searchParams = new URLSearchParams(pathnameParts.join("?"));
132
- const splitValue = searchParams.get(constants.tsrSplit);
133
- if (!splitValue) {
134
- throw new Error(
135
- `The split value for the virtual route "${id}" was not found.`
136
- );
137
- }
138
- const rawGrouping = pathIds.decodeIdentifier(splitValue);
139
- const grouping = [...new Set(rawGrouping)].filter(
140
- (p) => constants.splitRouteIdentNodes.includes(p)
141
- );
142
- const baseId = id.split("?")[0];
143
- const resolvedSharedBindings = sharedBindingsMap.get(baseId);
144
- const result = compilers.compileCodeSplitVirtualRoute({
145
- code,
146
- filename: id,
147
- splitTargets: grouping,
148
- sharedBindings: resolvedSharedBindings
149
- });
150
- if (utils.debug) {
151
- routerUtils.logDiff(code, result.code);
152
- console.log("Output:\n", result.code + "\n\n");
153
- }
154
- return result;
155
- };
156
- const includedCode = [
157
- "createFileRoute(",
158
- "createRootRoute(",
159
- "createRootRouteWithContext("
160
- ];
161
- return [
162
- {
163
- name: "tanstack-router:code-splitter:compile-reference-file",
164
- enforce: "pre",
165
- transform: {
166
- filter: {
167
- id: {
168
- exclude: [constants.tsrSplit, constants.tsrShared],
169
- // this is necessary for webpack / rspack to avoid matching .html files
170
- include: /\.(m|c)?(j|t)sx?$/
171
- },
172
- code: {
173
- include: includedCode
174
- }
175
- },
176
- handler(code, id) {
177
- const normalizedId = utils.normalizePath(id);
178
- const generatorFileInfo = globalThis.TSR_ROUTES_BY_ID_MAP?.get(normalizedId);
179
- if (generatorFileInfo && includedCode.some((included) => code.includes(included))) {
180
- return handleCompilingReferenceFile(
181
- code,
182
- normalizedId,
183
- generatorFileInfo
184
- );
185
- }
186
- return null;
187
- }
188
- },
189
- vite: {
190
- configResolved(config2) {
191
- ROOT = config2.root;
192
- initUserConfig();
193
- const routerPluginIndex = config2.plugins.findIndex(
194
- (p) => p.name === CODE_SPLITTER_PLUGIN_NAME
195
- );
196
- if (routerPluginIndex === -1) return;
197
- const frameworkPlugins2 = TRANSFORMATION_PLUGINS_BY_FRAMEWORK[userConfig.target];
198
- if (!frameworkPlugins2) return;
199
- for (const transformPlugin of frameworkPlugins2) {
200
- const transformPluginIndex = config2.plugins.findIndex(
201
- (p) => transformPlugin.pluginNames.includes(p.name)
202
- );
203
- if (transformPluginIndex !== -1 && transformPluginIndex < routerPluginIndex) {
204
- throw new Error(
205
- `Plugin order error: '${transformPlugin.pkg}' is placed before '@tanstack/router-plugin'.
206
-
207
- The TanStack Router plugin must come BEFORE JSX transformation plugins.
208
-
209
- Please update your Vite config:
210
-
211
- plugins: [
212
- tanstackRouter(),
213
- ${transformPlugin.usage},
214
- ]
215
- `
216
- );
217
- }
218
- }
219
- },
220
- applyToEnvironment(environment) {
221
- if (userConfig.plugin?.vite?.environmentName) {
222
- return userConfig.plugin.vite.environmentName === environment.name;
223
- }
224
- return true;
225
- }
226
- },
227
- rspack(compiler) {
228
- ROOT = process.cwd();
229
- initUserConfig();
230
- if (compiler.options.mode === "production") {
231
- compiler.hooks.done.tap(PLUGIN_NAME, () => {
232
- console.info("✅ " + PLUGIN_NAME + ": code-splitting done!");
233
- });
234
- }
235
- },
236
- webpack(compiler) {
237
- ROOT = process.cwd();
238
- initUserConfig();
239
- if (compiler.options.mode === "production") {
240
- compiler.hooks.done.tap(PLUGIN_NAME, () => {
241
- console.info("✅ " + PLUGIN_NAME + ": code-splitting done!");
242
- });
243
- }
244
- }
245
- },
246
- {
247
- name: "tanstack-router:code-splitter:compile-virtual-file",
248
- enforce: "pre",
249
- transform: {
250
- filter: {
251
- id: /tsr-split/
252
- },
253
- handler(code, id) {
254
- const url = node_url.pathToFileURL(id);
255
- url.searchParams.delete("v");
256
- const normalizedId = utils.normalizePath(node_url.fileURLToPath(url));
257
- return handleCompilingVirtualFile(code, normalizedId);
258
- }
259
- },
260
- vite: {
261
- applyToEnvironment(environment) {
262
- if (userConfig.plugin?.vite?.environmentName) {
263
- return userConfig.plugin.vite.environmentName === environment.name;
264
- }
265
- return true;
266
- }
267
- }
268
- },
269
- {
270
- name: "tanstack-router:code-splitter:compile-shared-file",
271
- enforce: "pre",
272
- transform: {
273
- filter: {
274
- id: /tsr-shared/
275
- },
276
- handler(code, id) {
277
- const url = node_url.pathToFileURL(id);
278
- url.searchParams.delete("v");
279
- const normalizedId = utils.normalizePath(node_url.fileURLToPath(url));
280
- const [baseId] = normalizedId.split("?");
281
- if (!baseId) return null;
282
- const sharedBindings = sharedBindingsMap.get(baseId);
283
- if (!sharedBindings || sharedBindings.size === 0) return null;
284
- if (utils.debug) console.info("Compiling Shared Module: ", id);
285
- const result = compilers.compileCodeSplitSharedRoute({
286
- code,
287
- sharedBindings,
288
- filename: normalizedId
289
- });
290
- if (utils.debug) {
291
- routerUtils.logDiff(code, result.code);
292
- console.log("Output:\n", result.code + "\n\n");
293
- }
294
- return result;
295
- }
296
- },
297
- vite: {
298
- applyToEnvironment(environment) {
299
- if (userConfig.plugin?.vite?.environmentName) {
300
- return userConfig.plugin.vite.environmentName === environment.name;
301
- }
302
- return true;
303
- }
304
- }
305
- }
306
- ];
45
+ var unpluginRouterCodeSplitterFactory = (options = {}, { framework: _framework }) => {
46
+ let ROOT = process.cwd();
47
+ let userConfig;
48
+ function initUserConfig() {
49
+ if (typeof options === "function") userConfig = options();
50
+ else userConfig = require_config.getConfig(options, ROOT);
51
+ }
52
+ const isProduction = process.env.NODE_ENV === "production";
53
+ const sharedBindingsMap = /* @__PURE__ */ new Map();
54
+ const getGlobalCodeSplitGroupings = () => {
55
+ return userConfig.codeSplittingOptions?.defaultBehavior || require_constants.defaultCodeSplitGroupings;
56
+ };
57
+ const getShouldSplitFn = () => {
58
+ return userConfig.codeSplittingOptions?.splitBehavior;
59
+ };
60
+ const handleCompilingReferenceFile = (code, id, generatorNodeInfo) => {
61
+ if (require_utils.debug) console.info("Compiling Route: ", id);
62
+ const fromCode = require_compilers.detectCodeSplitGroupingsFromRoute({ code });
63
+ if (fromCode.groupings) {
64
+ const res = require_config.splitGroupingsSchema.safeParse(fromCode.groupings);
65
+ if (!res.success) {
66
+ const message = res.error.errors.map((e) => e.message).join(". ");
67
+ throw new Error(`The groupings for the route "${id}" are invalid.\n${message}`);
68
+ }
69
+ }
70
+ const pluginSplitBehavior = getShouldSplitFn()?.({ routeId: generatorNodeInfo.routePath });
71
+ if (pluginSplitBehavior) {
72
+ const res = require_config.splitGroupingsSchema.safeParse(pluginSplitBehavior);
73
+ if (!res.success) {
74
+ const message = res.error.errors.map((e) => e.message).join(". ");
75
+ throw new Error(`The groupings returned when using \`splitBehavior\` for the route "${id}" are invalid.\n${message}`);
76
+ }
77
+ }
78
+ const splitGroupings = fromCode.groupings || pluginSplitBehavior || getGlobalCodeSplitGroupings();
79
+ const sharedBindings = require_compilers.computeSharedBindings({
80
+ code,
81
+ codeSplitGroupings: splitGroupings
82
+ });
83
+ if (sharedBindings.size > 0) sharedBindingsMap.set(id, sharedBindings);
84
+ else sharedBindingsMap.delete(id);
85
+ const addHmr = (userConfig.codeSplittingOptions?.addHmr ?? true) && !isProduction;
86
+ const compiledReferenceRoute = require_compilers.compileCodeSplitReferenceRoute({
87
+ code,
88
+ codeSplitGroupings: splitGroupings,
89
+ targetFramework: userConfig.target,
90
+ filename: id,
91
+ id,
92
+ deleteNodes: userConfig.codeSplittingOptions?.deleteNodes ? new Set(userConfig.codeSplittingOptions.deleteNodes) : void 0,
93
+ addHmr,
94
+ sharedBindings: sharedBindings.size > 0 ? sharedBindings : void 0,
95
+ compilerPlugins: require_framework_plugins.getReferenceRouteCompilerPlugins({
96
+ targetFramework: userConfig.target,
97
+ addHmr
98
+ })
99
+ });
100
+ if (compiledReferenceRoute === null) {
101
+ if (require_utils.debug) console.info(`No changes made to route "${id}", skipping code-splitting.`);
102
+ return null;
103
+ }
104
+ if (require_utils.debug) {
105
+ (0, _tanstack_router_utils.logDiff)(code, compiledReferenceRoute.code);
106
+ console.log("Output:\n", compiledReferenceRoute.code + "\n\n");
107
+ }
108
+ return compiledReferenceRoute;
109
+ };
110
+ const handleCompilingVirtualFile = (code, id) => {
111
+ if (require_utils.debug) console.info("Splitting Route: ", id);
112
+ const [_, ...pathnameParts] = id.split("?");
113
+ const splitValue = new URLSearchParams(pathnameParts.join("?")).get(require_constants.tsrSplit);
114
+ if (!splitValue) throw new Error(`The split value for the virtual route "${id}" was not found.`);
115
+ const rawGrouping = require_path_ids.decodeIdentifier(splitValue);
116
+ const grouping = [...new Set(rawGrouping)].filter((p) => require_constants.splitRouteIdentNodes.includes(p));
117
+ const baseId = id.split("?")[0];
118
+ const result = require_compilers.compileCodeSplitVirtualRoute({
119
+ code,
120
+ filename: id,
121
+ splitTargets: grouping,
122
+ sharedBindings: sharedBindingsMap.get(baseId)
123
+ });
124
+ if (require_utils.debug) {
125
+ (0, _tanstack_router_utils.logDiff)(code, result.code);
126
+ console.log("Output:\n", result.code + "\n\n");
127
+ }
128
+ return result;
129
+ };
130
+ const includedCode = [
131
+ "createFileRoute(",
132
+ "createRootRoute(",
133
+ "createRootRouteWithContext("
134
+ ];
135
+ return [
136
+ {
137
+ name: "tanstack-router:code-splitter:compile-reference-file",
138
+ enforce: "pre",
139
+ transform: {
140
+ filter: {
141
+ id: {
142
+ exclude: [require_constants.tsrSplit, require_constants.tsrShared],
143
+ include: /\.(m|c)?(j|t)sx?$/
144
+ },
145
+ code: { include: includedCode }
146
+ },
147
+ handler(code, id) {
148
+ const normalizedId = require_utils.normalizePath(id);
149
+ const generatorFileInfo = globalThis.TSR_ROUTES_BY_ID_MAP?.get(normalizedId);
150
+ if (generatorFileInfo && includedCode.some((included) => code.includes(included))) return handleCompilingReferenceFile(code, normalizedId, generatorFileInfo);
151
+ return null;
152
+ }
153
+ },
154
+ vite: {
155
+ configResolved(config) {
156
+ ROOT = config.root;
157
+ initUserConfig();
158
+ const routerPluginIndex = config.plugins.findIndex((p) => p.name === CODE_SPLITTER_PLUGIN_NAME);
159
+ if (routerPluginIndex === -1) return;
160
+ const frameworkPlugins = TRANSFORMATION_PLUGINS_BY_FRAMEWORK[userConfig.target];
161
+ if (!frameworkPlugins) return;
162
+ for (const transformPlugin of frameworkPlugins) {
163
+ const transformPluginIndex = config.plugins.findIndex((p) => transformPlugin.pluginNames.includes(p.name));
164
+ if (transformPluginIndex !== -1 && transformPluginIndex < routerPluginIndex) throw new Error(`Plugin order error: '${transformPlugin.pkg}' is placed before '@tanstack/router-plugin'.\n\nThe TanStack Router plugin must come BEFORE JSX transformation plugins.\n\nPlease update your Vite config:\n\n plugins: [\n tanstackRouter(),\n ${transformPlugin.usage},\n ]\n`);
165
+ }
166
+ },
167
+ applyToEnvironment(environment) {
168
+ if (userConfig.plugin?.vite?.environmentName) return userConfig.plugin.vite.environmentName === environment.name;
169
+ return true;
170
+ }
171
+ },
172
+ rspack(compiler) {
173
+ ROOT = process.cwd();
174
+ initUserConfig();
175
+ if (compiler.options.mode === "production") compiler.hooks.done.tap(PLUGIN_NAME, () => {
176
+ console.info("✅ " + PLUGIN_NAME + ": code-splitting done!");
177
+ });
178
+ },
179
+ webpack(compiler) {
180
+ ROOT = process.cwd();
181
+ initUserConfig();
182
+ if (compiler.options.mode === "production") compiler.hooks.done.tap(PLUGIN_NAME, () => {
183
+ console.info("✅ " + PLUGIN_NAME + ": code-splitting done!");
184
+ });
185
+ }
186
+ },
187
+ {
188
+ name: "tanstack-router:code-splitter:compile-virtual-file",
189
+ enforce: "pre",
190
+ transform: {
191
+ filter: { id: /tsr-split/ },
192
+ handler(code, id) {
193
+ const url = (0, node_url.pathToFileURL)(id);
194
+ url.searchParams.delete("v");
195
+ return handleCompilingVirtualFile(code, require_utils.normalizePath((0, node_url.fileURLToPath)(url)));
196
+ }
197
+ },
198
+ vite: { applyToEnvironment(environment) {
199
+ if (userConfig.plugin?.vite?.environmentName) return userConfig.plugin.vite.environmentName === environment.name;
200
+ return true;
201
+ } }
202
+ },
203
+ {
204
+ name: "tanstack-router:code-splitter:compile-shared-file",
205
+ enforce: "pre",
206
+ transform: {
207
+ filter: { id: /tsr-shared/ },
208
+ handler(code, id) {
209
+ const url = (0, node_url.pathToFileURL)(id);
210
+ url.searchParams.delete("v");
211
+ const normalizedId = require_utils.normalizePath((0, node_url.fileURLToPath)(url));
212
+ const [baseId] = normalizedId.split("?");
213
+ if (!baseId) return null;
214
+ const sharedBindings = sharedBindingsMap.get(baseId);
215
+ if (!sharedBindings || sharedBindings.size === 0) return null;
216
+ if (require_utils.debug) console.info("Compiling Shared Module: ", id);
217
+ const result = require_compilers.compileCodeSplitSharedRoute({
218
+ code,
219
+ sharedBindings,
220
+ filename: normalizedId
221
+ });
222
+ if (require_utils.debug) {
223
+ (0, _tanstack_router_utils.logDiff)(code, result.code);
224
+ console.log("Output:\n", result.code + "\n\n");
225
+ }
226
+ return result;
227
+ }
228
+ },
229
+ vite: { applyToEnvironment(environment) {
230
+ if (userConfig.plugin?.vite?.environmentName) return userConfig.plugin.vite.environmentName === environment.name;
231
+ return true;
232
+ } }
233
+ }
234
+ ];
307
235
  };
236
+ //#endregion
308
237
  exports.unpluginRouterCodeSplitterFactory = unpluginRouterCodeSplitterFactory;
309
- //# sourceMappingURL=router-code-splitter-plugin.cjs.map
238
+
239
+ //# sourceMappingURL=router-code-splitter-plugin.cjs.map