@tanstack/router-plugin 1.166.10 → 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.
- package/dist/cjs/_virtual/_rolldown/runtime.cjs +23 -0
- package/dist/cjs/core/code-splitter/compilers.cjs +866 -1324
- package/dist/cjs/core/code-splitter/compilers.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/framework-options.cjs +39 -41
- package/dist/cjs/core/code-splitter/framework-options.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/path-ids.cjs +26 -31
- package/dist/cjs/core/code-splitter/path-ids.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/plugins/framework-plugins.cjs +11 -14
- package/dist/cjs/core/code-splitter/plugins/framework-plugins.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/plugins/react-refresh-route-components.cjs +31 -65
- package/dist/cjs/core/code-splitter/plugins/react-refresh-route-components.cjs.map +1 -1
- package/dist/cjs/core/config.cjs +36 -46
- package/dist/cjs/core/config.cjs.map +1 -1
- package/dist/cjs/core/constants.cjs +16 -15
- package/dist/cjs/core/constants.cjs.map +1 -1
- package/dist/cjs/core/route-autoimport-plugin.cjs +81 -115
- package/dist/cjs/core/route-autoimport-plugin.cjs.map +1 -1
- package/dist/cjs/core/route-hmr-statement.cjs +34 -56
- package/dist/cjs/core/route-hmr-statement.cjs.map +1 -1
- package/dist/cjs/core/router-code-splitter-plugin.cjs +236 -306
- package/dist/cjs/core/router-code-splitter-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-composed-plugin.cjs +28 -34
- package/dist/cjs/core/router-composed-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-generator-plugin.cjs +101 -133
- package/dist/cjs/core/router-generator-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-hmr-plugin.cjs +81 -81
- package/dist/cjs/core/router-hmr-plugin.cjs.map +1 -1
- package/dist/cjs/core/utils.cjs +23 -30
- package/dist/cjs/core/utils.cjs.map +1 -1
- package/dist/cjs/esbuild.cjs +47 -18
- package/dist/cjs/esbuild.cjs.map +1 -1
- package/dist/cjs/index.cjs +11 -13
- package/dist/cjs/rspack.cjs +58 -19
- package/dist/cjs/rspack.cjs.map +1 -1
- package/dist/cjs/vite.cjs +52 -20
- package/dist/cjs/vite.cjs.map +1 -1
- package/dist/cjs/webpack.cjs +46 -19
- package/dist/cjs/webpack.cjs.map +1 -1
- package/dist/esm/core/code-splitter/compilers.js +859 -1307
- package/dist/esm/core/code-splitter/compilers.js.map +1 -1
- package/dist/esm/core/code-splitter/framework-options.js +40 -42
- package/dist/esm/core/code-splitter/framework-options.js.map +1 -1
- package/dist/esm/core/code-splitter/path-ids.js +27 -33
- package/dist/esm/core/code-splitter/path-ids.js.map +1 -1
- package/dist/esm/core/code-splitter/plugins/framework-plugins.js +11 -14
- 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 +29 -48
- package/dist/esm/core/code-splitter/plugins/react-refresh-route-components.js.map +1 -1
- package/dist/esm/core/config.js +35 -48
- package/dist/esm/core/config.js.map +1 -1
- package/dist/esm/core/constants.js +17 -19
- package/dist/esm/core/constants.js.map +1 -1
- package/dist/esm/core/route-autoimport-plugin.js +78 -98
- package/dist/esm/core/route-autoimport-plugin.js.map +1 -1
- package/dist/esm/core/route-hmr-statement.js +32 -39
- package/dist/esm/core/route-hmr-statement.js.map +1 -1
- package/dist/esm/core/router-code-splitter-plugin.js +234 -305
- package/dist/esm/core/router-code-splitter-plugin.js.map +1 -1
- package/dist/esm/core/router-composed-plugin.js +25 -32
- package/dist/esm/core/router-composed-plugin.js.map +1 -1
- package/dist/esm/core/router-generator-plugin.js +100 -111
- package/dist/esm/core/router-generator-plugin.js.map +1 -1
- package/dist/esm/core/router-hmr-plugin.js +79 -80
- package/dist/esm/core/router-hmr-plugin.js.map +1 -1
- package/dist/esm/core/utils.js +21 -15
- package/dist/esm/core/utils.js.map +1 -1
- package/dist/esm/esbuild.js +37 -18
- package/dist/esm/esbuild.js.map +1 -1
- package/dist/esm/index.js +2 -11
- package/dist/esm/rspack.js +49 -20
- package/dist/esm/rspack.js.map +1 -1
- package/dist/esm/vite.js +42 -21
- package/dist/esm/vite.js.map +1 -1
- package/dist/esm/webpack.js +37 -20
- package/dist/esm/webpack.js.map +1 -1
- package/package.json +6 -6
- package/src/core/code-splitter/compilers.ts +1 -1
- package/src/core/route-autoimport-plugin.ts +1 -1
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/esm/index.js.map +0 -1
|
@@ -1,309 +1,239 @@
|
|
|
1
|
-
"
|
|
2
|
-
|
|
3
|
-
const
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
const
|
|
7
|
-
const
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
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
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
210
|
-
|
|
211
|
-
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
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
|
-
|
|
238
|
+
|
|
239
|
+
//# sourceMappingURL=router-code-splitter-plugin.cjs.map
|