@tanstack/start-plugin-core 1.121.20 → 1.121.22

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 (137) hide show
  1. package/dist/cjs/compilers.cjs +416 -0
  2. package/dist/cjs/compilers.cjs.map +1 -0
  3. package/dist/cjs/compilers.d.cts +21 -0
  4. package/dist/cjs/constants.cjs +20 -0
  5. package/dist/cjs/constants.cjs.map +1 -0
  6. package/dist/cjs/constants.d.cts +6 -0
  7. package/dist/cjs/debug.cjs +5 -0
  8. package/dist/cjs/debug.cjs.map +1 -0
  9. package/dist/cjs/debug.d.cts +1 -0
  10. package/dist/cjs/dev-server-plugin/extract-html-scripts.cjs +35 -0
  11. package/dist/cjs/dev-server-plugin/extract-html-scripts.cjs.map +1 -0
  12. package/dist/cjs/dev-server-plugin/extract-html-scripts.d.cts +4 -0
  13. package/dist/cjs/dev-server-plugin/plugin.cjs +136 -0
  14. package/dist/cjs/dev-server-plugin/plugin.cjs.map +1 -0
  15. package/dist/cjs/dev-server-plugin/plugin.d.cts +5 -0
  16. package/dist/cjs/index.cjs +11 -0
  17. package/dist/cjs/index.cjs.map +1 -0
  18. package/dist/cjs/index.d.cts +3 -0
  19. package/dist/cjs/load-env-plugin/plugin.cjs +34 -0
  20. package/dist/cjs/load-env-plugin/plugin.cjs.map +1 -0
  21. package/dist/cjs/load-env-plugin/plugin.d.cts +3 -0
  22. package/dist/cjs/nitro-plugin/build-sitemap.cjs +138 -0
  23. package/dist/cjs/nitro-plugin/build-sitemap.cjs.map +1 -0
  24. package/dist/cjs/nitro-plugin/build-sitemap.d.cts +31 -0
  25. package/dist/cjs/nitro-plugin/plugin.cjs +181 -0
  26. package/dist/cjs/nitro-plugin/plugin.cjs.map +1 -0
  27. package/dist/cjs/nitro-plugin/plugin.d.cts +3 -0
  28. package/dist/cjs/nitro-plugin/prerender.cjs +174 -0
  29. package/dist/cjs/nitro-plugin/prerender.cjs.map +1 -0
  30. package/dist/cjs/nitro-plugin/prerender.d.cts +8 -0
  31. package/dist/cjs/nitro-plugin/queue.cjs +131 -0
  32. package/dist/cjs/nitro-plugin/queue.cjs.map +1 -0
  33. package/dist/cjs/nitro-plugin/queue.d.cts +32 -0
  34. package/dist/cjs/plugin.cjs +207 -0
  35. package/dist/cjs/plugin.cjs.map +1 -0
  36. package/dist/cjs/plugin.d.cts +291 -0
  37. package/dist/cjs/resolve-virtual-entries-plugin/plugin.cjs +66 -0
  38. package/dist/cjs/resolve-virtual-entries-plugin/plugin.cjs.map +1 -0
  39. package/dist/cjs/resolve-virtual-entries-plugin/plugin.d.cts +3 -0
  40. package/dist/cjs/schema.cjs +157 -0
  41. package/dist/cjs/schema.cjs.map +1 -0
  42. package/dist/cjs/schema.d.cts +8779 -0
  43. package/dist/cjs/start-compiler-plugin.cjs +74 -0
  44. package/dist/cjs/start-compiler-plugin.cjs.map +1 -0
  45. package/dist/cjs/start-compiler-plugin.d.cts +13 -0
  46. package/dist/cjs/start-manifest-plugin/plugin.cjs +187 -0
  47. package/dist/cjs/start-manifest-plugin/plugin.cjs.map +1 -0
  48. package/dist/cjs/start-manifest-plugin/plugin.d.cts +5 -0
  49. package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.cjs +39 -0
  50. package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.cjs.map +1 -0
  51. package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.d.cts +6 -0
  52. package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.cjs +121 -0
  53. package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.cjs.map +1 -0
  54. package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.d.cts +2 -0
  55. package/dist/cjs/start-router-plugin/plugin.cjs +21 -0
  56. package/dist/cjs/start-router-plugin/plugin.cjs.map +1 -0
  57. package/dist/cjs/start-router-plugin/plugin.d.cts +3 -0
  58. package/dist/cjs/start-router-plugin/route-tree-client-plugin.cjs +72 -0
  59. package/dist/cjs/start-router-plugin/route-tree-client-plugin.cjs.map +1 -0
  60. package/dist/cjs/start-router-plugin/route-tree-client-plugin.d.cts +6 -0
  61. package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.cjs +30 -0
  62. package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.cjs.map +1 -0
  63. package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.d.cts +4 -0
  64. package/dist/cjs/utils.cjs +18 -0
  65. package/dist/cjs/utils.cjs.map +1 -0
  66. package/dist/cjs/utils.d.cts +8 -0
  67. package/dist/esm/compilers.d.ts +21 -0
  68. package/dist/esm/compilers.js +398 -0
  69. package/dist/esm/compilers.js.map +1 -0
  70. package/dist/esm/constants.d.ts +6 -0
  71. package/dist/esm/constants.js +20 -0
  72. package/dist/esm/constants.js.map +1 -0
  73. package/dist/esm/debug.d.ts +1 -0
  74. package/dist/esm/debug.js +5 -0
  75. package/dist/esm/debug.js.map +1 -0
  76. package/dist/esm/dev-server-plugin/extract-html-scripts.d.ts +4 -0
  77. package/dist/esm/dev-server-plugin/extract-html-scripts.js +18 -0
  78. package/dist/esm/dev-server-plugin/extract-html-scripts.js.map +1 -0
  79. package/dist/esm/dev-server-plugin/plugin.d.ts +5 -0
  80. package/dist/esm/dev-server-plugin/plugin.js +136 -0
  81. package/dist/esm/dev-server-plugin/plugin.js.map +1 -0
  82. package/dist/esm/index.d.ts +3 -0
  83. package/dist/esm/index.js +11 -0
  84. package/dist/esm/index.js.map +1 -0
  85. package/dist/esm/load-env-plugin/plugin.d.ts +3 -0
  86. package/dist/esm/load-env-plugin/plugin.js +17 -0
  87. package/dist/esm/load-env-plugin/plugin.js.map +1 -0
  88. package/dist/esm/nitro-plugin/build-sitemap.d.ts +31 -0
  89. package/dist/esm/nitro-plugin/build-sitemap.js +138 -0
  90. package/dist/esm/nitro-plugin/build-sitemap.js.map +1 -0
  91. package/dist/esm/nitro-plugin/plugin.d.ts +3 -0
  92. package/dist/esm/nitro-plugin/plugin.js +181 -0
  93. package/dist/esm/nitro-plugin/plugin.js.map +1 -0
  94. package/dist/esm/nitro-plugin/prerender.d.ts +8 -0
  95. package/dist/esm/nitro-plugin/prerender.js +174 -0
  96. package/dist/esm/nitro-plugin/prerender.js.map +1 -0
  97. package/dist/esm/nitro-plugin/queue.d.ts +32 -0
  98. package/dist/esm/nitro-plugin/queue.js +131 -0
  99. package/dist/esm/nitro-plugin/queue.js.map +1 -0
  100. package/dist/esm/plugin.d.ts +291 -0
  101. package/dist/esm/plugin.js +190 -0
  102. package/dist/esm/plugin.js.map +1 -0
  103. package/dist/esm/resolve-virtual-entries-plugin/plugin.d.ts +3 -0
  104. package/dist/esm/resolve-virtual-entries-plugin/plugin.js +49 -0
  105. package/dist/esm/resolve-virtual-entries-plugin/plugin.js.map +1 -0
  106. package/dist/esm/schema.d.ts +8779 -0
  107. package/dist/esm/schema.js +157 -0
  108. package/dist/esm/schema.js.map +1 -0
  109. package/dist/esm/start-compiler-plugin.d.ts +13 -0
  110. package/dist/esm/start-compiler-plugin.js +74 -0
  111. package/dist/esm/start-compiler-plugin.js.map +1 -0
  112. package/dist/esm/start-manifest-plugin/plugin.d.ts +5 -0
  113. package/dist/esm/start-manifest-plugin/plugin.js +187 -0
  114. package/dist/esm/start-manifest-plugin/plugin.js.map +1 -0
  115. package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.d.ts +6 -0
  116. package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js +39 -0
  117. package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js.map +1 -0
  118. package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.d.ts +2 -0
  119. package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.js +121 -0
  120. package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.js.map +1 -0
  121. package/dist/esm/start-router-plugin/plugin.d.ts +3 -0
  122. package/dist/esm/start-router-plugin/plugin.js +21 -0
  123. package/dist/esm/start-router-plugin/plugin.js.map +1 -0
  124. package/dist/esm/start-router-plugin/route-tree-client-plugin.d.ts +6 -0
  125. package/dist/esm/start-router-plugin/route-tree-client-plugin.js +55 -0
  126. package/dist/esm/start-router-plugin/route-tree-client-plugin.js.map +1 -0
  127. package/dist/esm/start-router-plugin/virtual-route-tree-plugin.d.ts +4 -0
  128. package/dist/esm/start-router-plugin/virtual-route-tree-plugin.js +30 -0
  129. package/dist/esm/start-router-plugin/virtual-route-tree-plugin.js.map +1 -0
  130. package/dist/esm/utils.d.ts +8 -0
  131. package/dist/esm/utils.js +18 -0
  132. package/dist/esm/utils.js.map +1 -0
  133. package/package.json +7 -7
  134. package/src/global.d.ts +2 -0
  135. package/src/plugin.ts +10 -0
  136. package/src/start-manifest-plugin/plugin.ts +93 -99
  137. package/src/start-router-plugin/generator-plugins/routes-manifest-plugin.ts +2 -2
@@ -0,0 +1,121 @@
1
+ import { hasChildWithExport, checkRouteFullPathUniqueness, ensureStringArgument } from "@tanstack/router-generator";
2
+ const EXPORT_NAME = "ServerRoute";
3
+ function serverRoutesPlugin() {
4
+ return {
5
+ name: "server-routes-plugin",
6
+ transformPlugin: {
7
+ name: "server-routes-transform",
8
+ exportName: EXPORT_NAME,
9
+ imports: (ctx) => {
10
+ const targetModule = `@tanstack/${ctx.target}-start/server`;
11
+ const imports = {};
12
+ if (ctx.verboseFileRoutes === false) {
13
+ imports.banned = [
14
+ {
15
+ source: targetModule,
16
+ specifiers: [{ imported: "createServerFileRoute" }]
17
+ }
18
+ ];
19
+ } else {
20
+ imports.required = [
21
+ {
22
+ source: targetModule,
23
+ specifiers: [{ imported: "createServerFileRoute" }]
24
+ }
25
+ ];
26
+ }
27
+ return imports;
28
+ },
29
+ onExportFound: ({ ctx, decl }) => {
30
+ var _a;
31
+ let appliedChanges = false;
32
+ if (((_a = decl.init) == null ? void 0 : _a.type) === "CallExpression") {
33
+ let call = decl.init;
34
+ let callee = call.callee;
35
+ while (callee.type === "MemberExpression" && callee.object.type === "CallExpression") {
36
+ call = callee.object;
37
+ callee = call.callee;
38
+ }
39
+ if (call.callee.type === "Identifier" && call.callee.name === "createServerFileRoute") {
40
+ if (!ctx.verboseFileRoutes) {
41
+ if (call.arguments.length) {
42
+ call.arguments = [];
43
+ appliedChanges = true;
44
+ }
45
+ } else {
46
+ appliedChanges = ensureStringArgument(
47
+ call,
48
+ ctx.routeId,
49
+ ctx.preferredQuote
50
+ );
51
+ }
52
+ } else {
53
+ throw new Error(
54
+ `Expected "createServerFileRoute" call, but got "${call.callee.type}"`
55
+ );
56
+ }
57
+ }
58
+ return appliedChanges;
59
+ }
60
+ },
61
+ moduleAugmentation: ({ generator }) => ({
62
+ module: `@tanstack/${generator.config.target}-start/server`,
63
+ interfaceName: "ServerFileRoutesByPath"
64
+ }),
65
+ onRouteTreesChanged: ({ routeTrees, generator }) => {
66
+ const tree = routeTrees.find((tree2) => tree2.exportName === EXPORT_NAME);
67
+ if (tree) {
68
+ checkRouteFullPathUniqueness(tree.sortedRouteNodes, generator.config);
69
+ }
70
+ },
71
+ imports: (ctx) => {
72
+ var _a;
73
+ const imports = [];
74
+ const targetModule = `@tanstack/${ctx.generator.config.target}-start/server`;
75
+ if (ctx.generator.config.verboseFileRoutes === false) {
76
+ imports.push({
77
+ specifiers: [
78
+ { imported: "CreateServerFileRoute" },
79
+ { imported: "ServerFileRoutesByPath" }
80
+ ],
81
+ source: targetModule,
82
+ importKind: "type"
83
+ });
84
+ }
85
+ const hasMatchingRouteFiles = ctx.acc.routeNodes.length > 0;
86
+ if (hasMatchingRouteFiles) {
87
+ if (!((_a = ctx.rootRouteNode.exports) == null ? void 0 : _a.includes(EXPORT_NAME))) {
88
+ imports.push({
89
+ specifiers: [{ imported: "createServerRootRoute" }],
90
+ source: targetModule
91
+ });
92
+ }
93
+ }
94
+ return imports;
95
+ },
96
+ routeModuleAugmentation: ({ routeNode }) => {
97
+ if (routeNode._fsRouteType === "lazy") {
98
+ return void 0;
99
+ }
100
+ return `const createServerFileRoute: CreateServerFileRoute<
101
+ ServerFileRoutesByPath['${routeNode.routePath}']['parentRoute'],
102
+ ServerFileRoutesByPath['${routeNode.routePath}']['id'],
103
+ ServerFileRoutesByPath['${routeNode.routePath}']['path'],
104
+ ServerFileRoutesByPath['${routeNode.routePath}']['fullPath'],
105
+ ${hasChildWithExport(routeNode, "ServerRoute") ? `${routeNode.variableName}ServerRouteChildren` : "unknown"}
106
+ >`;
107
+ },
108
+ createRootRouteCode: () => `createServerRootRoute()`,
109
+ createVirtualRouteCode: ({ node }) => `createServerFileRoute('${node.routePath}')`,
110
+ config: ({ sortedRouteNodes }) => {
111
+ const hasMatchingRouteFiles = sortedRouteNodes.length > 0;
112
+ return {
113
+ virtualRootRoute: hasMatchingRouteFiles
114
+ };
115
+ }
116
+ };
117
+ }
118
+ export {
119
+ serverRoutesPlugin
120
+ };
121
+ //# sourceMappingURL=server-routes-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"server-routes-plugin.js","sources":["../../../../src/start-router-plugin/generator-plugins/server-routes-plugin.ts"],"sourcesContent":["import {\n checkRouteFullPathUniqueness,\n ensureStringArgument,\n hasChildWithExport,\n} from '@tanstack/router-generator'\n\nimport type {\n GeneratorPluginWithTransform,\n ImportDeclaration,\n TransformImportsConfig,\n} from '@tanstack/router-generator'\n\nconst EXPORT_NAME = 'ServerRoute'\nexport function serverRoutesPlugin(): GeneratorPluginWithTransform {\n return {\n name: 'server-routes-plugin',\n transformPlugin: {\n name: 'server-routes-transform',\n exportName: EXPORT_NAME,\n imports: (ctx) => {\n const targetModule = `@tanstack/${ctx.target}-start/server`\n const imports: TransformImportsConfig = {}\n if (ctx.verboseFileRoutes === false) {\n imports.banned = [\n {\n source: targetModule,\n specifiers: [{ imported: 'createServerFileRoute' }],\n },\n ]\n } else {\n imports.required = [\n {\n source: targetModule,\n specifiers: [{ imported: 'createServerFileRoute' }],\n },\n ]\n }\n return imports\n },\n onExportFound: ({ ctx, decl }) => {\n let appliedChanges = false\n if (decl.init?.type === 'CallExpression') {\n let call = decl.init\n let callee = call.callee\n\n while (\n callee.type === 'MemberExpression' &&\n callee.object.type === 'CallExpression'\n ) {\n call = callee.object\n callee = call.callee\n }\n if (\n call.callee.type === 'Identifier' &&\n call.callee.name === 'createServerFileRoute'\n ) {\n if (!ctx.verboseFileRoutes) {\n if (call.arguments.length) {\n call.arguments = []\n appliedChanges = true\n }\n } else {\n appliedChanges = ensureStringArgument(\n call,\n ctx.routeId,\n ctx.preferredQuote,\n )\n }\n } else {\n throw new Error(\n `Expected \"createServerFileRoute\" call, but got \"${call.callee.type}\"`,\n )\n }\n }\n return appliedChanges\n },\n },\n moduleAugmentation: ({ generator }) => ({\n module: `@tanstack/${generator.config.target}-start/server`,\n interfaceName: 'ServerFileRoutesByPath',\n }),\n onRouteTreesChanged: ({ routeTrees, generator }) => {\n const tree = routeTrees.find((tree) => tree.exportName === EXPORT_NAME)\n if (tree) {\n checkRouteFullPathUniqueness(tree.sortedRouteNodes, generator.config)\n }\n },\n imports: (ctx) => {\n const imports: Array<ImportDeclaration> = []\n\n const targetModule = `@tanstack/${ctx.generator.config.target}-start/server`\n if (ctx.generator.config.verboseFileRoutes === false) {\n imports.push({\n specifiers: [\n { imported: 'CreateServerFileRoute' },\n { imported: 'ServerFileRoutesByPath' },\n ],\n source: targetModule,\n importKind: 'type',\n })\n }\n // don't add the import if there are no server routes defined\n const hasMatchingRouteFiles = ctx.acc.routeNodes.length > 0\n if (hasMatchingRouteFiles) {\n // needs a virtual root route\n if (!ctx.rootRouteNode.exports?.includes(EXPORT_NAME)) {\n imports.push({\n specifiers: [{ imported: 'createServerRootRoute' }],\n source: targetModule,\n })\n }\n }\n return imports\n },\n routeModuleAugmentation: ({ routeNode }) => {\n // server routes don't support lazy routes\n if (routeNode._fsRouteType === 'lazy') {\n return undefined\n }\n return `const createServerFileRoute: CreateServerFileRoute<\n ServerFileRoutesByPath['${routeNode.routePath}']['parentRoute'],\n ServerFileRoutesByPath['${routeNode.routePath}']['id'],\n ServerFileRoutesByPath['${routeNode.routePath}']['path'],\n ServerFileRoutesByPath['${routeNode.routePath}']['fullPath'],\n ${hasChildWithExport(routeNode, 'ServerRoute') ? `${routeNode.variableName}ServerRouteChildren` : 'unknown'}\n >`\n },\n createRootRouteCode: () => `createServerRootRoute()`,\n createVirtualRouteCode: ({ node }) =>\n `createServerFileRoute('${node.routePath}')`,\n config: ({ sortedRouteNodes }) => {\n const hasMatchingRouteFiles = sortedRouteNodes.length > 0\n return {\n virtualRootRoute: hasMatchingRouteFiles,\n }\n },\n }\n}\n"],"names":["tree"],"mappings":"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"}
@@ -0,0 +1,3 @@
1
+ import { PluginOption } from 'vite';
2
+ import { Config } from '@tanstack/router-generator';
3
+ export declare function tanStackStartRouter(config: Config): Array<PluginOption>;
@@ -0,0 +1,21 @@
1
+ import { tanstackRouterGenerator, tanStackRouterCodeSplitter, tanstackRouterAutoImport } from "@tanstack/router-plugin/vite";
2
+ import { routeTreeClientPlugin } from "./route-tree-client-plugin.js";
3
+ import { virtualRouteTreePlugin } from "./virtual-route-tree-plugin.js";
4
+ import { routesManifestPlugin } from "./generator-plugins/routes-manifest-plugin.js";
5
+ import { serverRoutesPlugin } from "./generator-plugins/server-routes-plugin.js";
6
+ function tanStackStartRouter(config) {
7
+ return [
8
+ tanstackRouterGenerator({
9
+ ...config,
10
+ plugins: [serverRoutesPlugin(), routesManifestPlugin()]
11
+ }),
12
+ tanStackRouterCodeSplitter(config),
13
+ tanstackRouterAutoImport(config),
14
+ routeTreeClientPlugin(config),
15
+ virtualRouteTreePlugin(config)
16
+ ];
17
+ }
18
+ export {
19
+ tanStackStartRouter
20
+ };
21
+ //# sourceMappingURL=plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"plugin.js","sources":["../../../src/start-router-plugin/plugin.ts"],"sourcesContent":["/*\nwhat is this plugin doing, especially compared to one already existing in the @tanstack/router-plugin package?\n\nit configures:\n1. the generator to generate both the render-route-tree as well as the server-route-tree\n2. the code-splitter plugin, so it could possibly be enabled per environment (e.g. disable on the server)\n3. the auto import plugin for both environments\n4. the route tree client plugin, which removes the server part from the generated route tree\n5. the virtual route tree plugin, which provides the route tree to the server\n*/\n\nimport {\n tanStackRouterCodeSplitter,\n tanstackRouterAutoImport,\n tanstackRouterGenerator,\n} from '@tanstack/router-plugin/vite'\nimport { routeTreeClientPlugin } from './route-tree-client-plugin'\nimport { virtualRouteTreePlugin } from './virtual-route-tree-plugin'\nimport { routesManifestPlugin } from './generator-plugins/routes-manifest-plugin'\nimport { serverRoutesPlugin } from './generator-plugins/server-routes-plugin'\nimport type { PluginOption } from 'vite'\nimport type { Config } from '@tanstack/router-generator'\n\nexport function tanStackStartRouter(config: Config): Array<PluginOption> {\n return [\n tanstackRouterGenerator({\n ...config,\n plugins: [serverRoutesPlugin(), routesManifestPlugin()],\n }),\n tanStackRouterCodeSplitter(config),\n tanstackRouterAutoImport(config),\n routeTreeClientPlugin(config),\n virtualRouteTreePlugin(config),\n ]\n}\n"],"names":[],"mappings":";;;;;AAuBO,SAAS,oBAAoB,QAAqC;AAChE,SAAA;AAAA,IACL,wBAAwB;AAAA,MACtB,GAAG;AAAA,MACH,SAAS,CAAC,mBAAmB,GAAG,qBAAsB,CAAA;AAAA,IAAA,CACvD;AAAA,IACD,2BAA2B,MAAM;AAAA,IACjC,yBAAyB,MAAM;AAAA,IAC/B,sBAAsB,MAAM;AAAA,IAC5B,uBAAuB,MAAM;AAAA,EAC/B;AACF;"}
@@ -0,0 +1,6 @@
1
+ import { Plugin } from 'vite';
2
+ import { Config } from '@tanstack/router-generator';
3
+ /**
4
+ * This removes the server part from the generated route tree so that it can be used on the client.
5
+ */
6
+ export declare function routeTreeClientPlugin(config: Config): Plugin;
@@ -0,0 +1,55 @@
1
+ import path from "node:path";
2
+ import * as t from "@babel/types";
3
+ import { parseAst, generateFromAst, logDiff } from "@tanstack/router-utils";
4
+ import { normalizePath } from "vite";
5
+ import { deadCodeElimination } from "babel-dead-code-elimination";
6
+ import { debug } from "../debug.js";
7
+ function routeTreeClientPlugin(config) {
8
+ const generatedRouteTreePath = normalizePath(
9
+ path.resolve(config.generatedRouteTree)
10
+ );
11
+ return {
12
+ name: "tanstack-start:route-tree-client-plugin",
13
+ enforce: "pre",
14
+ // only run this plugin in the client environment
15
+ applyToEnvironment: (env) => env.config.consumer === "client",
16
+ transform: {
17
+ filter: { id: generatedRouteTreePath },
18
+ handler(code, id) {
19
+ if (id !== generatedRouteTreePath) {
20
+ return null;
21
+ }
22
+ if (debug) console.info(`Compiling route tree for the client`, id);
23
+ const ast = parseAst({ code, sourceFilename: id });
24
+ const filteredBody = ast.program.body.filter((node) => {
25
+ if (t.isExportNamedDeclaration(node)) {
26
+ if (node.declaration && t.isVariableDeclaration(node.declaration) && node.declaration.declarations.length === 1 && node.declaration.declarations[0] && t.isVariableDeclarator(node.declaration.declarations[0]) && t.isIdentifier(node.declaration.declarations[0].id) && node.declaration.declarations[0].id.name === "routeTree") {
27
+ return true;
28
+ }
29
+ return false;
30
+ }
31
+ if (t.isTSInterfaceDeclaration(node) || t.isTSModuleDeclaration(node)) {
32
+ return false;
33
+ }
34
+ return true;
35
+ });
36
+ ast.program.body = filteredBody;
37
+ deadCodeElimination(ast);
38
+ const compiled = generateFromAst(ast, {
39
+ sourceMaps: true,
40
+ sourceFileName: id,
41
+ filename: id
42
+ });
43
+ if (debug) {
44
+ logDiff(code, compiled.code);
45
+ console.log("Output:\n", compiled.code, "\n\n");
46
+ }
47
+ return compiled;
48
+ }
49
+ }
50
+ };
51
+ }
52
+ export {
53
+ routeTreeClientPlugin
54
+ };
55
+ //# sourceMappingURL=route-tree-client-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"route-tree-client-plugin.js","sources":["../../../src/start-router-plugin/route-tree-client-plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport * as t from '@babel/types'\nimport { generateFromAst, logDiff, parseAst } from '@tanstack/router-utils'\nimport { normalizePath } from 'vite'\nimport { deadCodeElimination } from 'babel-dead-code-elimination'\nimport { debug } from '../debug'\nimport type { Plugin } from 'vite'\nimport type { Config } from '@tanstack/router-generator'\n\n/**\n * This removes the server part from the generated route tree so that it can be used on the client.\n */\nexport function routeTreeClientPlugin(config: Config): Plugin {\n const generatedRouteTreePath = normalizePath(\n path.resolve(config.generatedRouteTree),\n )\n\n return {\n name: 'tanstack-start:route-tree-client-plugin',\n enforce: 'pre',\n // only run this plugin in the client environment\n applyToEnvironment: (env) => env.config.consumer === 'client',\n transform: {\n filter: { id: generatedRouteTreePath },\n handler(code, id) {\n if (id !== generatedRouteTreePath) {\n return null\n }\n if (debug) console.info(`Compiling route tree for the client`, id)\n const ast = parseAst({ code, sourceFilename: id })\n\n // only keep `export const routeTree = ... `\n const filteredBody = ast.program.body.filter((node) => {\n if (t.isExportNamedDeclaration(node)) {\n if (\n node.declaration &&\n t.isVariableDeclaration(node.declaration) &&\n node.declaration.declarations.length === 1 &&\n node.declaration.declarations[0] &&\n t.isVariableDeclarator(node.declaration.declarations[0]) &&\n t.isIdentifier(node.declaration.declarations[0].id) &&\n node.declaration.declarations[0].id.name === 'routeTree'\n ) {\n return true\n }\n return false\n }\n // strip off the typescript interface & module declarations since they also reference the server routes\n if (\n t.isTSInterfaceDeclaration(node) ||\n t.isTSModuleDeclaration(node)\n ) {\n return false\n }\n return true\n })\n\n ast.program.body = filteredBody\n\n deadCodeElimination(ast)\n\n const compiled = generateFromAst(ast, {\n sourceMaps: true,\n sourceFileName: id,\n filename: id,\n })\n if (debug) {\n logDiff(code, compiled.code)\n console.log('Output:\\n', compiled.code, '\\n\\n')\n }\n\n return compiled\n },\n },\n }\n}\n"],"names":[],"mappings":";;;;;;AAYO,SAAS,sBAAsB,QAAwB;AAC5D,QAAM,yBAAyB;AAAA,IAC7B,KAAK,QAAQ,OAAO,kBAAkB;AAAA,EACxC;AAEO,SAAA;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA;AAAA,IAET,oBAAoB,CAAC,QAAQ,IAAI,OAAO,aAAa;AAAA,IACrD,WAAW;AAAA,MACT,QAAQ,EAAE,IAAI,uBAAuB;AAAA,MACrC,QAAQ,MAAM,IAAI;AAChB,YAAI,OAAO,wBAAwB;AAC1B,iBAAA;AAAA,QAAA;AAET,YAAI,MAAO,SAAQ,KAAK,uCAAuC,EAAE;AACjE,cAAM,MAAM,SAAS,EAAE,MAAM,gBAAgB,IAAI;AAGjD,cAAM,eAAe,IAAI,QAAQ,KAAK,OAAO,CAAC,SAAS;AACjD,cAAA,EAAE,yBAAyB,IAAI,GAAG;AACpC,gBACE,KAAK,eACL,EAAE,sBAAsB,KAAK,WAAW,KACxC,KAAK,YAAY,aAAa,WAAW,KACzC,KAAK,YAAY,aAAa,CAAC,KAC/B,EAAE,qBAAqB,KAAK,YAAY,aAAa,CAAC,CAAC,KACvD,EAAE,aAAa,KAAK,YAAY,aAAa,CAAC,EAAE,EAAE,KAClD,KAAK,YAAY,aAAa,CAAC,EAAE,GAAG,SAAS,aAC7C;AACO,qBAAA;AAAA,YAAA;AAEF,mBAAA;AAAA,UAAA;AAGT,cACE,EAAE,yBAAyB,IAAI,KAC/B,EAAE,sBAAsB,IAAI,GAC5B;AACO,mBAAA;AAAA,UAAA;AAEF,iBAAA;AAAA,QAAA,CACR;AAED,YAAI,QAAQ,OAAO;AAEnB,4BAAoB,GAAG;AAEjB,cAAA,WAAW,gBAAgB,KAAK;AAAA,UACpC,YAAY;AAAA,UACZ,gBAAgB;AAAA,UAChB,UAAU;AAAA,QAAA,CACX;AACD,YAAI,OAAO;AACD,kBAAA,MAAM,SAAS,IAAI;AAC3B,kBAAQ,IAAI,aAAa,SAAS,MAAM,MAAM;AAAA,QAAA;AAGzC,eAAA;AAAA,MAAA;AAAA,IACT;AAAA,EAEJ;AACF;"}
@@ -0,0 +1,4 @@
1
+ import { Config } from '@tanstack/router-generator';
2
+ import { Plugin } from 'vite';
3
+ export declare const moduleId = "tanstack-start-route-tree:v";
4
+ export declare function virtualRouteTreePlugin(config: Config): Plugin;
@@ -0,0 +1,30 @@
1
+ import path from "node:path";
2
+ import { normalizePath } from "vite";
3
+ import { debug } from "../debug.js";
4
+ const moduleId = "tanstack-start-route-tree:v";
5
+ function virtualRouteTreePlugin(config) {
6
+ const generatedRouteTreePath = normalizePath(
7
+ path.resolve(config.generatedRouteTree)
8
+ );
9
+ return {
10
+ name: "tanstack-start:virtual-route-tree",
11
+ enforce: "pre",
12
+ sharedDuringBuild: true,
13
+ resolveId: {
14
+ filter: { id: new RegExp(moduleId) },
15
+ handler(id) {
16
+ let resolvedId = null;
17
+ if (id === moduleId) {
18
+ if (debug) console.info("resolving id", id, generatedRouteTreePath);
19
+ resolvedId = generatedRouteTreePath;
20
+ }
21
+ return resolvedId;
22
+ }
23
+ }
24
+ };
25
+ }
26
+ export {
27
+ moduleId,
28
+ virtualRouteTreePlugin
29
+ };
30
+ //# sourceMappingURL=virtual-route-tree-plugin.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"virtual-route-tree-plugin.js","sources":["../../../src/start-router-plugin/virtual-route-tree-plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { normalizePath } from 'vite'\nimport { debug } from '../debug'\nimport type { Config } from '@tanstack/router-generator'\nimport type { Plugin } from 'vite'\n\nexport const moduleId = 'tanstack-start-route-tree:v'\n\nexport function virtualRouteTreePlugin(config: Config): Plugin {\n const generatedRouteTreePath = normalizePath(\n path.resolve(config.generatedRouteTree),\n )\n\n return {\n name: 'tanstack-start:virtual-route-tree',\n enforce: 'pre',\n sharedDuringBuild: true,\n resolveId: {\n filter: { id: new RegExp(moduleId) },\n handler(id) {\n let resolvedId: string | null = null\n if (id === moduleId) {\n if (debug) console.info('resolving id', id, generatedRouteTreePath)\n resolvedId = generatedRouteTreePath\n }\n return resolvedId\n },\n },\n }\n}\n"],"names":[],"mappings":";;;AAMO,MAAM,WAAW;AAEjB,SAAS,uBAAuB,QAAwB;AAC7D,QAAM,yBAAyB;AAAA,IAC7B,KAAK,QAAQ,OAAO,kBAAkB;AAAA,EACxC;AAEO,SAAA;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT,mBAAmB;AAAA,IACnB,WAAW;AAAA,MACT,QAAQ,EAAE,IAAI,IAAI,OAAO,QAAQ,EAAE;AAAA,MACnC,QAAQ,IAAI;AACV,YAAI,aAA4B;AAChC,YAAI,OAAO,UAAU;AACnB,cAAI,MAAO,SAAQ,KAAK,gBAAgB,IAAI,sBAAsB;AACrD,uBAAA;AAAA,QAAA;AAER,eAAA;AAAA,MAAA;AAAA,IACT;AAAA,EAEJ;AACF;"}
@@ -0,0 +1,8 @@
1
+ export declare function resolveViteId(id: string): string;
2
+ export declare function createLogger(prefix: string): {
3
+ log: (...args: any) => void;
4
+ debug: (...args: any) => void;
5
+ info: (...args: any) => void;
6
+ warn: (...args: any) => void;
7
+ error: (...args: any) => void;
8
+ };
@@ -0,0 +1,18 @@
1
+ function resolveViteId(id) {
2
+ return `\0${id}`;
3
+ }
4
+ function createLogger(prefix) {
5
+ const label = `[${prefix}]`;
6
+ return {
7
+ log: (...args) => console.log(label, ...args),
8
+ debug: (...args) => console.debug(label, ...args),
9
+ info: (...args) => console.info(label, ...args),
10
+ warn: (...args) => console.warn(label, ...args),
11
+ error: (...args) => console.error(label, ...args)
12
+ };
13
+ }
14
+ export {
15
+ createLogger,
16
+ resolveViteId
17
+ };
18
+ //# sourceMappingURL=utils.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"utils.js","sources":["../../src/utils.ts"],"sourcesContent":["export function resolveViteId(id: string) {\n return `\\0${id}`\n}\n\nexport function createLogger(prefix: string) {\n const label = `[${prefix}]`\n return {\n log: (...args: any) => console.log(label, ...args),\n debug: (...args: any) => console.debug(label, ...args),\n info: (...args: any) => console.info(label, ...args),\n warn: (...args: any) => console.warn(label, ...args),\n error: (...args: any) => console.error(label, ...args),\n }\n}\n"],"names":[],"mappings":"AAAO,SAAS,cAAc,IAAY;AACxC,SAAO,KAAK,EAAE;AAChB;AAEO,SAAS,aAAa,QAAgB;AACrC,QAAA,QAAQ,IAAI,MAAM;AACjB,SAAA;AAAA,IACL,KAAK,IAAI,SAAc,QAAQ,IAAI,OAAO,GAAG,IAAI;AAAA,IACjD,OAAO,IAAI,SAAc,QAAQ,MAAM,OAAO,GAAG,IAAI;AAAA,IACrD,MAAM,IAAI,SAAc,QAAQ,KAAK,OAAO,GAAG,IAAI;AAAA,IACnD,MAAM,IAAI,SAAc,QAAQ,KAAK,OAAO,GAAG,IAAI;AAAA,IACnD,OAAO,IAAI,SAAc,QAAQ,MAAM,OAAO,GAAG,IAAI;AAAA,EACvD;AACF;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/start-plugin-core",
3
- "version": "1.121.20",
3
+ "version": "1.121.22",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -63,12 +63,12 @@
63
63
  "ufo": "^1.5.4",
64
64
  "xmlbuilder2": "^3.1.1",
65
65
  "zod": "^3.24.2",
66
- "@tanstack/router-core": "^1.121.20",
67
- "@tanstack/router-plugin": "^1.121.20",
68
- "@tanstack/router-generator": "^1.121.20",
69
- "@tanstack/router-utils": "^1.121.20",
70
- "@tanstack/start-server-core": "^1.121.20",
71
- "@tanstack/server-functions-plugin": "^1.121.20"
66
+ "@tanstack/router-core": "^1.121.21",
67
+ "@tanstack/router-plugin": "^1.121.22",
68
+ "@tanstack/router-utils": "^1.121.21",
69
+ "@tanstack/router-generator": "^1.121.21",
70
+ "@tanstack/server-functions-plugin": "^1.121.21",
71
+ "@tanstack/start-server-core": "^1.121.21"
72
72
  },
73
73
  "devDependencies": {
74
74
  "vite": "^6.0.0"
package/src/global.d.ts CHANGED
@@ -1,8 +1,10 @@
1
1
  import type { Manifest } from '@tanstack/router-core'
2
+ import type { Rollup } from 'vite'
2
3
 
3
4
  /* eslint-disable no-var */
4
5
  declare global {
5
6
  var TSS_APP_BASE: string
6
7
  var TSS_ROUTES_MANIFEST: Manifest
8
+ var TSS_CLIENT_BUNDLE: Rollup.OutputBundle
7
9
  }
8
10
  export {}
package/src/plugin.ts CHANGED
@@ -221,6 +221,16 @@ export function TanStackStartVitePluginCore(
221
221
  startManifestPlugin(startConfig),
222
222
  devServerPlugin(),
223
223
  nitroPlugin(startConfig, () => ssrBundle),
224
+ {
225
+ name: 'tanstack-start:core:capture-client-bundle',
226
+ applyToEnvironment(e) {
227
+ return e.config.consumer === 'client'
228
+ },
229
+ enforce: 'post',
230
+ generateBundle(_options, bundle) {
231
+ globalThis.TSS_CLIENT_BUNDLE = bundle
232
+ },
233
+ },
224
234
  ]
225
235
  }
226
236
 
@@ -1,28 +1,22 @@
1
- import { readFileSync } from 'node:fs'
2
1
  import path from 'node:path'
3
2
  import { joinURL } from 'ufo'
4
3
  import { rootRouteId } from '@tanstack/router-core'
5
4
  import { VIRTUAL_MODULES } from '@tanstack/start-server-core'
5
+ import { tsrSplit } from '@tanstack/router-plugin'
6
6
  import { resolveViteId } from '../utils'
7
- import { CLIENT_DIST_DIR } from '../constants'
8
- import type {
9
- PluginOption,
10
- ResolvedConfig,
11
- Manifest as ViteManifest,
12
- ManifestChunk as ViteManifestChunk,
13
- } from 'vite'
7
+ import type { PluginOption, ResolvedConfig, Rollup } from 'vite'
14
8
  import type { RouterManagedTag } from '@tanstack/router-core'
15
9
  import type { TanStackStartOutputConfig } from '../plugin'
16
10
 
17
- const getCSSRecursively = (
18
- file: ViteManifestChunk,
19
- filesByRouteFilePath: ViteManifest,
11
+ export const getCSSRecursively = (
12
+ chunk: Rollup.OutputChunk,
13
+ chunksByFileName: Map<string, Rollup.OutputChunk>,
20
14
  basePath: string,
21
15
  ) => {
22
16
  const result: Array<RouterManagedTag> = []
23
17
 
24
18
  // Get all css imports from the file
25
- for (const cssFile of file.css ?? []) {
19
+ for (const cssFile of chunk.viteMetadata?.importedCss ?? []) {
26
20
  result.push({
27
21
  tag: 'link',
28
22
  attrs: {
@@ -34,11 +28,11 @@ const getCSSRecursively = (
34
28
  }
35
29
 
36
30
  // Recursively get CSS from imports
37
- for (const imp of file.imports ?? []) {
38
- const importInfo = filesByRouteFilePath[imp]
39
- if (importInfo) {
31
+ for (const importedFileName of chunk.imports) {
32
+ const importedChunk = chunksByFileName.get(importedFileName)
33
+ if (importedChunk) {
40
34
  result.push(
41
- ...getCSSRecursively(importInfo, filesByRouteFilePath, basePath),
35
+ ...getCSSRecursively(importedChunk, chunksByFileName, basePath),
42
36
  )
43
37
  }
44
38
  }
@@ -59,9 +53,6 @@ export function startManifestPlugin(
59
53
  configResolved(resolvedConfig) {
60
54
  config = resolvedConfig
61
55
  },
62
- // configEnvironment(env, envConfig) {
63
- // config = envConfig.
64
- // },
65
56
  resolveId: {
66
57
  filter: { id: new RegExp(VIRTUAL_MODULES.startManifest) },
67
58
  handler(id) {
@@ -93,106 +84,110 @@ export function startManifestPlugin(
93
84
  // This is the basepath for the application
94
85
  const APP_BASE = globalThis.TSS_APP_BASE
95
86
 
96
- const clientViteManifestPath = path.resolve(
97
- opts.root,
98
- CLIENT_DIST_DIR,
99
- '.vite',
100
- 'manifest.json',
101
- )
102
-
103
- let viteManifest: ViteManifest
104
- try {
105
- viteManifest = JSON.parse(
106
- readFileSync(clientViteManifestPath, 'utf-8'),
107
- )
108
- } catch (err) {
109
- console.error(err)
110
- throw new Error(
111
- `Could not find the production client vite manifest at '${clientViteManifestPath}'!`,
112
- )
113
- }
114
-
115
87
  // This the manifest pulled from the generated route tree and later used by the Router.
116
- // i.e what's located in `src/generatedRouteTree.gen.ts`
88
+ // i.e what's located in `src/routeTree.gen.ts`
117
89
  const routeTreeRoutes = globalThis.TSS_ROUTES_MANIFEST.routes
118
90
 
119
91
  // This is where hydration will start, from when the SSR'd page reaches the browser.
120
92
  // By default, this'd be the virtual entry of `/~start/default-client-entry.tsx`, unless a custom entry is provided.
121
- let entryFile: ViteManifestChunk | undefined
122
-
123
- const filesByRouteFilePath: ViteManifest = Object.fromEntries(
124
- Object.entries(viteManifest).map(([k, v]) => {
125
- if (v.isEntry) {
126
- if (entryFile !== undefined) {
127
- console.error(
128
- `multiple entries detected`,
129
- entryFile.file,
130
- v.file,
93
+ let entryFile: Rollup.OutputChunk | undefined
94
+
95
+ const clientBundle = globalThis.TSS_CLIENT_BUNDLE
96
+ const chunksByFileName = new Map<string, Rollup.OutputChunk>()
97
+
98
+ const routeChunks: Record<
99
+ string /** fullPath of route file **/,
100
+ Array<Rollup.OutputChunk>
101
+ > = {}
102
+ for (const bundleEntry of Object.values(clientBundle)) {
103
+ if (bundleEntry.type === 'chunk') {
104
+ chunksByFileName.set(bundleEntry.fileName, bundleEntry)
105
+ if (bundleEntry.isEntry) {
106
+ if (entryFile) {
107
+ throw new Error(
108
+ `multiple entries detected: ${entryFile.fileName} ${bundleEntry.fileName}`,
131
109
  )
132
110
  }
133
- entryFile = v
111
+ entryFile = bundleEntry
134
112
  }
135
-
136
- const rPath = k.split('?')[0]
137
-
138
- return [rPath, v]
139
- }, {}),
140
- )
141
-
142
- const routesDirectoryFromRoot = path.relative(
143
- opts.root,
144
- opts.tsr.routesDirectory,
145
- )
113
+ const routePieces = bundleEntry.moduleIds.flatMap((m) => {
114
+ const [id, query] = m.split('?')
115
+ if (id === undefined) {
116
+ throw new Error('expected id to be defined')
117
+ }
118
+ if (query === undefined) {
119
+ return []
120
+ }
121
+ const searchParams = new URLSearchParams(query)
122
+ const split = searchParams.get(tsrSplit)
123
+
124
+ if (split !== null) {
125
+ return {
126
+ id,
127
+ split,
128
+ }
129
+ }
130
+ return []
131
+ })
132
+ if (routePieces.length > 0) {
133
+ routePieces.forEach((r) => {
134
+ let array = routeChunks[r.id]
135
+ if (array === undefined) {
136
+ array = []
137
+ routeChunks[r.id] = array
138
+ }
139
+ array.push(bundleEntry)
140
+ })
141
+ }
142
+ }
143
+ }
146
144
 
147
145
  // Add preloads to the routes from the vite manifest
148
146
  Object.entries(routeTreeRoutes).forEach(([routeId, v]) => {
149
- const file =
150
- filesByRouteFilePath[
151
- path.posix.join(routesDirectoryFromRoot, v.filePath as string)
152
- ]
153
-
154
- if (file) {
155
- // Map the relevant imports to their route paths,
156
- // so that it can be imported in the browser.
157
- const preloads = (file.imports ?? []).map((d) => {
158
- const assetPath = joinURL(APP_BASE, viteManifest[d]!.file)
159
- return assetPath
147
+ if (!v.filePath) {
148
+ throw new Error(`expected filePath to be set for ${routeId}`)
149
+ }
150
+ const chunks = routeChunks[v.filePath]
151
+ if (chunks) {
152
+ chunks.forEach((chunk) => {
153
+ // Map the relevant imports to their route paths,
154
+ // so that it can be imported in the browser.
155
+ const preloads = chunk.imports.map((d) => {
156
+ const assetPath = joinURL(APP_BASE, d)
157
+ return assetPath
158
+ })
159
+
160
+ // Since this is the most important JS entry for the route,
161
+ // it should be moved to the front of the preloads so that
162
+ // it has the best chance of being loaded first.
163
+ preloads.unshift(path.join(APP_BASE, chunk.fileName))
164
+
165
+ const cssAssetsList = getCSSRecursively(
166
+ chunk,
167
+ chunksByFileName,
168
+ APP_BASE,
169
+ )
170
+
171
+ routeTreeRoutes[routeId] = {
172
+ ...v,
173
+ assets: [...(v.assets || []), ...cssAssetsList],
174
+ preloads: [...(v.preloads || []), ...preloads],
175
+ }
160
176
  })
161
-
162
- // Since this is the most important JS entry for the route,
163
- // it should be moved to the front of the preloads so that
164
- // it has the best chance of being loaded first.
165
- if (file.file) {
166
- preloads.unshift(path.join(APP_BASE, file.file))
167
- }
168
-
169
- const cssAssetsList = getCSSRecursively(
170
- file,
171
- filesByRouteFilePath,
172
- APP_BASE,
173
- )
174
-
175
- routeTreeRoutes[routeId] = {
176
- ...v,
177
- assets: [...(v.assets || []), ...cssAssetsList],
178
- preloads,
179
- }
180
177
  }
181
178
  })
182
179
 
183
180
  if (entryFile) {
184
181
  routeTreeRoutes[rootRouteId]!.preloads = [
185
- joinURL(APP_BASE, entryFile.file),
186
- ...(entryFile.imports?.map((d) =>
187
- joinURL(APP_BASE, viteManifest[d]!.file),
188
- ) || []),
182
+ joinURL(APP_BASE, entryFile.fileName),
183
+ ...entryFile.imports.map((d) => joinURL(APP_BASE, d)),
189
184
  ]
190
185
 
191
186
  // Gather all the CSS files from the entry file in
192
187
  // the `css` key and add them to the root route
193
188
  const entryCssAssetsList = getCSSRecursively(
194
189
  entryFile,
195
- filesByRouteFilePath,
190
+ chunksByFileName,
196
191
  APP_BASE,
197
192
  )
198
193
 
@@ -202,7 +197,7 @@ export function startManifestPlugin(
202
197
  {
203
198
  tag: 'script',
204
199
  attrs: {
205
- src: joinURL(APP_BASE, entryFile.file),
200
+ src: joinURL(APP_BASE, entryFile.fileName),
206
201
  type: 'module',
207
202
  },
208
203
  },
@@ -232,8 +227,7 @@ export function startManifestPlugin(
232
227
  }
233
228
  }
234
229
 
235
- // @ts-expect-error
236
- recurseRoute(routeTreeRoutes[rootRouteId])
230
+ recurseRoute(routeTreeRoutes[rootRouteId]!)
237
231
 
238
232
  const routesManifest = {
239
233
  routes: routeTreeRoutes,