@tanstack/router-plugin 1.124.2 → 1.125.0

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 (40) hide show
  1. package/dist/cjs/core/code-splitter/compilers.cjs +43 -21
  2. package/dist/cjs/core/code-splitter/compilers.cjs.map +1 -1
  3. package/dist/cjs/core/code-splitter/compilers.d.cts +3 -2
  4. package/dist/cjs/core/config.cjs +11 -1
  5. package/dist/cjs/core/config.cjs.map +1 -1
  6. package/dist/cjs/core/config.d.cts +45 -0
  7. package/dist/cjs/core/router-code-splitter-plugin.cjs +20 -4
  8. package/dist/cjs/core/router-code-splitter-plugin.cjs.map +1 -1
  9. package/dist/cjs/core/router-generator-plugin.cjs +6 -3
  10. package/dist/cjs/core/router-generator-plugin.cjs.map +1 -1
  11. package/dist/cjs/core/router-hmr-plugin.cjs +25 -2
  12. package/dist/cjs/core/router-hmr-plugin.cjs.map +1 -1
  13. package/dist/cjs/core/router-hmr-plugin.d.cts +1 -6
  14. package/dist/cjs/esbuild.d.cts +20 -0
  15. package/dist/cjs/rspack.d.cts +20 -0
  16. package/dist/cjs/vite.d.cts +25 -0
  17. package/dist/cjs/webpack.d.cts +20 -0
  18. package/dist/esm/core/code-splitter/compilers.d.ts +3 -2
  19. package/dist/esm/core/code-splitter/compilers.js +43 -21
  20. package/dist/esm/core/code-splitter/compilers.js.map +1 -1
  21. package/dist/esm/core/config.d.ts +45 -0
  22. package/dist/esm/core/config.js +11 -1
  23. package/dist/esm/core/config.js.map +1 -1
  24. package/dist/esm/core/router-code-splitter-plugin.js +20 -4
  25. package/dist/esm/core/router-code-splitter-plugin.js.map +1 -1
  26. package/dist/esm/core/router-generator-plugin.js +6 -3
  27. package/dist/esm/core/router-generator-plugin.js.map +1 -1
  28. package/dist/esm/core/router-hmr-plugin.d.ts +1 -6
  29. package/dist/esm/core/router-hmr-plugin.js +25 -2
  30. package/dist/esm/core/router-hmr-plugin.js.map +1 -1
  31. package/dist/esm/esbuild.d.ts +20 -0
  32. package/dist/esm/rspack.d.ts +20 -0
  33. package/dist/esm/vite.d.ts +25 -0
  34. package/dist/esm/webpack.d.ts +20 -0
  35. package/package.json +4 -4
  36. package/src/core/code-splitter/compilers.ts +52 -35
  37. package/src/core/config.ts +25 -0
  38. package/src/core/router-code-splitter-plugin.ts +20 -3
  39. package/src/core/router-generator-plugin.ts +6 -7
  40. package/src/core/router-hmr-plugin.ts +27 -3
@@ -1 +1 @@
1
- {"version":3,"file":"compilers.js","sources":["../../../../src/core/code-splitter/compilers.ts"],"sourcesContent":["import * as t from '@babel/types'\nimport babel from '@babel/core'\nimport * as template from '@babel/template'\nimport {\n deadCodeElimination,\n findReferencedIdentifiers,\n} from 'babel-dead-code-elimination'\nimport { generateFromAst, parseAst } from '@tanstack/router-utils'\nimport { tsrSplit } from '../constants'\nimport { routeHmrStatement } from '../route-hmr-statement'\nimport { createIdentifier } from './path-ids'\nimport { getFrameworkOptions } from './framework-options'\nimport type { GeneratorResult, ParseAstOptions } from '@tanstack/router-utils'\nimport type { CodeSplitGroupings, SplitRouteIdentNodes } from '../constants'\nimport type { Config } from '../config'\n\ntype SplitNodeMeta = {\n routeIdent: SplitRouteIdentNodes\n splitStrategy: 'lazyFn' | 'lazyRouteComponent'\n localImporterIdent: string\n exporterIdent: string\n localExporterIdent: string\n}\nconst SPLIT_NODES_CONFIG = new Map<SplitRouteIdentNodes, SplitNodeMeta>([\n [\n 'loader',\n {\n routeIdent: 'loader',\n localImporterIdent: '$$splitLoaderImporter', // const $$splitLoaderImporter = () => import('...')\n splitStrategy: 'lazyFn',\n localExporterIdent: 'SplitLoader', // const SplitLoader = ...\n exporterIdent: 'loader', // export { SplitLoader as loader }\n },\n ],\n [\n 'component',\n {\n routeIdent: 'component',\n localImporterIdent: '$$splitComponentImporter', // const $$splitComponentImporter = () => import('...')\n splitStrategy: 'lazyRouteComponent',\n localExporterIdent: 'SplitComponent', // const SplitComponent = ...\n exporterIdent: 'component', // export { SplitComponent as component }\n },\n ],\n [\n 'pendingComponent',\n {\n routeIdent: 'pendingComponent',\n localImporterIdent: '$$splitPendingComponentImporter', // const $$splitPendingComponentImporter = () => import('...')\n splitStrategy: 'lazyRouteComponent',\n localExporterIdent: 'SplitPendingComponent', // const SplitPendingComponent = ...\n exporterIdent: 'pendingComponent', // export { SplitPendingComponent as pendingComponent }\n },\n ],\n [\n 'errorComponent',\n {\n routeIdent: 'errorComponent',\n localImporterIdent: '$$splitErrorComponentImporter', // const $$splitErrorComponentImporter = () => import('...')\n splitStrategy: 'lazyRouteComponent',\n localExporterIdent: 'SplitErrorComponent', // const SplitErrorComponent = ...\n exporterIdent: 'errorComponent', // export { SplitErrorComponent as errorComponent }\n },\n ],\n [\n 'notFoundComponent',\n {\n routeIdent: 'notFoundComponent',\n localImporterIdent: '$$splitNotFoundComponentImporter', // const $$splitNotFoundComponentImporter = () => import('...')\n splitStrategy: 'lazyRouteComponent',\n localExporterIdent: 'SplitNotFoundComponent', // const SplitNotFoundComponent = ...\n exporterIdent: 'notFoundComponent', // export { SplitNotFoundComponent as notFoundComponent }\n },\n ],\n])\nconst KNOWN_SPLIT_ROUTE_IDENTS = [...SPLIT_NODES_CONFIG.keys()] as const\n\nfunction addSplitSearchParamToFilename(\n filename: string,\n grouping: Array<string>,\n) {\n const [bareFilename] = filename.split('?')\n\n const params = new URLSearchParams()\n params.append(tsrSplit, createIdentifier(grouping))\n\n return `${bareFilename}?${params.toString()}`\n}\n\nfunction removeSplitSearchParamFromFilename(filename: string) {\n const [bareFilename] = filename.split('?')\n return bareFilename!\n}\n\nexport function compileCodeSplitReferenceRoute(\n opts: ParseAstOptions & {\n runtimeEnv: 'dev' | 'prod'\n codeSplitGroupings: CodeSplitGroupings\n targetFramework: Config['target']\n filename: string\n id: string\n },\n): GeneratorResult {\n const ast = parseAst(opts)\n\n const refIdents = findReferencedIdentifiers(ast)\n\n function findIndexForSplitNode(str: string) {\n return opts.codeSplitGroupings.findIndex((group) =>\n group.includes(str as any),\n )\n }\n\n const frameworkOptions = getFrameworkOptions(opts.targetFramework)\n const PACKAGE = frameworkOptions.package\n const LAZY_ROUTE_COMPONENT_IDENT = frameworkOptions.idents.lazyRouteComponent\n const LAZY_FN_IDENT = frameworkOptions.idents.lazyFn\n\n babel.traverse(ast, {\n Program: {\n enter(programPath) {\n /**\n * If the component for the route is being imported from\n * another file, this is to track the path to that file\n * the path itself doesn't matter, we just need to keep\n * track of it so that we can remove it from the imports\n * list if it's not being used like:\n *\n * `import '../shared/imported'`\n */\n const removableImportPaths = new Set<string>([])\n\n programPath.traverse({\n CallExpression: (path) => {\n if (!t.isIdentifier(path.node.callee)) {\n return\n }\n\n if (\n !(\n path.node.callee.name === 'createRoute' ||\n path.node.callee.name === 'createFileRoute'\n )\n ) {\n return\n }\n\n function babelHandleReference(routeOptions: t.Node | undefined) {\n const hasImportedOrDefinedIdentifier = (name: string) => {\n return programPath.scope.hasBinding(name)\n }\n\n if (t.isObjectExpression(routeOptions)) {\n routeOptions.properties.forEach((prop) => {\n if (t.isObjectProperty(prop)) {\n if (t.isIdentifier(prop.key)) {\n // If the user has not specified a split grouping for this key\n // then we should not split it\n const codeSplitGroupingByKey = findIndexForSplitNode(\n prop.key.name,\n )\n if (codeSplitGroupingByKey === -1) {\n return\n }\n const codeSplitGroup = [\n ...new Set(\n opts.codeSplitGroupings[codeSplitGroupingByKey],\n ),\n ]\n\n const key = prop.key.name\n // find key in nodeSplitConfig\n const isNodeConfigAvailable = SPLIT_NODES_CONFIG.has(\n key as any,\n )\n\n if (!isNodeConfigAvailable) {\n return\n }\n\n const splitNodeMeta = SPLIT_NODES_CONFIG.get(key as any)!\n\n // We need to extract the existing search params from the filename, if any\n // and add the relevant codesplitPrefix to them, then write them back to the filename\n const splitUrl = addSplitSearchParamToFilename(\n opts.filename,\n codeSplitGroup,\n )\n\n if (\n splitNodeMeta.splitStrategy === 'lazyRouteComponent'\n ) {\n const value = prop.value\n\n let shouldSplit = true\n\n if (t.isIdentifier(value)) {\n const existingImportPath =\n getImportSpecifierAndPathFromLocalName(\n programPath,\n value.name,\n ).path\n if (existingImportPath) {\n removableImportPaths.add(existingImportPath)\n }\n\n // exported identifiers should not be split\n // since they are already being imported\n // and need to be retained in the compiled file\n const isExported = hasExport(ast, value)\n shouldSplit = !isExported\n\n if (shouldSplit) {\n removeIdentifierLiteral(path, value)\n }\n }\n\n if (!shouldSplit) {\n return\n }\n\n // Prepend the import statement to the program along with the importer function\n // Check to see if lazyRouteComponent is already imported before attempting\n // to import it again\n\n if (\n !hasImportedOrDefinedIdentifier(\n LAZY_ROUTE_COMPONENT_IDENT,\n )\n ) {\n programPath.unshiftContainer('body', [\n template.statement(\n `import { ${LAZY_ROUTE_COMPONENT_IDENT} } from '${PACKAGE}'`,\n )(),\n ])\n }\n\n // Check to see if the importer function is already defined\n // If not, define it with the dynamic import statement\n if (\n !hasImportedOrDefinedIdentifier(\n splitNodeMeta.localImporterIdent,\n )\n ) {\n programPath.unshiftContainer('body', [\n template.statement(\n `const ${splitNodeMeta.localImporterIdent} = () => import('${splitUrl}')`,\n )(),\n ])\n }\n\n // If it's a component, we need to pass the function to check the Route.ssr value\n if (key === 'component') {\n prop.value = template.expression(\n `${LAZY_ROUTE_COMPONENT_IDENT}(${splitNodeMeta.localImporterIdent}, '${splitNodeMeta.exporterIdent}', () => Route.ssr)`,\n )()\n } else {\n prop.value = template.expression(\n `${LAZY_ROUTE_COMPONENT_IDENT}(${splitNodeMeta.localImporterIdent}, '${splitNodeMeta.exporterIdent}')`,\n )()\n }\n\n // add HMR handling\n if (opts.runtimeEnv !== 'prod') {\n programPath.pushContainer('body', routeHmrStatement)\n }\n }\n\n if (splitNodeMeta.splitStrategy === 'lazyFn') {\n const value = prop.value\n\n let shouldSplit = true\n\n if (t.isIdentifier(value)) {\n const existingImportPath =\n getImportSpecifierAndPathFromLocalName(\n programPath,\n value.name,\n ).path\n if (existingImportPath) {\n removableImportPaths.add(existingImportPath)\n }\n\n // exported identifiers should not be split\n // since they are already being imported\n // and need to be retained in the compiled file\n const isExported = hasExport(ast, value)\n shouldSplit = !isExported\n\n if (shouldSplit) {\n removeIdentifierLiteral(path, value)\n }\n }\n\n if (!shouldSplit) {\n return\n }\n\n // Prepend the import statement to the program along with the importer function\n if (!hasImportedOrDefinedIdentifier(LAZY_FN_IDENT)) {\n programPath.unshiftContainer(\n 'body',\n template.smart(\n `import { ${LAZY_FN_IDENT} } from '${PACKAGE}'`,\n )(),\n )\n }\n\n // Check to see if the importer function is already defined\n // If not, define it with the dynamic import statement\n if (\n !hasImportedOrDefinedIdentifier(\n splitNodeMeta.localImporterIdent,\n )\n ) {\n programPath.unshiftContainer('body', [\n template.statement(\n `const ${splitNodeMeta.localImporterIdent} = () => import('${splitUrl}')`,\n )(),\n ])\n }\n\n // Add the lazyFn call with the dynamic import to the prop value\n prop.value = template.expression(\n `${LAZY_FN_IDENT}(${splitNodeMeta.localImporterIdent}, '${splitNodeMeta.exporterIdent}')`,\n )()\n }\n }\n }\n\n programPath.scope.crawl()\n })\n }\n }\n\n if (t.isCallExpression(path.parentPath.node)) {\n // createFileRoute('/')({ ... })\n const options = resolveIdentifier(\n path,\n path.parentPath.node.arguments[0],\n )\n\n babelHandleReference(options)\n } else if (t.isVariableDeclarator(path.parentPath.node)) {\n // createFileRoute({ ... })\n const caller = resolveIdentifier(path, path.parentPath.node.init)\n\n if (t.isCallExpression(caller)) {\n const options = resolveIdentifier(path, caller.arguments[0])\n babelHandleReference(options)\n }\n }\n },\n })\n\n /**\n * If the component for the route is being imported,\n * and it's not being used, remove the import statement\n * from the program, by checking that the import has no\n * specifiers\n */\n if (removableImportPaths.size > 0) {\n programPath.traverse({\n ImportDeclaration(path) {\n if (path.node.specifiers.length > 0) return\n if (removableImportPaths.has(path.node.source.value)) {\n path.remove()\n }\n },\n })\n }\n },\n },\n })\n\n deadCodeElimination(ast, refIdents)\n\n return generateFromAst(ast, {\n sourceMaps: true,\n sourceFileName: opts.filename,\n filename: opts.filename,\n })\n}\n\nexport function compileCodeSplitVirtualRoute(\n opts: ParseAstOptions & {\n splitTargets: Array<SplitRouteIdentNodes>\n filename: string\n },\n): GeneratorResult {\n const ast = parseAst(opts)\n const refIdents = findReferencedIdentifiers(ast)\n\n const intendedSplitNodes = new Set(opts.splitTargets)\n\n const knownExportedIdents = new Set<string>()\n\n babel.traverse(ast, {\n Program: {\n enter(programPath) {\n const trackedNodesToSplitByType: Record<\n SplitRouteIdentNodes,\n { node: t.Node | undefined; meta: SplitNodeMeta } | undefined\n > = {\n component: undefined,\n loader: undefined,\n pendingComponent: undefined,\n errorComponent: undefined,\n notFoundComponent: undefined,\n }\n\n // Find and track all the known split-able nodes\n programPath.traverse({\n CallExpression: (path) => {\n if (!t.isIdentifier(path.node.callee)) {\n return\n }\n\n if (\n !(\n path.node.callee.name === 'createRoute' ||\n path.node.callee.name === 'createFileRoute'\n )\n ) {\n return\n }\n\n function babelHandleVirtual(options: t.Node | undefined) {\n if (t.isObjectExpression(options)) {\n options.properties.forEach((prop) => {\n if (t.isObjectProperty(prop)) {\n // do not use `intendedSplitNodes` here\n // since we have special considerations that need\n // to be accounted for like (not splitting exported identifiers)\n KNOWN_SPLIT_ROUTE_IDENTS.forEach((splitType) => {\n if (\n !t.isIdentifier(prop.key) ||\n prop.key.name !== splitType\n ) {\n return\n }\n\n const value = prop.value\n\n let isExported = false\n if (t.isIdentifier(value)) {\n isExported = hasExport(ast, value)\n if (isExported) {\n knownExportedIdents.add(value.name)\n }\n }\n\n // If the node is exported, we need to remove\n // the export from the split file\n if (isExported && t.isIdentifier(value)) {\n removeExports(ast, value)\n } else {\n const meta = SPLIT_NODES_CONFIG.get(splitType)!\n trackedNodesToSplitByType[splitType] = {\n node: prop.value,\n meta,\n }\n }\n })\n }\n })\n\n // Remove all of the options\n options.properties = []\n }\n }\n\n if (t.isCallExpression(path.parentPath.node)) {\n // createFileRoute('/')({ ... })\n const options = resolveIdentifier(\n path,\n path.parentPath.node.arguments[0],\n )\n\n babelHandleVirtual(options)\n } else if (t.isVariableDeclarator(path.parentPath.node)) {\n // createFileRoute({ ... })\n const caller = resolveIdentifier(path, path.parentPath.node.init)\n\n if (t.isCallExpression(caller)) {\n const options = resolveIdentifier(path, caller.arguments[0])\n babelHandleVirtual(options)\n }\n }\n },\n })\n\n // Start the transformation to only exported the intended split nodes\n intendedSplitNodes.forEach((SPLIT_TYPE) => {\n const splitKey = trackedNodesToSplitByType[SPLIT_TYPE]\n\n if (!splitKey) {\n return\n }\n\n let splitNode = splitKey.node\n const splitMeta = splitKey.meta\n\n while (t.isIdentifier(splitNode)) {\n const binding = programPath.scope.getBinding(splitNode.name)\n splitNode = binding?.path.node\n }\n\n // Add the node to the program\n if (splitNode) {\n if (t.isFunctionDeclaration(splitNode)) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitMeta.localExporterIdent),\n t.functionExpression(\n splitNode.id || null, // Anonymize the function expression\n splitNode.params,\n splitNode.body,\n splitNode.generator,\n splitNode.async,\n ),\n ),\n ]),\n )\n } else if (\n t.isFunctionExpression(splitNode) ||\n t.isArrowFunctionExpression(splitNode)\n ) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitMeta.localExporterIdent),\n splitNode as any,\n ),\n ]),\n )\n } else if (\n t.isImportSpecifier(splitNode) ||\n t.isImportDefaultSpecifier(splitNode)\n ) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitMeta.localExporterIdent),\n splitNode.local,\n ),\n ]),\n )\n } else if (t.isVariableDeclarator(splitNode)) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitMeta.localExporterIdent),\n splitNode.init,\n ),\n ]),\n )\n } else if (t.isCallExpression(splitNode)) {\n const outputSplitNodeCode = generateFromAst(splitNode).code\n const splitNodeAst = babel.parse(outputSplitNodeCode)\n\n if (!splitNodeAst) {\n throw new Error(\n `Failed to parse the generated code for \"${SPLIT_TYPE}\" in the node type \"${splitNode.type}\"`,\n )\n }\n\n const statement = splitNodeAst.program.body[0]\n\n if (!statement) {\n throw new Error(\n `Failed to parse the generated code for \"${SPLIT_TYPE}\" in the node type \"${splitNode.type}\" as no statement was found in the program body`,\n )\n }\n\n if (t.isExpressionStatement(statement)) {\n const expression = statement.expression\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitMeta.localExporterIdent),\n expression,\n ),\n ]),\n )\n } else {\n throw new Error(\n `Unexpected expression type encounter for \"${SPLIT_TYPE}\" in the node type \"${splitNode.type}\"`,\n )\n }\n } else if (t.isConditionalExpression(splitNode)) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitMeta.localExporterIdent),\n splitNode,\n ),\n ]),\n )\n } else if (t.isTSAsExpression(splitNode)) {\n // remove the type assertion\n splitNode = splitNode.expression\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitMeta.localExporterIdent),\n splitNode,\n ),\n ]),\n )\n } else {\n console.info('Unexpected splitNode type:', splitNode)\n throw new Error(`Unexpected splitNode type ☝️: ${splitNode.type}`)\n }\n }\n\n // If the splitNode exists at the top of the program\n // then we need to remove that copy\n programPath.node.body = programPath.node.body.filter((node) => {\n return node !== splitNode\n })\n\n // Export the node\n programPath.pushContainer('body', [\n t.exportNamedDeclaration(null, [\n t.exportSpecifier(\n t.identifier(splitMeta.localExporterIdent), // local variable name\n t.identifier(splitMeta.exporterIdent), // as what name it should be exported as\n ),\n ]),\n ])\n })\n\n // convert exports to imports from the original file\n programPath.traverse({\n ExportNamedDeclaration(path) {\n // e.g. export const x = 1 or export { x }\n // becomes\n // import { x } from '${opts.id}'\n\n if (path.node.declaration) {\n if (t.isVariableDeclaration(path.node.declaration)) {\n path.replaceWith(\n t.importDeclaration(\n path.node.declaration.declarations.map((decl) =>\n t.importSpecifier(\n t.identifier((decl.id as any).name),\n t.identifier((decl.id as any).name),\n ),\n ),\n t.stringLiteral(\n removeSplitSearchParamFromFilename(opts.filename),\n ),\n ),\n )\n }\n }\n },\n })\n },\n },\n })\n\n deadCodeElimination(ast, refIdents)\n\n // if there are exported identifiers, then we need to add a warning\n // to the file to let the user know that the exported identifiers\n // will not in the split file but in the original file, therefore\n // increasing the bundle size\n if (knownExportedIdents.size > 0) {\n const list = Array.from(knownExportedIdents).reduce((str, ident) => {\n str += `\\n- ${ident}`\n return str\n }, '')\n\n const warningMessage = `These exports from \"${opts.filename}\" are not being code-split and will increase your bundle size: ${list}\\nThese should either have their export statements removed or be imported from another file that is not a route.`\n console.warn(warningMessage)\n\n // append this warning to the file using a template\n if (process.env.NODE_ENV !== 'production') {\n const warningTemplate = template.statement(\n `console.warn(${JSON.stringify(warningMessage)})`,\n )()\n ast.program.body.unshift(warningTemplate)\n }\n }\n\n return generateFromAst(ast, {\n sourceMaps: true,\n sourceFileName: opts.filename,\n filename: opts.filename,\n })\n}\n\n/**\n * This function should read get the options from by searching for the key `codeSplitGroupings`\n * on createFileRoute and return it's values if it exists, else return undefined\n */\nexport function detectCodeSplitGroupingsFromRoute(opts: ParseAstOptions): {\n groupings: CodeSplitGroupings | undefined\n} {\n const ast = parseAst(opts)\n\n let codeSplitGroupings: CodeSplitGroupings | undefined = undefined\n\n babel.traverse(ast, {\n Program: {\n enter(programPath) {\n programPath.traverse({\n CallExpression(path) {\n if (!t.isIdentifier(path.node.callee)) {\n return\n }\n\n if (\n !(\n path.node.callee.name === 'createRoute' ||\n path.node.callee.name === 'createFileRoute'\n )\n ) {\n return\n }\n\n function babelHandleSplittingGroups(\n routeOptions: t.Node | undefined,\n ) {\n if (t.isObjectExpression(routeOptions)) {\n routeOptions.properties.forEach((prop) => {\n if (t.isObjectProperty(prop)) {\n if (t.isIdentifier(prop.key)) {\n if (prop.key.name === 'codeSplitGroupings') {\n const value = prop.value\n\n if (t.isArrayExpression(value)) {\n codeSplitGroupings = value.elements.map((group) => {\n if (t.isArrayExpression(group)) {\n return group.elements.map((node) => {\n if (!t.isStringLiteral(node)) {\n throw new Error(\n 'You must provide a string literal for the codeSplitGroupings',\n )\n }\n\n return node.value\n }) as Array<SplitRouteIdentNodes>\n }\n\n throw new Error(\n 'You must provide arrays with codeSplitGroupings options.',\n )\n })\n } else {\n throw new Error(\n 'You must provide an array of arrays for the codeSplitGroupings.',\n )\n }\n }\n }\n }\n })\n }\n }\n\n // Extracting the codeSplitGroupings\n if (t.isCallExpression(path.parentPath.node)) {\n // createFileRoute('/')({ ... })\n const options = resolveIdentifier(\n path,\n path.parentPath.node.arguments[0],\n )\n\n babelHandleSplittingGroups(options)\n } else if (t.isVariableDeclarator(path.parentPath.node)) {\n // createFileRoute({ ... })\n const caller = resolveIdentifier(path, path.parentPath.node.init)\n\n if (t.isCallExpression(caller)) {\n const options = resolveIdentifier(path, caller.arguments[0])\n babelHandleSplittingGroups(options)\n }\n }\n },\n })\n },\n },\n })\n\n return { groupings: codeSplitGroupings }\n}\n\nfunction getImportSpecifierAndPathFromLocalName(\n programPath: babel.NodePath<t.Program>,\n name: string,\n): {\n specifier:\n | t.ImportSpecifier\n | t.ImportDefaultSpecifier\n | t.ImportNamespaceSpecifier\n | null\n path: string | null\n} {\n let specifier:\n | t.ImportSpecifier\n | t.ImportDefaultSpecifier\n | t.ImportNamespaceSpecifier\n | null = null\n let path: string | null = null\n\n programPath.traverse({\n ImportDeclaration(importPath) {\n const found = importPath.node.specifiers.find(\n (targetSpecifier) => targetSpecifier.local.name === name,\n )\n if (found) {\n specifier = found\n path = importPath.node.source.value\n }\n },\n })\n\n return { specifier, path }\n}\n\n// Reusable function to get literal value or resolve variable to literal\nfunction resolveIdentifier(path: any, node: any): t.Node | undefined {\n if (t.isIdentifier(node)) {\n const binding = path.scope.getBinding(node.name)\n if (\n binding\n // && binding.kind === 'const'\n ) {\n const declarator = binding.path.node\n if (t.isObjectExpression(declarator.init)) {\n return declarator.init\n } else if (t.isFunctionDeclaration(declarator.init)) {\n return declarator.init\n }\n }\n return undefined\n }\n\n return node\n}\n\nfunction removeIdentifierLiteral(path: any, node: any) {\n if (t.isIdentifier(node)) {\n const binding = path.scope.getBinding(node.name)\n if (binding) {\n binding.path.remove()\n }\n }\n}\n\nfunction hasExport(ast: t.File, node: t.Identifier): boolean {\n let found = false\n\n babel.traverse(ast, {\n ExportNamedDeclaration(path) {\n if (path.node.declaration) {\n // declared as `const loaderFn = () => {}`\n if (t.isVariableDeclaration(path.node.declaration)) {\n path.node.declaration.declarations.forEach((decl) => {\n if (t.isVariableDeclarator(decl)) {\n if (t.isIdentifier(decl.id)) {\n if (decl.id.name === node.name) {\n found = true\n }\n }\n }\n })\n }\n\n // declared as `function loaderFn() {}`\n if (t.isFunctionDeclaration(path.node.declaration)) {\n if (t.isIdentifier(path.node.declaration.id)) {\n if (path.node.declaration.id.name === node.name) {\n found = true\n }\n }\n }\n }\n },\n ExportDefaultDeclaration(path) {\n // declared as `export default loaderFn`\n if (t.isIdentifier(path.node.declaration)) {\n if (path.node.declaration.name === node.name) {\n found = true\n }\n }\n\n // declared as `export default function loaderFn() {}`\n if (t.isFunctionDeclaration(path.node.declaration)) {\n if (t.isIdentifier(path.node.declaration.id)) {\n if (path.node.declaration.id.name === node.name) {\n found = true\n }\n }\n }\n },\n })\n\n return found\n}\n\nfunction removeExports(ast: t.File, node: t.Identifier): boolean {\n let removed = false\n\n // The checks use sequential if/else if statements since it\n // directly mutates the AST and as such doing normal checks\n // (using only if statements) could lead to a situation where\n // `path.node` is null since it has been already removed from\n // the program tree but typescript doesn't know that.\n babel.traverse(ast, {\n ExportNamedDeclaration(path) {\n if (path.node.declaration) {\n if (t.isVariableDeclaration(path.node.declaration)) {\n // declared as `const loaderFn = () => {}`\n path.node.declaration.declarations.forEach((decl) => {\n if (t.isVariableDeclarator(decl)) {\n if (t.isIdentifier(decl.id)) {\n if (decl.id.name === node.name) {\n path.remove()\n removed = true\n }\n }\n }\n })\n } else if (t.isFunctionDeclaration(path.node.declaration)) {\n // declared as `export const loaderFn = () => {}`\n if (t.isIdentifier(path.node.declaration.id)) {\n if (path.node.declaration.id.name === node.name) {\n path.remove()\n removed = true\n }\n }\n }\n }\n },\n ExportDefaultDeclaration(path) {\n // declared as `export default loaderFn`\n if (t.isIdentifier(path.node.declaration)) {\n if (path.node.declaration.name === node.name) {\n path.remove()\n removed = true\n }\n } else if (t.isFunctionDeclaration(path.node.declaration)) {\n // declared as `export default function loaderFn() {}`\n if (t.isIdentifier(path.node.declaration.id)) {\n if (path.node.declaration.id.name === node.name) {\n path.remove()\n removed = true\n }\n }\n }\n },\n })\n\n return removed\n}\n"],"names":[],"mappings":";;;;;;;;;AAuBA,MAAM,yCAAyB,IAAyC;AAAA,EACtE;AAAA,IACE;AAAA,IACA;AAAA,MACE,YAAY;AAAA,MACZ,oBAAoB;AAAA;AAAA,MACpB,eAAe;AAAA,MACf,oBAAoB;AAAA;AAAA,MACpB,eAAe;AAAA;AAAA,IAAA;AAAA,EAEnB;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,MACE,YAAY;AAAA,MACZ,oBAAoB;AAAA;AAAA,MACpB,eAAe;AAAA,MACf,oBAAoB;AAAA;AAAA,MACpB,eAAe;AAAA;AAAA,IAAA;AAAA,EAEnB;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,MACE,YAAY;AAAA,MACZ,oBAAoB;AAAA;AAAA,MACpB,eAAe;AAAA,MACf,oBAAoB;AAAA;AAAA,MACpB,eAAe;AAAA;AAAA,IAAA;AAAA,EAEnB;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,MACE,YAAY;AAAA,MACZ,oBAAoB;AAAA;AAAA,MACpB,eAAe;AAAA,MACf,oBAAoB;AAAA;AAAA,MACpB,eAAe;AAAA;AAAA,IAAA;AAAA,EAEnB;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,MACE,YAAY;AAAA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AA,EAAE,qBAAqB,IAAI,GAAG;AAChC,kBAAI,EAAE,aAAa,KAAK,EAAE,GAAG;AAC3B,oBAAI,KAAK,GAAG,SAAS,KAAK,MAAM;AAC9B,uBAAK,OAAO;AACF,4BAAA;AAAA,gBAAA;AAAA,cACZ;AAAA,YACF;AAAA,UACF,CACD;AAAA,QAAA,WACQ,EAAE,sBAAsB,KAAK,KAAK,WAAW,GAAG;AAEzD,cAAI,EAAE,aAAa,KAAK,KAAK,YAAY,EAAE,GAAG;AAC5C,gBAAI,KAAK,KAAK,YAAY,GAAG,SAAS,KAAK,MAAM;AAC/C,mBAAK,OAAO;AACF,wBAAA;AAAA,YAAA;AAAA,UACZ;AAAA,QACF;AAAA,MACF;AAAA,IAEJ;AAAA,IACA,yBAAyB,MAAM;AAE7B,UAAI,EAAE,aAAa,KAAK,KAAK,WAAW,GAAG;AACzC,YAAI,KAAK,KAAK,YAAY,SAAS,KAAK,MAAM;AAC5C,eAAK,OAAO;AACF,oBAAA;AAAA,QAAA;AAAA,MACZ,WACS,EAAE,sBAAsB,KAAK,KAAK,WAAW,GAAG;AAEzD,YAAI,EAAE,aAAa,KAAK,KAAK,YAAY,EAAE,GAAG;AAC5C,cAAI,KAAK,KAAK,YAAY,GAAG,SAAS,KAAK,MAAM;AAC/C,iBAAK,OAAO;AACF,sBAAA;AAAA,UAAA;AAAA,QACZ;AAAA,MACF;AAAA,IACF;AAAA,EACF,CACD;AAEM,SAAA;AACT;"}
1
+ {"version":3,"file":"compilers.js","sources":["../../../../src/core/code-splitter/compilers.ts"],"sourcesContent":["import * as t from '@babel/types'\nimport babel from '@babel/core'\nimport * as template from '@babel/template'\nimport {\n deadCodeElimination,\n findReferencedIdentifiers,\n} from 'babel-dead-code-elimination'\nimport { generateFromAst, parseAst } from '@tanstack/router-utils'\nimport { tsrSplit } from '../constants'\nimport { routeHmrStatement } from '../route-hmr-statement'\nimport { createIdentifier } from './path-ids'\nimport { getFrameworkOptions } from './framework-options'\nimport type { GeneratorResult, ParseAstOptions } from '@tanstack/router-utils'\nimport type { CodeSplitGroupings, SplitRouteIdentNodes } from '../constants'\nimport type { Config, DeletableNodes } from '../config'\n\ntype SplitNodeMeta = {\n routeIdent: SplitRouteIdentNodes\n splitStrategy: 'lazyFn' | 'lazyRouteComponent'\n localImporterIdent: string\n exporterIdent: string\n localExporterIdent: string\n}\nconst SPLIT_NODES_CONFIG = new Map<SplitRouteIdentNodes, SplitNodeMeta>([\n [\n 'loader',\n {\n routeIdent: 'loader',\n localImporterIdent: '$$splitLoaderImporter', // const $$splitLoaderImporter = () => import('...')\n splitStrategy: 'lazyFn',\n localExporterIdent: 'SplitLoader', // const SplitLoader = ...\n exporterIdent: 'loader', // export { SplitLoader as loader }\n },\n ],\n [\n 'component',\n {\n routeIdent: 'component',\n localImporterIdent: '$$splitComponentImporter', // const $$splitComponentImporter = () => import('...')\n splitStrategy: 'lazyRouteComponent',\n localExporterIdent: 'SplitComponent', // const SplitComponent = ...\n exporterIdent: 'component', // export { SplitComponent as component }\n },\n ],\n [\n 'pendingComponent',\n {\n routeIdent: 'pendingComponent',\n localImporterIdent: '$$splitPendingComponentImporter', // const $$splitPendingComponentImporter = () => import('...')\n splitStrategy: 'lazyRouteComponent',\n localExporterIdent: 'SplitPendingComponent', // const SplitPendingComponent = ...\n exporterIdent: 'pendingComponent', // export { SplitPendingComponent as pendingComponent }\n },\n ],\n [\n 'errorComponent',\n {\n routeIdent: 'errorComponent',\n localImporterIdent: '$$splitErrorComponentImporter', // const $$splitErrorComponentImporter = () => import('...')\n splitStrategy: 'lazyRouteComponent',\n localExporterIdent: 'SplitErrorComponent', // const SplitErrorComponent = ...\n exporterIdent: 'errorComponent', // export { SplitErrorComponent as errorComponent }\n },\n ],\n [\n 'notFoundComponent',\n {\n routeIdent: 'notFoundComponent',\n localImporterIdent: '$$splitNotFoundComponentImporter', // const $$splitNotFoundComponentImporter = () => import('...')\n splitStrategy: 'lazyRouteComponent',\n localExporterIdent: 'SplitNotFoundComponent', // const SplitNotFoundComponent = ...\n exporterIdent: 'notFoundComponent', // export { SplitNotFoundComponent as notFoundComponent }\n },\n ],\n])\nconst KNOWN_SPLIT_ROUTE_IDENTS = [...SPLIT_NODES_CONFIG.keys()] as const\n\nfunction addSplitSearchParamToFilename(\n filename: string,\n grouping: Array<string>,\n) {\n const [bareFilename] = filename.split('?')\n\n const params = new URLSearchParams()\n params.append(tsrSplit, createIdentifier(grouping))\n\n return `${bareFilename}?${params.toString()}`\n}\n\nfunction removeSplitSearchParamFromFilename(filename: string) {\n const [bareFilename] = filename.split('?')\n return bareFilename!\n}\n\nconst splittableCreateRouteFns = ['createFileRoute']\nconst unsplittableCreateRouteFns = [\n 'createRootRoute',\n 'createRootRouteWithContext',\n]\nconst allCreateRouteFns = [\n ...splittableCreateRouteFns,\n ...unsplittableCreateRouteFns,\n]\n\nexport function compileCodeSplitReferenceRoute(\n opts: ParseAstOptions & {\n codeSplitGroupings: CodeSplitGroupings\n deleteNodes?: Set<DeletableNodes>\n targetFramework: Config['target']\n filename: string\n id: string\n addHmr?: boolean\n },\n): GeneratorResult {\n const ast = parseAst(opts)\n\n const refIdents = findReferencedIdentifiers(ast)\n\n function findIndexForSplitNode(str: string) {\n return opts.codeSplitGroupings.findIndex((group) =>\n group.includes(str as any),\n )\n }\n\n const frameworkOptions = getFrameworkOptions(opts.targetFramework)\n const PACKAGE = frameworkOptions.package\n const LAZY_ROUTE_COMPONENT_IDENT = frameworkOptions.idents.lazyRouteComponent\n const LAZY_FN_IDENT = frameworkOptions.idents.lazyFn\n\n let createRouteFn: string\n\n babel.traverse(ast, {\n Program: {\n enter(programPath) {\n /**\n * If the component for the route is being imported from\n * another file, this is to track the path to that file\n * the path itself doesn't matter, we just need to keep\n * track of it so that we can remove it from the imports\n * list if it's not being used like:\n *\n * `import '../shared/imported'`\n */\n const removableImportPaths = new Set<string>([])\n\n programPath.traverse({\n CallExpression: (path) => {\n if (!t.isIdentifier(path.node.callee)) {\n return\n }\n\n if (!allCreateRouteFns.includes(path.node.callee.name)) {\n return\n }\n\n createRouteFn = path.node.callee.name\n\n function babelHandleReference(routeOptions: t.Node | undefined) {\n const hasImportedOrDefinedIdentifier = (name: string) => {\n return programPath.scope.hasBinding(name)\n }\n\n if (t.isObjectExpression(routeOptions)) {\n if (opts.deleteNodes && opts.deleteNodes.size > 0) {\n routeOptions.properties = routeOptions.properties.filter(\n (prop) => {\n if (t.isObjectProperty(prop)) {\n if (t.isIdentifier(prop.key)) {\n if (opts.deleteNodes?.has(prop.key.name as any)) {\n return false\n }\n }\n }\n return true\n },\n )\n }\n if (!splittableCreateRouteFns.includes(createRouteFn)) {\n // we can't split this route but we still add HMR handling if enabled\n if (opts.addHmr) {\n programPath.pushContainer('body', routeHmrStatement)\n }\n // exit traversal so this route is not split\n return programPath.stop()\n }\n routeOptions.properties.forEach((prop) => {\n if (t.isObjectProperty(prop)) {\n if (t.isIdentifier(prop.key)) {\n const key = prop.key.name\n\n // If the user has not specified a split grouping for this key\n // then we should not split it\n const codeSplitGroupingByKey = findIndexForSplitNode(key)\n if (codeSplitGroupingByKey === -1) {\n return\n }\n const codeSplitGroup = [\n ...new Set(\n opts.codeSplitGroupings[codeSplitGroupingByKey],\n ),\n ]\n\n // find key in nodeSplitConfig\n const isNodeConfigAvailable = SPLIT_NODES_CONFIG.has(\n key as any,\n )\n\n if (!isNodeConfigAvailable) {\n return\n }\n\n const splitNodeMeta = SPLIT_NODES_CONFIG.get(key as any)!\n\n // We need to extract the existing search params from the filename, if any\n // and add the relevant codesplitPrefix to them, then write them back to the filename\n const splitUrl = addSplitSearchParamToFilename(\n opts.filename,\n codeSplitGroup,\n )\n\n if (\n splitNodeMeta.splitStrategy === 'lazyRouteComponent'\n ) {\n const value = prop.value\n\n let shouldSplit = true\n\n if (t.isIdentifier(value)) {\n const existingImportPath =\n getImportSpecifierAndPathFromLocalName(\n programPath,\n value.name,\n ).path\n if (existingImportPath) {\n removableImportPaths.add(existingImportPath)\n }\n\n // exported identifiers should not be split\n // since they are already being imported\n // and need to be retained in the compiled file\n const isExported = hasExport(ast, value)\n shouldSplit = !isExported\n\n if (shouldSplit) {\n removeIdentifierLiteral(path, value)\n }\n }\n\n if (!shouldSplit) {\n return\n }\n\n // Prepend the import statement to the program along with the importer function\n // Check to see if lazyRouteComponent is already imported before attempting\n // to import it again\n\n if (\n !hasImportedOrDefinedIdentifier(\n LAZY_ROUTE_COMPONENT_IDENT,\n )\n ) {\n programPath.unshiftContainer('body', [\n template.statement(\n `import { ${LAZY_ROUTE_COMPONENT_IDENT} } from '${PACKAGE}'`,\n )(),\n ])\n }\n\n // Check to see if the importer function is already defined\n // If not, define it with the dynamic import statement\n if (\n !hasImportedOrDefinedIdentifier(\n splitNodeMeta.localImporterIdent,\n )\n ) {\n programPath.unshiftContainer('body', [\n template.statement(\n `const ${splitNodeMeta.localImporterIdent} = () => import('${splitUrl}')`,\n )(),\n ])\n }\n\n prop.value = template.expression(\n `${LAZY_ROUTE_COMPONENT_IDENT}(${splitNodeMeta.localImporterIdent}, '${splitNodeMeta.exporterIdent}')`,\n )()\n\n // add HMR handling\n if (opts.addHmr) {\n programPath.pushContainer('body', routeHmrStatement)\n }\n }\n\n if (splitNodeMeta.splitStrategy === 'lazyFn') {\n const value = prop.value\n\n let shouldSplit = true\n\n if (t.isIdentifier(value)) {\n const existingImportPath =\n getImportSpecifierAndPathFromLocalName(\n programPath,\n value.name,\n ).path\n if (existingImportPath) {\n removableImportPaths.add(existingImportPath)\n }\n\n // exported identifiers should not be split\n // since they are already being imported\n // and need to be retained in the compiled file\n const isExported = hasExport(ast, value)\n shouldSplit = !isExported\n\n if (shouldSplit) {\n removeIdentifierLiteral(path, value)\n }\n }\n\n if (!shouldSplit) {\n return\n }\n\n // Prepend the import statement to the program along with the importer function\n if (!hasImportedOrDefinedIdentifier(LAZY_FN_IDENT)) {\n programPath.unshiftContainer(\n 'body',\n template.smart(\n `import { ${LAZY_FN_IDENT} } from '${PACKAGE}'`,\n )(),\n )\n }\n\n // Check to see if the importer function is already defined\n // If not, define it with the dynamic import statement\n if (\n !hasImportedOrDefinedIdentifier(\n splitNodeMeta.localImporterIdent,\n )\n ) {\n programPath.unshiftContainer('body', [\n template.statement(\n `const ${splitNodeMeta.localImporterIdent} = () => import('${splitUrl}')`,\n )(),\n ])\n }\n\n // Add the lazyFn call with the dynamic import to the prop value\n prop.value = template.expression(\n `${LAZY_FN_IDENT}(${splitNodeMeta.localImporterIdent}, '${splitNodeMeta.exporterIdent}')`,\n )()\n }\n }\n }\n\n programPath.scope.crawl()\n })\n }\n }\n\n if (t.isCallExpression(path.parentPath.node)) {\n // createFileRoute('/')({ ... })\n const options = resolveIdentifier(\n path,\n path.parentPath.node.arguments[0],\n )\n\n babelHandleReference(options)\n } else if (t.isVariableDeclarator(path.parentPath.node)) {\n // createFileRoute({ ... })\n const caller = resolveIdentifier(path, path.parentPath.node.init)\n\n if (t.isCallExpression(caller)) {\n const options = resolveIdentifier(path, caller.arguments[0])\n babelHandleReference(options)\n }\n }\n },\n })\n\n /**\n * If the component for the route is being imported,\n * and it's not being used, remove the import statement\n * from the program, by checking that the import has no\n * specifiers\n */\n if (removableImportPaths.size > 0) {\n programPath.traverse({\n ImportDeclaration(path) {\n if (path.node.specifiers.length > 0) return\n if (removableImportPaths.has(path.node.source.value)) {\n path.remove()\n }\n },\n })\n }\n },\n },\n })\n\n deadCodeElimination(ast, refIdents)\n\n return generateFromAst(ast, {\n sourceMaps: true,\n sourceFileName: opts.filename,\n filename: opts.filename,\n })\n}\n\nexport function compileCodeSplitVirtualRoute(\n opts: ParseAstOptions & {\n splitTargets: Array<SplitRouteIdentNodes>\n filename: string\n },\n): GeneratorResult {\n const ast = parseAst(opts)\n const refIdents = findReferencedIdentifiers(ast)\n\n const intendedSplitNodes = new Set(opts.splitTargets)\n\n const knownExportedIdents = new Set<string>()\n\n babel.traverse(ast, {\n Program: {\n enter(programPath) {\n const trackedNodesToSplitByType: Record<\n SplitRouteIdentNodes,\n { node: t.Node | undefined; meta: SplitNodeMeta } | undefined\n > = {\n component: undefined,\n loader: undefined,\n pendingComponent: undefined,\n errorComponent: undefined,\n notFoundComponent: undefined,\n }\n\n // Find and track all the known split-able nodes\n programPath.traverse({\n CallExpression: (path) => {\n if (!t.isIdentifier(path.node.callee)) {\n return\n }\n\n if (!splittableCreateRouteFns.includes(path.node.callee.name)) {\n return\n }\n\n function babelHandleVirtual(options: t.Node | undefined) {\n if (t.isObjectExpression(options)) {\n options.properties.forEach((prop) => {\n if (t.isObjectProperty(prop)) {\n // do not use `intendedSplitNodes` here\n // since we have special considerations that need\n // to be accounted for like (not splitting exported identifiers)\n KNOWN_SPLIT_ROUTE_IDENTS.forEach((splitType) => {\n if (\n !t.isIdentifier(prop.key) ||\n prop.key.name !== splitType\n ) {\n return\n }\n\n const value = prop.value\n\n let isExported = false\n if (t.isIdentifier(value)) {\n isExported = hasExport(ast, value)\n if (isExported) {\n knownExportedIdents.add(value.name)\n }\n }\n\n // If the node is exported, we need to remove\n // the export from the split file\n if (isExported && t.isIdentifier(value)) {\n removeExports(ast, value)\n } else {\n const meta = SPLIT_NODES_CONFIG.get(splitType)!\n trackedNodesToSplitByType[splitType] = {\n node: prop.value,\n meta,\n }\n }\n })\n }\n })\n\n // Remove all of the options\n options.properties = []\n }\n }\n\n if (t.isCallExpression(path.parentPath.node)) {\n // createFileRoute('/')({ ... })\n const options = resolveIdentifier(\n path,\n path.parentPath.node.arguments[0],\n )\n\n babelHandleVirtual(options)\n } else if (t.isVariableDeclarator(path.parentPath.node)) {\n // createFileRoute({ ... })\n const caller = resolveIdentifier(path, path.parentPath.node.init)\n\n if (t.isCallExpression(caller)) {\n const options = resolveIdentifier(path, caller.arguments[0])\n babelHandleVirtual(options)\n }\n }\n },\n })\n\n // Start the transformation to only exported the intended split nodes\n intendedSplitNodes.forEach((SPLIT_TYPE) => {\n const splitKey = trackedNodesToSplitByType[SPLIT_TYPE]\n\n if (!splitKey) {\n return\n }\n\n let splitNode = splitKey.node\n const splitMeta = splitKey.meta\n\n while (t.isIdentifier(splitNode)) {\n const binding = programPath.scope.getBinding(splitNode.name)\n splitNode = binding?.path.node\n }\n\n // Add the node to the program\n if (splitNode) {\n if (t.isFunctionDeclaration(splitNode)) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitMeta.localExporterIdent),\n t.functionExpression(\n splitNode.id || null, // Anonymize the function expression\n splitNode.params,\n splitNode.body,\n splitNode.generator,\n splitNode.async,\n ),\n ),\n ]),\n )\n } else if (\n t.isFunctionExpression(splitNode) ||\n t.isArrowFunctionExpression(splitNode)\n ) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitMeta.localExporterIdent),\n splitNode as any,\n ),\n ]),\n )\n } else if (\n t.isImportSpecifier(splitNode) ||\n t.isImportDefaultSpecifier(splitNode)\n ) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitMeta.localExporterIdent),\n splitNode.local,\n ),\n ]),\n )\n } else if (t.isVariableDeclarator(splitNode)) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitMeta.localExporterIdent),\n splitNode.init,\n ),\n ]),\n )\n } else if (t.isCallExpression(splitNode)) {\n const outputSplitNodeCode = generateFromAst(splitNode).code\n const splitNodeAst = babel.parse(outputSplitNodeCode)\n\n if (!splitNodeAst) {\n throw new Error(\n `Failed to parse the generated code for \"${SPLIT_TYPE}\" in the node type \"${splitNode.type}\"`,\n )\n }\n\n const statement = splitNodeAst.program.body[0]\n\n if (!statement) {\n throw new Error(\n `Failed to parse the generated code for \"${SPLIT_TYPE}\" in the node type \"${splitNode.type}\" as no statement was found in the program body`,\n )\n }\n\n if (t.isExpressionStatement(statement)) {\n const expression = statement.expression\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitMeta.localExporterIdent),\n expression,\n ),\n ]),\n )\n } else {\n throw new Error(\n `Unexpected expression type encounter for \"${SPLIT_TYPE}\" in the node type \"${splitNode.type}\"`,\n )\n }\n } else if (t.isConditionalExpression(splitNode)) {\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitMeta.localExporterIdent),\n splitNode,\n ),\n ]),\n )\n } else if (t.isTSAsExpression(splitNode)) {\n // remove the type assertion\n splitNode = splitNode.expression\n programPath.pushContainer(\n 'body',\n t.variableDeclaration('const', [\n t.variableDeclarator(\n t.identifier(splitMeta.localExporterIdent),\n splitNode,\n ),\n ]),\n )\n } else {\n console.info('Unexpected splitNode type:', splitNode)\n throw new Error(`Unexpected splitNode type ☝️: ${splitNode.type}`)\n }\n }\n\n // If the splitNode exists at the top of the program\n // then we need to remove that copy\n programPath.node.body = programPath.node.body.filter((node) => {\n return node !== splitNode\n })\n\n // Export the node\n programPath.pushContainer('body', [\n t.exportNamedDeclaration(null, [\n t.exportSpecifier(\n t.identifier(splitMeta.localExporterIdent), // local variable name\n t.identifier(splitMeta.exporterIdent), // as what name it should be exported as\n ),\n ]),\n ])\n })\n\n // convert exports to imports from the original file\n programPath.traverse({\n ExportNamedDeclaration(path) {\n // e.g. export const x = 1 or export { x }\n // becomes\n // import { x } from '${opts.id}'\n\n if (path.node.declaration) {\n if (t.isVariableDeclaration(path.node.declaration)) {\n path.replaceWith(\n t.importDeclaration(\n path.node.declaration.declarations.map((decl) =>\n t.importSpecifier(\n t.identifier((decl.id as any).name),\n t.identifier((decl.id as any).name),\n ),\n ),\n t.stringLiteral(\n removeSplitSearchParamFromFilename(opts.filename),\n ),\n ),\n )\n }\n }\n },\n })\n },\n },\n })\n\n deadCodeElimination(ast, refIdents)\n\n // if there are exported identifiers, then we need to add a warning\n // to the file to let the user know that the exported identifiers\n // will not in the split file but in the original file, therefore\n // increasing the bundle size\n if (knownExportedIdents.size > 0) {\n const list = Array.from(knownExportedIdents).reduce((str, ident) => {\n str += `\\n- ${ident}`\n return str\n }, '')\n\n const warningMessage = `These exports from \"${opts.filename}\" are not being code-split and will increase your bundle size: ${list}\\nThese should either have their export statements removed or be imported from another file that is not a route.`\n console.warn(warningMessage)\n\n // append this warning to the file using a template\n if (process.env.NODE_ENV !== 'production') {\n const warningTemplate = template.statement(\n `console.warn(${JSON.stringify(warningMessage)})`,\n )()\n ast.program.body.unshift(warningTemplate)\n }\n }\n\n return generateFromAst(ast, {\n sourceMaps: true,\n sourceFileName: opts.filename,\n filename: opts.filename,\n })\n}\n\n/**\n * This function should read get the options from by searching for the key `codeSplitGroupings`\n * on createFileRoute and return it's values if it exists, else return undefined\n */\nexport function detectCodeSplitGroupingsFromRoute(opts: ParseAstOptions): {\n groupings: CodeSplitGroupings | undefined\n} {\n const ast = parseAst(opts)\n\n let codeSplitGroupings: CodeSplitGroupings | undefined = undefined\n\n babel.traverse(ast, {\n Program: {\n enter(programPath) {\n programPath.traverse({\n CallExpression(path) {\n if (!t.isIdentifier(path.node.callee)) {\n return\n }\n\n if (\n !(\n path.node.callee.name === 'createRoute' ||\n path.node.callee.name === 'createFileRoute'\n )\n ) {\n return\n }\n\n function babelHandleSplittingGroups(\n routeOptions: t.Node | undefined,\n ) {\n if (t.isObjectExpression(routeOptions)) {\n routeOptions.properties.forEach((prop) => {\n if (t.isObjectProperty(prop)) {\n if (t.isIdentifier(prop.key)) {\n if (prop.key.name === 'codeSplitGroupings') {\n const value = prop.value\n\n if (t.isArrayExpression(value)) {\n codeSplitGroupings = value.elements.map((group) => {\n if (t.isArrayExpression(group)) {\n return group.elements.map((node) => {\n if (!t.isStringLiteral(node)) {\n throw new Error(\n 'You must provide a string literal for the codeSplitGroupings',\n )\n }\n\n return node.value\n }) as Array<SplitRouteIdentNodes>\n }\n\n throw new Error(\n 'You must provide arrays with codeSplitGroupings options.',\n )\n })\n } else {\n throw new Error(\n 'You must provide an array of arrays for the codeSplitGroupings.',\n )\n }\n }\n }\n }\n })\n }\n }\n\n // Extracting the codeSplitGroupings\n if (t.isCallExpression(path.parentPath.node)) {\n // createFileRoute('/')({ ... })\n const options = resolveIdentifier(\n path,\n path.parentPath.node.arguments[0],\n )\n\n babelHandleSplittingGroups(options)\n } else if (t.isVariableDeclarator(path.parentPath.node)) {\n // createFileRoute({ ... })\n const caller = resolveIdentifier(path, path.parentPath.node.init)\n\n if (t.isCallExpression(caller)) {\n const options = resolveIdentifier(path, caller.arguments[0])\n babelHandleSplittingGroups(options)\n }\n }\n },\n })\n },\n },\n })\n\n return { groupings: codeSplitGroupings }\n}\n\nfunction getImportSpecifierAndPathFromLocalName(\n programPath: babel.NodePath<t.Program>,\n name: string,\n): {\n specifier:\n | t.ImportSpecifier\n | t.ImportDefaultSpecifier\n | t.ImportNamespaceSpecifier\n | null\n path: string | null\n} {\n let specifier:\n | t.ImportSpecifier\n | t.ImportDefaultSpecifier\n | t.ImportNamespaceSpecifier\n | null = null\n let path: string | null = null\n\n programPath.traverse({\n ImportDeclaration(importPath) {\n const found = importPath.node.specifiers.find(\n (targetSpecifier) => targetSpecifier.local.name === name,\n )\n if (found) {\n specifier = found\n path = importPath.node.source.value\n }\n },\n })\n\n return { specifier, path }\n}\n\n// Reusable function to get literal value or resolve variable to literal\nfunction resolveIdentifier(path: any, node: any): t.Node | undefined {\n if (t.isIdentifier(node)) {\n const binding = path.scope.getBinding(node.name)\n if (\n binding\n // && binding.kind === 'const'\n ) {\n const declarator = binding.path.node\n if (t.isObjectExpression(declarator.init)) {\n return declarator.init\n } else if (t.isFunctionDeclaration(declarator.init)) {\n return declarator.init\n }\n }\n return undefined\n }\n\n return node\n}\n\nfunction removeIdentifierLiteral(path: babel.NodePath, node: t.Identifier) {\n const binding = path.scope.getBinding(node.name)\n if (binding) {\n binding.path.remove()\n }\n}\n\nfunction hasExport(ast: t.File, node: t.Identifier): boolean {\n let found = false\n\n babel.traverse(ast, {\n ExportNamedDeclaration(path) {\n if (path.node.declaration) {\n // declared as `const loaderFn = () => {}`\n if (t.isVariableDeclaration(path.node.declaration)) {\n path.node.declaration.declarations.forEach((decl) => {\n if (t.isVariableDeclarator(decl)) {\n if (t.isIdentifier(decl.id)) {\n if (decl.id.name === node.name) {\n found = true\n }\n }\n }\n })\n }\n\n // declared as `function loaderFn() {}`\n if (t.isFunctionDeclaration(path.node.declaration)) {\n if (t.isIdentifier(path.node.declaration.id)) {\n if (path.node.declaration.id.name === node.name) {\n found = true\n }\n }\n }\n }\n },\n ExportDefaultDeclaration(path) {\n // declared as `export default loaderFn`\n if (t.isIdentifier(path.node.declaration)) {\n if (path.node.declaration.name === node.name) {\n found = true\n }\n }\n\n // declared as `export default function loaderFn() {}`\n if (t.isFunctionDeclaration(path.node.declaration)) {\n if (t.isIdentifier(path.node.declaration.id)) {\n if (path.node.declaration.id.name === node.name) {\n found = true\n }\n }\n }\n },\n })\n\n return found\n}\n\nfunction removeExports(ast: t.File, node: t.Identifier): boolean {\n let removed = false\n\n // The checks use sequential if/else if statements since it\n // directly mutates the AST and as such doing normal checks\n // (using only if statements) could lead to a situation where\n // `path.node` is null since it has been already removed from\n // the program tree but typescript doesn't know that.\n babel.traverse(ast, {\n ExportNamedDeclaration(path) {\n if (path.node.declaration) {\n if (t.isVariableDeclaration(path.node.declaration)) {\n // declared as `const loaderFn = () => {}`\n path.node.declaration.declarations.forEach((decl) => {\n if (t.isVariableDeclarator(decl)) {\n if (t.isIdentifier(decl.id)) {\n if (decl.id.name === node.name) {\n path.remove()\n removed = true\n }\n }\n }\n })\n } else if (t.isFunctionDeclaration(path.node.declaration)) {\n // declared as `export const loaderFn = () => {}`\n if (t.isIdentifier(path.node.declaration.id)) {\n if (path.node.declaration.id.name === node.name) {\n path.remove()\n removed = true\n }\n }\n }\n }\n },\n ExportDefaultDeclaration(path) {\n // declared as `export default loaderFn`\n if (t.isIdentifier(path.node.declaration)) {\n if (path.node.declaration.name === node.name) {\n path.remove()\n removed = true\n }\n } else if (t.isFunctionDeclaration(path.node.declaration)) {\n // declared as `export default function loaderFn() {}`\n if (t.isIdentifier(path.node.declaration.id)) {\n if (path.node.declaration.id.name === node.name) {\n path.remove()\n removed = true\n }\n }\n }\n },\n })\n\n return removed\n}\n"],"names":[],"mappings":";;;;;;;;;AAuBA,MAAM,yCAAyB,IAAyC;AAAA,EACtE;AAAA,IACE;AAAA,IACA;AAAA,MACE,YAAY;AAAA,MACZ,oBAAoB;AAAA;AAAA,MACpB,eAAe;AAAA,MACf,oBAAoB;AAAA;AAAA,MACpB,eAAe;AAAA;AAAA,IAAA;AAAA,EAEnB;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,MACE,YAAY;AAAA,MACZ,oBAAoB;AAAA;AAAA,MACpB,eAAe;AAAA,MACf,oBAAoB;AAAA;AAAA,MACpB,eAAe;AAAA;AAAA,IAAA;AAAA,EAEnB;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,MACE,YAAY;AAAA,MACZ,oBAAoB;AAAA;AAAA,MACpB,eAAe;AAAA,MACf,oBAAoB;AAAA;AAAA,MACpB,eAAe;AAAA;AAAA,IAAA;AAAA,EAEnB;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,MACE,YAAY;AAAA,MACZ,oBAAoB;AAAA;AAAA,MACpB,eAAe;AAAA,MACf,oBAAoB;AAAA;AAAA,MACpB,eAAe;AAAA;AAAA,IAAA;AAAA,EAEnB;AAAA,EACA;AAAA,IACE;AAAA,IACA;AAAA,MACE,YAAY;AAAA,MACZ,oBAAoB;AAAA;AAAA,MACpB,eAAe;AAAA,MACf,oBAAoB;AAAA;AAAA,MACpB,eAAe;AAAA;AAAA,IAAA;AAAA,EACjB;AAEJ,CAAC;AACD,MAAM,2BAA2B,CAAC,GAAG,mBAAmB,MAAM;AAE9D,SAAS,8BACP,UACA,UACA;AACA,QAAM,CAAC,YAAY,IAAI,SAAS,MAAM,GAAG;AAEnC,QAAA,SAAS,IAAI,gBAAgB;AACnC,SAAO,OAAO,UAAU,iBAAiB,QAAQ,CAAC;AAElD,SAAO,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K,KAAK,WAAW,GAAG;AAElD,eAAK,KAAK,YAAY,aAAa,QAAQ,CAAC,SAAS;AAC/C,gBAAA,EAAE,qBAAqB,IAAI,GAAG;AAChC,kBAAI,EAAE,aAAa,KAAK,EAAE,GAAG;AAC3B,oBAAI,KAAK,GAAG,SAAS,KAAK,MAAM;AAC9B,uBAAK,OAAO;AACF,4BAAA;AAAA,gBAAA;AAAA,cACZ;AAAA,YACF;AAAA,UACF,CACD;AAAA,QAAA,WACQ,EAAE,sBAAsB,KAAK,KAAK,WAAW,GAAG;AAEzD,cAAI,EAAE,aAAa,KAAK,KAAK,YAAY,EAAE,GAAG;AAC5C,gBAAI,KAAK,KAAK,YAAY,GAAG,SAAS,KAAK,MAAM;AAC/C,mBAAK,OAAO;AACF,wBAAA;AAAA,YAAA;AAAA,UACZ;AAAA,QACF;AAAA,MACF;AAAA,IAEJ;AAAA,IACA,yBAAyB,MAAM;AAE7B,UAAI,EAAE,aAAa,KAAK,KAAK,WAAW,GAAG;AACzC,YAAI,KAAK,KAAK,YAAY,SAAS,KAAK,MAAM;AAC5C,eAAK,OAAO;AACF,oBAAA;AAAA,QAAA;AAAA,MACZ,WACS,EAAE,sBAAsB,KAAK,KAAK,WAAW,GAAG;AAEzD,YAAI,EAAE,aAAa,KAAK,KAAK,YAAY,EAAE,GAAG;AAC5C,cAAI,KAAK,KAAK,YAAY,GAAG,SAAS,KAAK,MAAM;AAC/C,iBAAK,OAAO;AACF,sBAAA;AAAA,UAAA;AAAA,QACZ;AAAA,MACF;AAAA,IACF;AAAA,EACF,CACD;AAEM,SAAA;AACT;"}
@@ -18,7 +18,19 @@ export type CodeSplittingOptions = {
18
18
  * @default [['component'],['pendingComponent'],['errorComponent'],['notFoundComponent']]
19
19
  */
20
20
  defaultBehavior?: CodeSplitGroupings;
21
+ /**
22
+ * The nodes that shall be deleted from the route.
23
+ * @default undefined
24
+ */
25
+ deleteNodes?: Array<DeletableNodes>;
26
+ /**
27
+ * @default true
28
+ */
29
+ addHmr?: boolean;
21
30
  };
31
+ declare const DELETABLE_NODES: readonly ["ssr"];
32
+ export declare const deletableNodesSchema: z.ZodEnum<["ssr"]>;
33
+ export type DeletableNodes = (typeof DELETABLE_NODES)[number];
22
34
  export declare const configSchema: z.ZodObject<{
23
35
  target: z.ZodDefault<z.ZodOptional<z.ZodEnum<["react", "solid"]>>>;
24
36
  virtualRouteConfig: z.ZodOptional<z.ZodUnion<[z.ZodType<import('@tanstack/virtual-file-routes').VirtualRootRoute, z.ZodTypeDef, import('@tanstack/virtual-file-routes').VirtualRootRoute>, z.ZodString]>>;
@@ -63,6 +75,23 @@ export declare const configSchema: z.ZodObject<{
63
75
  } & {
64
76
  enableRouteGeneration: z.ZodOptional<z.ZodBoolean>;
65
77
  codeSplittingOptions: z.ZodOptional<z.ZodType<CodeSplittingOptions, z.ZodTypeDef, CodeSplittingOptions>>;
78
+ plugin: z.ZodOptional<z.ZodObject<{
79
+ vite: z.ZodOptional<z.ZodObject<{
80
+ environmentName: z.ZodOptional<z.ZodString>;
81
+ }, "strip", z.ZodTypeAny, {
82
+ environmentName?: string | undefined;
83
+ }, {
84
+ environmentName?: string | undefined;
85
+ }>>;
86
+ }, "strip", z.ZodTypeAny, {
87
+ vite?: {
88
+ environmentName?: string | undefined;
89
+ } | undefined;
90
+ }, {
91
+ vite?: {
92
+ environmentName?: string | undefined;
93
+ } | undefined;
94
+ }>>;
66
95
  }, "strip", z.ZodTypeAny, {
67
96
  target: "react" | "solid";
68
97
  routeFileIgnorePrefix: string;
@@ -81,6 +110,11 @@ export declare const configSchema: z.ZodObject<{
81
110
  tmpDir: string;
82
111
  enableRouteGeneration?: boolean | undefined;
83
112
  codeSplittingOptions?: CodeSplittingOptions | undefined;
113
+ plugin?: {
114
+ vite?: {
115
+ environmentName?: string | undefined;
116
+ } | undefined;
117
+ } | undefined;
84
118
  virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
85
119
  routeFilePrefix?: string | undefined;
86
120
  routeFileIgnorePattern?: string | undefined;
@@ -98,6 +132,11 @@ export declare const configSchema: z.ZodObject<{
98
132
  }, {
99
133
  enableRouteGeneration?: boolean | undefined;
100
134
  codeSplittingOptions?: CodeSplittingOptions | undefined;
135
+ plugin?: {
136
+ vite?: {
137
+ environmentName?: string | undefined;
138
+ } | undefined;
139
+ } | undefined;
101
140
  target?: "react" | "solid" | undefined;
102
141
  virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
103
142
  routeFilePrefix?: string | undefined;
@@ -146,6 +185,11 @@ export declare const getConfig: (inlineConfig: Partial<Config>, root: string) =>
146
185
  tmpDir: string;
147
186
  enableRouteGeneration?: boolean | undefined;
148
187
  codeSplittingOptions?: CodeSplittingOptions | undefined;
188
+ plugin?: {
189
+ vite?: {
190
+ environmentName?: string | undefined;
191
+ } | undefined;
192
+ } | undefined;
149
193
  virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
150
194
  routeFilePrefix?: string | undefined;
151
195
  routeFileIgnorePattern?: string | undefined;
@@ -164,3 +208,4 @@ export declare const getConfig: (inlineConfig: Partial<Config>, root: string) =>
164
208
  export type Config = z.infer<typeof configSchema>;
165
209
  export type ConfigInput = z.input<typeof configSchema>;
166
210
  export type ConfigOutput = z.output<typeof configSchema>;
211
+ export {};
@@ -24,14 +24,23 @@ const splitGroupingsSchema = z.array(
24
24
  });
25
25
  }
26
26
  });
27
+ const DELETABLE_NODES = ["ssr"];
28
+ const deletableNodesSchema = z.enum(DELETABLE_NODES);
27
29
  const codeSplittingOptionsSchema = z.object({
28
30
  splitBehavior: z.function().optional(),
29
- defaultBehavior: splitGroupingsSchema.optional()
31
+ defaultBehavior: splitGroupingsSchema.optional(),
32
+ deleteNodes: z.array(deletableNodesSchema).optional(),
33
+ addHmr: z.boolean().optional().default(true)
30
34
  });
31
35
  const configSchema = configSchema$1.extend({
32
36
  enableRouteGeneration: z.boolean().optional(),
33
37
  codeSplittingOptions: z.custom((v) => {
34
38
  return codeSplittingOptionsSchema.parse(v);
39
+ }).optional(),
40
+ plugin: z.object({
41
+ vite: z.object({
42
+ environmentName: z.string().optional()
43
+ }).optional()
35
44
  }).optional()
36
45
  });
37
46
  const getConfig = (inlineConfig, root) => {
@@ -40,6 +49,7 @@ const getConfig = (inlineConfig, root) => {
40
49
  };
41
50
  export {
42
51
  configSchema,
52
+ deletableNodesSchema,
43
53
  getConfig,
44
54
  splitGroupingsSchema
45
55
  };
@@ -1 +1 @@
1
- {"version":3,"file":"config.js","sources":["../../../src/core/config.ts"],"sourcesContent":["import { z } from 'zod'\nimport {\n configSchema as generatorConfigSchema,\n getConfig as getGeneratorConfig,\n} from '@tanstack/router-generator'\nimport type { RegisteredRouter, RouteIds } from '@tanstack/router-core'\nimport type { CodeSplitGroupings } from './constants'\n\nexport const splitGroupingsSchema = z\n .array(\n z.array(\n z.union([\n z.literal('loader'),\n z.literal('component'),\n z.literal('pendingComponent'),\n z.literal('errorComponent'),\n z.literal('notFoundComponent'),\n ]),\n ),\n {\n message:\n \" Must be an Array of Arrays containing the split groupings. i.e. [['component'], ['pendingComponent'], ['errorComponent', 'notFoundComponent']]\",\n },\n )\n .superRefine((val, ctx) => {\n const flattened = val.flat()\n const unique = [...new Set(flattened)]\n\n // Elements must be unique,\n // ie. this shouldn't be allows [['component'], ['component', 'loader']]\n if (unique.length !== flattened.length) {\n ctx.addIssue({\n code: 'custom',\n message:\n \" Split groupings must be unique and not repeated. i.e. i.e. [['component'], ['pendingComponent'], ['errorComponent', 'notFoundComponent']].\" +\n `\\n You input was: ${JSON.stringify(val)}.`,\n })\n }\n })\n\nexport type CodeSplittingOptions = {\n /**\n * Use this function to programmatically control the code splitting behavior\n * based on the `routeId` for each route.\n *\n * If you just need to change the default behavior, you can use the `defaultBehavior` option.\n * @param params\n */\n splitBehavior?: (params: {\n routeId: RouteIds<RegisteredRouter['routeTree']>\n }) => CodeSplitGroupings | undefined | void\n\n /**\n * The default/global configuration to control your code splitting behavior per route.\n * @default [['component'],['pendingComponent'],['errorComponent'],['notFoundComponent']]\n */\n defaultBehavior?: CodeSplitGroupings\n}\n\nconst codeSplittingOptionsSchema = z.object({\n splitBehavior: z.function().optional(),\n defaultBehavior: splitGroupingsSchema.optional(),\n})\n\nexport const configSchema = generatorConfigSchema.extend({\n enableRouteGeneration: z.boolean().optional(),\n codeSplittingOptions: z\n .custom<CodeSplittingOptions>((v) => {\n return codeSplittingOptionsSchema.parse(v)\n })\n .optional(),\n})\n\nexport const getConfig = (inlineConfig: Partial<Config>, root: string) => {\n const config = getGeneratorConfig(inlineConfig, root)\n\n return configSchema.parse({ ...config, ...inlineConfig })\n}\n\nexport type Config = z.infer<typeof configSchema>\nexport type ConfigInput = z.input<typeof configSchema>\nexport type ConfigOutput = z.output<typeof configSchema>\n"],"names":["generatorConfigSchema","getGeneratorConfig"],"mappings":";;AAQO,MAAM,uBAAuB,EACjC;AAAA,EACC,EAAE;AAAA,IACA,EAAE,MAAM;AAAA,MACN,EAAE,QAAQ,QAAQ;AAAA,MAClB,EAAE,QAAQ,WAAW;AAAA,MACrB,EAAE,QAAQ,kBAAkB;AAAA,MAC5B,EAAE,QAAQ,gBAAgB;AAAA,MAC1B,EAAE,QAAQ,mBAAmB;AAAA,IAC9B,CAAA;AAAA,EACH;AAAA,EACA;AAAA,IACE,SACE;AAAA,EAAA;AAEN,EACC,YAAY,CAAC,KAAK,QAAQ;AACnB,QAAA,YAAY,IAAI,KAAK;AAC3B,QAAM,SAAS,CAAC,GAAG,IAAI,IAAI,SAAS,CAAC;AAIjC,MAAA,OAAO,WAAW,UAAU,QAAQ;AACtC,QAAI,SAAS;AAAA,MACX,MAAM;AAAA,MACN,SACE;AAAA,mBACsB,KAAK,UAAU,GAAG,CAAC;AAAA,IAAA,CAC5C;AAAA,EAAA;AAEL,CAAC;AAqBH,MAAM,6BAA6B,EAAE,OAAO;AAAA,EAC1C,eAAe,EAAE,SAAS,EAAE,SAAS;AAAA,EACrC,iBAAiB,qBAAqB,SAAS;AACjD,CAAC;AAEY,MAAA,eAAeA,eAAsB,OAAO;AAAA,EACvD,uBAAuB,EAAE,QAAQ,EAAE,SAAS;AAAA,EAC5C,sBAAsB,EACnB,OAA6B,CAAC,MAAM;AAC5B,WAAA,2BAA2B,MAAM,CAAC;AAAA,EAC1C,CAAA,EACA,SAAS;AACd,CAAC;AAEY,MAAA,YAAY,CAAC,cAA+B,SAAiB;AAClE,QAAA,SAASC,YAAmB,cAAc,IAAI;AAEpD,SAAO,aAAa,MAAM,EAAE,GAAG,QAAQ,GAAG,cAAc;AAC1D;"}
1
+ {"version":3,"file":"config.js","sources":["../../../src/core/config.ts"],"sourcesContent":["import { z } from 'zod'\nimport {\n configSchema as generatorConfigSchema,\n getConfig as getGeneratorConfig,\n} from '@tanstack/router-generator'\nimport type { RegisteredRouter, RouteIds } from '@tanstack/router-core'\nimport type { CodeSplitGroupings } from './constants'\n\nexport const splitGroupingsSchema = z\n .array(\n z.array(\n z.union([\n z.literal('loader'),\n z.literal('component'),\n z.literal('pendingComponent'),\n z.literal('errorComponent'),\n z.literal('notFoundComponent'),\n ]),\n ),\n {\n message:\n \" Must be an Array of Arrays containing the split groupings. i.e. [['component'], ['pendingComponent'], ['errorComponent', 'notFoundComponent']]\",\n },\n )\n .superRefine((val, ctx) => {\n const flattened = val.flat()\n const unique = [...new Set(flattened)]\n\n // Elements must be unique,\n // ie. this shouldn't be allows [['component'], ['component', 'loader']]\n if (unique.length !== flattened.length) {\n ctx.addIssue({\n code: 'custom',\n message:\n \" Split groupings must be unique and not repeated. i.e. i.e. [['component'], ['pendingComponent'], ['errorComponent', 'notFoundComponent']].\" +\n `\\n You input was: ${JSON.stringify(val)}.`,\n })\n }\n })\n\nexport type CodeSplittingOptions = {\n /**\n * Use this function to programmatically control the code splitting behavior\n * based on the `routeId` for each route.\n *\n * If you just need to change the default behavior, you can use the `defaultBehavior` option.\n * @param params\n */\n splitBehavior?: (params: {\n routeId: RouteIds<RegisteredRouter['routeTree']>\n }) => CodeSplitGroupings | undefined | void\n\n /**\n * The default/global configuration to control your code splitting behavior per route.\n * @default [['component'],['pendingComponent'],['errorComponent'],['notFoundComponent']]\n */\n defaultBehavior?: CodeSplitGroupings\n\n /**\n * The nodes that shall be deleted from the route.\n * @default undefined\n */\n deleteNodes?: Array<DeletableNodes>\n\n /**\n * @default true\n */\n addHmr?: boolean\n}\n\nconst DELETABLE_NODES = ['ssr'] as const\nexport const deletableNodesSchema = z.enum(DELETABLE_NODES)\nconst codeSplittingOptionsSchema = z.object({\n splitBehavior: z.function().optional(),\n defaultBehavior: splitGroupingsSchema.optional(),\n deleteNodes: z.array(deletableNodesSchema).optional(),\n addHmr: z.boolean().optional().default(true),\n})\nexport type DeletableNodes = (typeof DELETABLE_NODES)[number]\n\nexport const configSchema = generatorConfigSchema.extend({\n enableRouteGeneration: z.boolean().optional(),\n codeSplittingOptions: z\n .custom<CodeSplittingOptions>((v) => {\n return codeSplittingOptionsSchema.parse(v)\n })\n .optional(),\n plugin: z\n .object({\n vite: z\n .object({\n environmentName: z.string().optional(),\n })\n .optional(),\n })\n .optional(),\n})\n\nexport const getConfig = (inlineConfig: Partial<Config>, root: string) => {\n const config = getGeneratorConfig(inlineConfig, root)\n\n return configSchema.parse({ ...config, ...inlineConfig })\n}\n\nexport type Config = z.infer<typeof configSchema>\nexport type ConfigInput = z.input<typeof configSchema>\nexport type ConfigOutput = z.output<typeof configSchema>\n"],"names":["generatorConfigSchema","getGeneratorConfig"],"mappings":";;AAQO,MAAM,uBAAuB,EACjC;AAAA,EACC,EAAE;AAAA,IACA,EAAE,MAAM;AAAA,MACN,EAAE,QAAQ,QAAQ;AAAA,MAClB,EAAE,QAAQ,WAAW;AAAA,MACrB,EAAE,QAAQ,kBAAkB;AAAA,MAC5B,EAAE,QAAQ,gBAAgB;AAAA,MAC1B,EAAE,QAAQ,mBAAmB;AAAA,IAC9B,CAAA;AAAA,EACH;AAAA,EACA;AAAA,IACE,SACE;AAAA,EAAA;AAEN,EACC,YAAY,CAAC,KAAK,QAAQ;AACnB,QAAA,YAAY,IAAI,KAAK;AAC3B,QAAM,SAAS,CAAC,GAAG,IAAI,IAAI,SAAS,CAAC;AAIjC,MAAA,OAAO,WAAW,UAAU,QAAQ;AACtC,QAAI,SAAS;AAAA,MACX,MAAM;AAAA,MACN,SACE;AAAA,mBACsB,KAAK,UAAU,GAAG,CAAC;AAAA,IAAA,CAC5C;AAAA,EAAA;AAEL,CAAC;AAgCH,MAAM,kBAAkB,CAAC,KAAK;AACjB,MAAA,uBAAuB,EAAE,KAAK,eAAe;AAC1D,MAAM,6BAA6B,EAAE,OAAO;AAAA,EAC1C,eAAe,EAAE,SAAS,EAAE,SAAS;AAAA,EACrC,iBAAiB,qBAAqB,SAAS;AAAA,EAC/C,aAAa,EAAE,MAAM,oBAAoB,EAAE,SAAS;AAAA,EACpD,QAAQ,EAAE,QAAA,EAAU,SAAS,EAAE,QAAQ,IAAI;AAC7C,CAAC;AAGY,MAAA,eAAeA,eAAsB,OAAO;AAAA,EACvD,uBAAuB,EAAE,QAAQ,EAAE,SAAS;AAAA,EAC5C,sBAAsB,EACnB,OAA6B,CAAC,MAAM;AAC5B,WAAA,2BAA2B,MAAM,CAAC;AAAA,EAC1C,CAAA,EACA,SAAS;AAAA,EACZ,QAAQ,EACL,OAAO;AAAA,IACN,MAAM,EACH,OAAO;AAAA,MACN,iBAAiB,EAAE,OAAO,EAAE,SAAS;AAAA,IACtC,CAAA,EACA,SAAS;AAAA,EACb,CAAA,EACA,SAAS;AACd,CAAC;AAEY,MAAA,YAAY,CAAC,cAA+B,SAAiB;AAClE,QAAA,SAASC,YAAmB,cAAc,IAAI;AAEpD,SAAO,aAAa,MAAM,EAAE,GAAG,QAAQ,GAAG,cAAc;AAC1D;"}
@@ -38,6 +38,7 @@ const unpluginRouterCodeSplitterFactory = (options = {}, { framework }) => {
38
38
  return (_a = userConfig.codeSplittingOptions) == null ? void 0 : _a.splitBehavior;
39
39
  };
40
40
  const handleCompilingReferenceFile = (code, id, generatorNodeInfo) => {
41
+ var _a, _b;
41
42
  if (debug) console.info("Compiling Route: ", id);
42
43
  const fromCode = detectCodeSplitGroupingsFromRoute({
43
44
  code
@@ -69,11 +70,12 @@ ${message}`
69
70
  const splitGroupings = fromCode.groupings || pluginSplitBehavior || getGlobalCodeSplitGroupings();
70
71
  const compiledReferenceRoute = compileCodeSplitReferenceRoute({
71
72
  code,
72
- runtimeEnv: isProduction ? "prod" : "dev",
73
73
  codeSplitGroupings: splitGroupings,
74
74
  targetFramework: userConfig.target,
75
75
  filename: id,
76
- id
76
+ id,
77
+ deleteNodes: new Set((_a = userConfig.codeSplittingOptions) == null ? void 0 : _a.deleteNodes),
78
+ addHmr: ((_b = options.codeSplittingOptions) == null ? void 0 : _b.addHmr) && !isProduction
77
79
  });
78
80
  if (debug) {
79
81
  logDiff(code, compiledReferenceRoute.code);
@@ -106,6 +108,11 @@ ${message}`
106
108
  }
107
109
  return result;
108
110
  };
111
+ const includedCode = [
112
+ "createFileRoute(",
113
+ "createRootRoute(",
114
+ "createRootRouteWithContext("
115
+ ];
109
116
  return [
110
117
  {
111
118
  name: "tanstack-router:code-splitter:compile-reference-file",
@@ -117,12 +124,14 @@ ${message}`
117
124
  // this is necessary for webpack / rspack to avoid matching .html files
118
125
  include: /\.(m|c)?(j|t)sx?$/
119
126
  },
120
- code: "createFileRoute("
127
+ code: {
128
+ include: includedCode
129
+ }
121
130
  },
122
131
  handler(code, id) {
123
132
  var _a;
124
133
  const generatorFileInfo = (_a = globalThis.TSR_ROUTES_BY_ID_MAP) == null ? void 0 : _a.get(id);
125
- if (generatorFileInfo && code.includes("createFileRoute(")) {
134
+ if (generatorFileInfo && includedCode.some((included) => code.includes(included))) {
126
135
  for (const externalPlugin of bannedBeforeExternalPlugins) {
127
136
  if (!externalPlugin.frameworks.includes(framework)) {
128
137
  continue;
@@ -140,6 +149,13 @@ ${message}`
140
149
  configResolved(config) {
141
150
  ROOT = config.root;
142
151
  userConfig = getConfig(options, ROOT);
152
+ },
153
+ applyToEnvironment(environment) {
154
+ var _a, _b;
155
+ if ((_b = (_a = userConfig.plugin) == null ? void 0 : _a.vite) == null ? void 0 : _b.environmentName) {
156
+ return userConfig.plugin.vite.environmentName === environment.name;
157
+ }
158
+ return true;
143
159
  }
144
160
  },
145
161
  rspack() {
@@ -1 +1 @@
1
- {"version":3,"file":"router-code-splitter-plugin.js","sources":["../../../src/core/router-code-splitter-plugin.ts"],"sourcesContent":["/**\n * It is important to familiarize yourself with how the code-splitting works in this plugin.\n * https://github.com/TanStack/router/pull/3355\n */\n\nimport { fileURLToPath, pathToFileURL } from 'node:url'\nimport { logDiff } from '@tanstack/router-utils'\nimport { getConfig, splitGroupingsSchema } from './config'\nimport {\n compileCodeSplitReferenceRoute,\n compileCodeSplitVirtualRoute,\n detectCodeSplitGroupingsFromRoute,\n} from './code-splitter/compilers'\nimport {\n defaultCodeSplitGroupings,\n splitRouteIdentNodes,\n tsrSplit,\n} from './constants'\nimport { decodeIdentifier } from './code-splitter/path-ids'\nimport { debug } from './utils'\nimport type { CodeSplitGroupings, SplitRouteIdentNodes } from './constants'\nimport type { GetRoutesByFileMapResultValue } from '@tanstack/router-generator'\nimport type { Config } from './config'\nimport type {\n UnpluginContextMeta,\n UnpluginFactory,\n TransformResult as UnpluginTransformResult,\n} from 'unplugin'\n\ntype BannedBeforeExternalPlugin = {\n identifier: string\n pkg: string\n usage: string\n frameworks: Array<UnpluginContextMeta['framework']>\n}\n\nconst bannedBeforeExternalPlugins: Array<BannedBeforeExternalPlugin> = [\n {\n identifier: '@react-refresh',\n pkg: '@vitejs/plugin-react',\n usage: 'viteReact()',\n frameworks: ['vite'],\n },\n]\n\nclass FoundPluginInBeforeCode extends Error {\n constructor(\n externalPlugin: BannedBeforeExternalPlugin,\n pluginFramework: string,\n ) {\n 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: \ne.g.\nplugins: [\n tanstackRouter(), // Place this before ${externalPlugin.usage}\n ${externalPlugin.usage},\n]\n`)\n }\n}\n\nconst PLUGIN_NAME = 'unplugin:router-code-splitter'\n\nexport const unpluginRouterCodeSplitterFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}, { framework }) => {\n let ROOT: string = process.cwd()\n let userConfig = options as Config\n\n const isProduction = process.env.NODE_ENV === 'production'\n\n const getGlobalCodeSplitGroupings = () => {\n return (\n userConfig.codeSplittingOptions?.defaultBehavior ||\n defaultCodeSplitGroupings\n )\n }\n const getShouldSplitFn = () => {\n return userConfig.codeSplittingOptions?.splitBehavior\n }\n\n const handleCompilingReferenceFile = (\n code: string,\n id: string,\n generatorNodeInfo: GetRoutesByFileMapResultValue,\n ): UnpluginTransformResult => {\n if (debug) console.info('Compiling Route: ', id)\n\n const fromCode = detectCodeSplitGroupingsFromRoute({\n code,\n })\n\n if (fromCode.groupings) {\n const res = splitGroupingsSchema.safeParse(fromCode.groupings)\n if (!res.success) {\n const message = res.error.errors.map((e) => e.message).join('. ')\n throw new Error(\n `The groupings for the route \"${id}\" are invalid.\\n${message}`,\n )\n }\n }\n\n const userShouldSplitFn = getShouldSplitFn()\n\n const pluginSplitBehavior = userShouldSplitFn?.({\n routeId: generatorNodeInfo.routePath,\n }) as CodeSplitGroupings | undefined\n\n if (pluginSplitBehavior) {\n const res = splitGroupingsSchema.safeParse(pluginSplitBehavior)\n if (!res.success) {\n const message = res.error.errors.map((e) => e.message).join('. ')\n throw new Error(\n `The groupings returned when using \\`splitBehavior\\` for the route \"${id}\" are invalid.\\n${message}`,\n )\n }\n }\n\n const splitGroupings: CodeSplitGroupings =\n fromCode.groupings || pluginSplitBehavior || getGlobalCodeSplitGroupings()\n\n const compiledReferenceRoute = compileCodeSplitReferenceRoute({\n code,\n runtimeEnv: isProduction ? 'prod' : 'dev',\n codeSplitGroupings: splitGroupings,\n targetFramework: userConfig.target,\n filename: id,\n id,\n })\n\n if (debug) {\n logDiff(code, compiledReferenceRoute.code)\n console.log('Output:\\n', compiledReferenceRoute.code + '\\n\\n')\n }\n\n return compiledReferenceRoute\n }\n\n const handleCompilingVirtualFile = (\n code: string,\n id: string,\n ): UnpluginTransformResult => {\n if (debug) console.info('Splitting Route: ', id)\n\n const [_, ...pathnameParts] = id.split('?')\n\n const searchParams = new URLSearchParams(pathnameParts.join('?'))\n const splitValue = searchParams.get(tsrSplit)\n\n if (!splitValue) {\n throw new Error(\n `The split value for the virtual route \"${id}\" was not found.`,\n )\n }\n\n const rawGrouping = decodeIdentifier(splitValue)\n const grouping = [...new Set(rawGrouping)].filter((p) =>\n splitRouteIdentNodes.includes(p as any),\n ) as Array<SplitRouteIdentNodes>\n\n const result = compileCodeSplitVirtualRoute({\n code,\n filename: id,\n splitTargets: grouping,\n })\n\n if (debug) {\n logDiff(code, result.code)\n console.log('Output:\\n', result.code + '\\n\\n')\n }\n\n return result\n }\n\n return [\n {\n name: 'tanstack-router:code-splitter:compile-reference-file',\n enforce: 'pre',\n\n transform: {\n filter: {\n id: {\n exclude: tsrSplit,\n // this is necessary for webpack / rspack to avoid matching .html files\n include: /\\.(m|c)?(j|t)sx?$/,\n },\n code: 'createFileRoute(',\n },\n handler(code, id) {\n const generatorFileInfo = globalThis.TSR_ROUTES_BY_ID_MAP?.get(id)\n if (generatorFileInfo && code.includes('createFileRoute(')) {\n for (const externalPlugin of bannedBeforeExternalPlugins) {\n if (!externalPlugin.frameworks.includes(framework)) {\n continue\n }\n\n if (code.includes(externalPlugin.identifier)) {\n throw new FoundPluginInBeforeCode(externalPlugin, framework)\n }\n }\n\n return handleCompilingReferenceFile(code, id, generatorFileInfo)\n }\n\n return null\n },\n },\n\n vite: {\n configResolved(config) {\n ROOT = config.root\n userConfig = getConfig(options, ROOT)\n },\n },\n\n rspack() {\n ROOT = process.cwd()\n userConfig = getConfig(options, ROOT)\n },\n\n webpack(compiler) {\n ROOT = process.cwd()\n userConfig = getConfig(options, ROOT)\n\n if (compiler.options.mode === 'production') {\n compiler.hooks.done.tap(PLUGIN_NAME, () => {\n console.info('✅ ' + PLUGIN_NAME + ': code-splitting done!')\n setTimeout(() => {\n process.exit(0)\n })\n })\n }\n },\n },\n {\n name: 'tanstack-router:code-splitter:compile-virtual-file',\n enforce: 'pre',\n\n transform: {\n filter: {\n id: /tsr-split/,\n },\n handler(code, id) {\n const url = pathToFileURL(id)\n url.searchParams.delete('v')\n id = fileURLToPath(url).replace(/\\\\/g, '/')\n return handleCompilingVirtualFile(code, id)\n },\n },\n },\n ]\n}\n"],"names":[],"mappings":";;;;;;;AAoCA,MAAM,8BAAiE;AAAA,EACrE;AAAA,IACE,YAAY;AAAA,IACZ,KAAK;AAAA,IACL,OAAO;AAAA,IACP,YAAY,CAAC,MAAM;AAAA,EAAA;AAEvB;AAEA,MAAM,gCAAgC,MAAM;AAAA,EAC1C,YACE,gBACA,iBACA;AACA,UAAM,yBAAyB,eAAe,GAAG,gDAAgD,eAAe,wEAAwE,eAAe,GAAG;AAAA;AAAA;AAAA,2CAGnK,eAAe,KAAK;AAAA,IAC3D,eAAe,KAAK;AAAA;AAAA,CAEvB;AAAA,EAAA;AAED;AAEA,MAAM,cAAc;AAEb,MAAM,oCAET,CAAC,UAAU,IAAI,EAAE,gBAAgB;AAC/B,MAAA,OAAe,QAAQ,IAAI;AAC/B,MAAI,aAAa;AAEX,QAAA,eAAe,QAAQ,IAAI,aAAa;AAE9C,QAAM,8BAA8B,MAAM;;AAEtC,aAAA,gBAAW,yBAAX,mBAAiC,oBACjC;AAAA,EAEJ;AACA,QAAM,mBAAmB,MAAM;;AAC7B,YAAO,gBAAW,yBAAX,mBAAiC;AAAA,EAC1C;AAEA,QAAM,+BAA+B,CACnC,MACA,IACA,sBAC4B;AAC5B,QAAI,MAAO,SAAQ,KAAK,qBAAqB,EAAE;AAE/C,UAAM,WAAW,kCAAkC;AAAA,MACjD;AAAA,IAAA,CACD;AAED,QAAI,SAAS,WAAW;AACt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AU,SAAS,IAAI;AAAA,MACtC;AAAA,MAEA,QAAQ,UAAU;AAChB,eAAO,QAAQ,IAAI;AACN,qBAAA,UAAU,SAAS,IAAI;AAEhC,YAAA,SAAS,QAAQ,SAAS,cAAc;AAC1C,mBAAS,MAAM,KAAK,IAAI,aAAa,MAAM;AACjC,oBAAA,KAAK,OAAO,cAAc,wBAAwB;AAC1D,uBAAW,MAAM;AACf,sBAAQ,KAAK,CAAC;AAAA,YAAA,CACf;AAAA,UAAA,CACF;AAAA,QAAA;AAAA,MACH;AAAA,IAEJ;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,SAAS;AAAA,MAET,WAAW;AAAA,QACT,QAAQ;AAAA,UACN,IAAI;AAAA,QACN;AAAA,QACA,QAAQ,MAAM,IAAI;AACV,gBAAA,MAAM,cAAc,EAAE;AACxB,cAAA,aAAa,OAAO,GAAG;AAC3B,eAAK,cAAc,GAAG,EAAE,QAAQ,OAAO,GAAG;AACnC,iBAAA,2BAA2B,MAAM,EAAE;AAAA,QAAA;AAAA,MAC5C;AAAA,IACF;AAAA,EAEJ;AACF;"}
1
+ {"version":3,"file":"router-code-splitter-plugin.js","sources":["../../../src/core/router-code-splitter-plugin.ts"],"sourcesContent":["/**\n * It is important to familiarize yourself with how the code-splitting works in this plugin.\n * https://github.com/TanStack/router/pull/3355\n */\n\nimport { fileURLToPath, pathToFileURL } from 'node:url'\nimport { logDiff } from '@tanstack/router-utils'\nimport { getConfig, splitGroupingsSchema } from './config'\nimport {\n compileCodeSplitReferenceRoute,\n compileCodeSplitVirtualRoute,\n detectCodeSplitGroupingsFromRoute,\n} from './code-splitter/compilers'\nimport {\n defaultCodeSplitGroupings,\n splitRouteIdentNodes,\n tsrSplit,\n} from './constants'\nimport { decodeIdentifier } from './code-splitter/path-ids'\nimport { debug } from './utils'\nimport type { CodeSplitGroupings, SplitRouteIdentNodes } from './constants'\nimport type { GetRoutesByFileMapResultValue } from '@tanstack/router-generator'\nimport type { Config } from './config'\nimport type {\n UnpluginContextMeta,\n UnpluginFactory,\n TransformResult as UnpluginTransformResult,\n} from 'unplugin'\n\ntype BannedBeforeExternalPlugin = {\n identifier: string\n pkg: string\n usage: string\n frameworks: Array<UnpluginContextMeta['framework']>\n}\n\nconst bannedBeforeExternalPlugins: Array<BannedBeforeExternalPlugin> = [\n {\n identifier: '@react-refresh',\n pkg: '@vitejs/plugin-react',\n usage: 'viteReact()',\n frameworks: ['vite'],\n },\n]\n\nclass FoundPluginInBeforeCode extends Error {\n constructor(\n externalPlugin: BannedBeforeExternalPlugin,\n pluginFramework: string,\n ) {\n 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: \ne.g.\nplugins: [\n tanstackRouter(), // Place this before ${externalPlugin.usage}\n ${externalPlugin.usage},\n]\n`)\n }\n}\n\nconst PLUGIN_NAME = 'unplugin:router-code-splitter'\n\nexport const unpluginRouterCodeSplitterFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}, { framework }) => {\n let ROOT: string = process.cwd()\n let userConfig = options as Config\n\n const isProduction = process.env.NODE_ENV === 'production'\n\n const getGlobalCodeSplitGroupings = () => {\n return (\n userConfig.codeSplittingOptions?.defaultBehavior ||\n defaultCodeSplitGroupings\n )\n }\n const getShouldSplitFn = () => {\n return userConfig.codeSplittingOptions?.splitBehavior\n }\n\n const handleCompilingReferenceFile = (\n code: string,\n id: string,\n generatorNodeInfo: GetRoutesByFileMapResultValue,\n ): UnpluginTransformResult => {\n if (debug) console.info('Compiling Route: ', id)\n\n const fromCode = detectCodeSplitGroupingsFromRoute({\n code,\n })\n\n if (fromCode.groupings) {\n const res = splitGroupingsSchema.safeParse(fromCode.groupings)\n if (!res.success) {\n const message = res.error.errors.map((e) => e.message).join('. ')\n throw new Error(\n `The groupings for the route \"${id}\" are invalid.\\n${message}`,\n )\n }\n }\n\n const userShouldSplitFn = getShouldSplitFn()\n\n const pluginSplitBehavior = userShouldSplitFn?.({\n routeId: generatorNodeInfo.routePath,\n }) as CodeSplitGroupings | undefined\n\n if (pluginSplitBehavior) {\n const res = splitGroupingsSchema.safeParse(pluginSplitBehavior)\n if (!res.success) {\n const message = res.error.errors.map((e) => e.message).join('. ')\n throw new Error(\n `The groupings returned when using \\`splitBehavior\\` for the route \"${id}\" are invalid.\\n${message}`,\n )\n }\n }\n\n const splitGroupings: CodeSplitGroupings =\n fromCode.groupings || pluginSplitBehavior || getGlobalCodeSplitGroupings()\n\n const compiledReferenceRoute = compileCodeSplitReferenceRoute({\n code,\n codeSplitGroupings: splitGroupings,\n targetFramework: userConfig.target,\n filename: id,\n id,\n deleteNodes: new Set(userConfig.codeSplittingOptions?.deleteNodes),\n addHmr: options.codeSplittingOptions?.addHmr && !isProduction,\n })\n\n if (debug) {\n logDiff(code, compiledReferenceRoute.code)\n console.log('Output:\\n', compiledReferenceRoute.code + '\\n\\n')\n }\n\n return compiledReferenceRoute\n }\n\n const handleCompilingVirtualFile = (\n code: string,\n id: string,\n ): UnpluginTransformResult => {\n if (debug) console.info('Splitting Route: ', id)\n\n const [_, ...pathnameParts] = id.split('?')\n\n const searchParams = new URLSearchParams(pathnameParts.join('?'))\n const splitValue = searchParams.get(tsrSplit)\n\n if (!splitValue) {\n throw new Error(\n `The split value for the virtual route \"${id}\" was not found.`,\n )\n }\n\n const rawGrouping = decodeIdentifier(splitValue)\n const grouping = [...new Set(rawGrouping)].filter((p) =>\n splitRouteIdentNodes.includes(p as any),\n ) as Array<SplitRouteIdentNodes>\n\n const result = compileCodeSplitVirtualRoute({\n code,\n filename: id,\n splitTargets: grouping,\n })\n\n if (debug) {\n logDiff(code, result.code)\n console.log('Output:\\n', result.code + '\\n\\n')\n }\n\n return result\n }\n\n const includedCode = [\n 'createFileRoute(',\n 'createRootRoute(',\n 'createRootRouteWithContext(',\n ]\n return [\n {\n name: 'tanstack-router:code-splitter:compile-reference-file',\n enforce: 'pre',\n\n transform: {\n filter: {\n id: {\n exclude: tsrSplit,\n // this is necessary for webpack / rspack to avoid matching .html files\n include: /\\.(m|c)?(j|t)sx?$/,\n },\n code: {\n include: includedCode,\n },\n },\n handler(code, id) {\n const generatorFileInfo = globalThis.TSR_ROUTES_BY_ID_MAP?.get(id)\n if (\n generatorFileInfo &&\n includedCode.some((included) => code.includes(included))\n ) {\n for (const externalPlugin of bannedBeforeExternalPlugins) {\n if (!externalPlugin.frameworks.includes(framework)) {\n continue\n }\n\n if (code.includes(externalPlugin.identifier)) {\n throw new FoundPluginInBeforeCode(externalPlugin, framework)\n }\n }\n\n return handleCompilingReferenceFile(code, id, generatorFileInfo)\n }\n\n return null\n },\n },\n\n vite: {\n configResolved(config) {\n ROOT = config.root\n userConfig = getConfig(options, ROOT)\n },\n applyToEnvironment(environment) {\n if (userConfig.plugin?.vite?.environmentName) {\n return userConfig.plugin.vite.environmentName === environment.name\n }\n return true\n },\n },\n\n rspack() {\n ROOT = process.cwd()\n userConfig = getConfig(options, ROOT)\n },\n\n webpack(compiler) {\n ROOT = process.cwd()\n userConfig = getConfig(options, ROOT)\n\n if (compiler.options.mode === 'production') {\n compiler.hooks.done.tap(PLUGIN_NAME, () => {\n console.info('✅ ' + PLUGIN_NAME + ': code-splitting done!')\n setTimeout(() => {\n process.exit(0)\n })\n })\n }\n },\n },\n {\n name: 'tanstack-router:code-splitter:compile-virtual-file',\n enforce: 'pre',\n\n transform: {\n filter: {\n id: /tsr-split/,\n },\n handler(code, id) {\n const url = pathToFileURL(id)\n url.searchParams.delete('v')\n id = fileURLToPath(url).replace(/\\\\/g, '/')\n return handleCompilingVirtualFile(code, id)\n },\n },\n },\n ]\n}\n"],"names":[],"mappings":";;;;;;;AAoCA,MAAM,8BAAiE;AAAA,EACrE;AAAA,IACE,YAAY;AAAA,IACZ,KAAK;AAAA,IACL,OAAO;AAAA,IACP,YAAY,CAAC,MAAM;AAAA,EAAA;AAEvB;AAEA,MAAM,gCAAgC,MAAM;AAAA,EAC1C,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,MAAM;AACjC,oBAAA,KAAK,OAAO,cAAc,wBAAwB;AAC1D,uBAAW,MAAM;AACf,sBAAQ,KAAK,CAAC;AAAA,YAAA,CACf;AAAA,UAAA,CACF;AAAA,QAAA;AAAA,MACH;AAAA,IAEJ;AAAA,IACA;AAAA,MACE,MAAM;AAAA,MACN,SAAS;AAAA,MAET,WAAW;AAAA,QACT,QAAQ;AAAA,UACN,IAAI;AAAA,QACN;AAAA,QACA,QAAQ,MAAM,IAAI;AACV,gBAAA,MAAM,cAAc,EAAE;AACxB,cAAA,aAAa,OAAO,GAAG;AAC3B,eAAK,cAAc,GAAG,EAAE,QAAQ,OAAO,GAAG;AACnC,iBAAA,2BAA2B,MAAM,EAAE;AAAA,QAAA;AAAA,MAC5C;AAAA,IACF;AAAA,EAEJ;AACF;"}
@@ -53,11 +53,14 @@ const unpluginRouterGeneratorFactory = (options = {}) => {
53
53
  configResolved() {
54
54
  initConfigAndGenerator();
55
55
  },
56
- async buildStart() {
56
+ applyToEnvironment(environment) {
57
57
  var _a, _b;
58
- if (((_b = (_a = this.environment) == null ? void 0 : _a.config) == null ? void 0 : _b.consumer) === "server") {
59
- return;
58
+ if ((_b = (_a = userConfig.plugin) == null ? void 0 : _a.vite) == null ? void 0 : _b.environmentName) {
59
+ return userConfig.plugin.vite.environmentName === environment.name;
60
60
  }
61
+ return true;
62
+ },
63
+ async buildStart() {
61
64
  await generate();
62
65
  },
63
66
  sharedDuringBuild: true
@@ -1 +1 @@
1
- {"version":3,"file":"router-generator-plugin.js","sources":["../../../src/core/router-generator-plugin.ts"],"sourcesContent":["import { isAbsolute, join, normalize } from 'node:path'\nimport { Generator, resolveConfigPath } from '@tanstack/router-generator'\nimport { getConfig } from './config'\n\nimport type { GeneratorEvent } from '@tanstack/router-generator'\nimport type { FSWatcher } from 'chokidar'\nimport type { UnpluginFactory } from 'unplugin'\nimport type { Config } from './config'\n\nconst PLUGIN_NAME = 'unplugin:router-generator'\n\nexport const unpluginRouterGeneratorFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}) => {\n const ROOT: string = process.cwd()\n let userConfig = options as Config\n let generator: Generator\n\n const routeGenerationDisabled = () =>\n userConfig.enableRouteGeneration === false\n const getRoutesDirectoryPath = () => {\n return isAbsolute(userConfig.routesDirectory)\n ? userConfig.routesDirectory\n : join(ROOT, userConfig.routesDirectory)\n }\n\n const initConfigAndGenerator = () => {\n userConfig = getConfig(options, ROOT)\n generator = new Generator({\n config: userConfig,\n root: ROOT,\n })\n }\n\n const generate = async (opts?: {\n file: string\n event: 'create' | 'update' | 'delete'\n }) => {\n if (routeGenerationDisabled()) {\n return\n }\n let generatorEvent: GeneratorEvent | undefined = undefined\n if (opts) {\n const filePath = normalize(opts.file)\n if (filePath === resolveConfigPath({ configDirectory: ROOT })) {\n initConfigAndGenerator()\n return\n }\n generatorEvent = { path: filePath, type: opts.event }\n }\n\n try {\n await generator.run(generatorEvent)\n globalThis.TSR_ROUTES_BY_ID_MAP = generator.getRoutesByFileMap()\n } catch (e) {\n console.error(e)\n }\n }\n\n return {\n name: 'tanstack:router-generator',\n enforce: 'pre',\n async watchChange(id, { event }) {\n await generate({\n file: id,\n event,\n })\n },\n async buildStart() {\n await generate()\n },\n vite: {\n configResolved() {\n initConfigAndGenerator()\n },\n async buildStart() {\n // to support vite 5, we need to optionally chain the access to the environment\n // eslint-disable-next-line @typescript-eslint/no-unnecessary-condition\n if (this.environment?.config?.consumer === 'server') {\n // When building in environment mode, we only need to generate routes\n // for the client environment\n return\n }\n await generate()\n },\n sharedDuringBuild: true,\n },\n rspack(compiler) {\n initConfigAndGenerator()\n\n let handle: FSWatcher | null = null\n\n compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, () => generate())\n\n compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {\n if (handle) {\n return\n }\n\n // rspack watcher doesn't register newly created files\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n handle = chokidar\n .watch(routesDirectoryPath, { ignoreInitial: true })\n .on('add', (file) => generate({ file, event: 'create' }))\n\n await generate()\n })\n\n compiler.hooks.watchClose.tap(PLUGIN_NAME, async () => {\n if (handle) {\n await handle.close()\n }\n })\n },\n webpack(compiler) {\n initConfigAndGenerator()\n\n let handle: FSWatcher | null = null\n\n compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, () => generate())\n\n compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {\n if (handle) {\n return\n }\n\n // webpack watcher doesn't register newly created files\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n handle = chokidar\n .watch(routesDirectoryPath, { ignoreInitial: true })\n .on('add', (file) => generate({ file, event: 'create' }))\n\n await generate()\n })\n\n compiler.hooks.watchClose.tap(PLUGIN_NAME, async () => {\n if (handle) {\n await handle.close()\n }\n })\n\n compiler.hooks.done.tap(PLUGIN_NAME, () => {\n console.info('✅ ' + PLUGIN_NAME + ': route-tree generation done')\n })\n },\n }\n}\n"],"names":[],"mappings":";;;AASA,MAAM,cAAc;AAEb,MAAM,iCAET,CAAC,UAAU,OAAO;AACd,QAAA,OAAe,QAAQ,IAAI;AACjC,MAAI,aAAa;AACb,MAAA;AAEE,QAAA,0BAA0B,MAC9B,WAAW,0BAA0B;AACvC,QAAM,yBAAyB,MAAM;AAC5B,WAAA,WAAW,WAAW,eAAe,IACxC,WAAW,kBACX,KAAK,MAAM,WAAW,eAAe;AAAA,EAC3C;AAEA,QAAM,yBAAyB,MAAM;AACtB,iBAAA,UAAU,SAAS,IAAI;AACpC,gBAAY,IAAI,UAAU;AAAA,MACxB,QAAQ;AAAA,MACR,MAAM;AAAA,IAAA,CACP;AAAA,EACH;AAEM,QAAA,WAAW,OAAO,SAGlB;AACJ,QAAI,2BAA2B;AAC7B;AAAA,IAAA;AAEF,QAAI,iBAA6C;AACjD,QAAI,MAAM;AACF,YAAA,WAAW,UAAU,KAAK,IAAI;AACpC,UAAI,aAAa,kBAAkB,EAAE,iBAAiB,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D;AAAA,IACH;AAAA,IACA,QAAQ,UAAU;AACO,6BAAA;AAEvB,UAAI,SAA2B;AAE/B,eAAS,MAAM,UAAU,WAAW,aAAa,MAAM,UAAU;AAEjE,eAAS,MAAM,SAAS,WAAW,aAAa,YAAY;AAC1D,YAAI,QAAQ;AACV;AAAA,QAAA;AAIF,cAAM,sBAAsB,uBAAuB;AAC7C,cAAA,WAAW,MAAM,OAAO,UAAU;AACxC,iBAAS,SACN,MAAM,qBAAqB,EAAE,eAAe,KAAA,CAAM,EAClD,GAAG,OAAO,CAAC,SAAS,SAAS,EAAE,MAAM,OAAO,SAAA,CAAU,CAAC;AAE1D,cAAM,SAAS;AAAA,MAAA,CAChB;AAED,eAAS,MAAM,WAAW,IAAI,aAAa,YAAY;AACrD,YAAI,QAAQ;AACV,gBAAM,OAAO,MAAM;AAAA,QAAA;AAAA,MACrB,CACD;AAED,eAAS,MAAM,KAAK,IAAI,aAAa,MAAM;AACjC,gBAAA,KAAK,OAAO,cAAc,8BAA8B;AAAA,MAAA,CACjE;AAAA,IAAA;AAAA,EAEL;AACF;"}
1
+ {"version":3,"file":"router-generator-plugin.js","sources":["../../../src/core/router-generator-plugin.ts"],"sourcesContent":["import { isAbsolute, join, normalize } from 'node:path'\nimport { Generator, resolveConfigPath } from '@tanstack/router-generator'\nimport { getConfig } from './config'\n\nimport type { GeneratorEvent } from '@tanstack/router-generator'\nimport type { FSWatcher } from 'chokidar'\nimport type { UnpluginFactory } from 'unplugin'\nimport type { Config } from './config'\n\nconst PLUGIN_NAME = 'unplugin:router-generator'\n\nexport const unpluginRouterGeneratorFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}) => {\n const ROOT: string = process.cwd()\n let userConfig = options as Config\n let generator: Generator\n\n const routeGenerationDisabled = () =>\n userConfig.enableRouteGeneration === false\n const getRoutesDirectoryPath = () => {\n return isAbsolute(userConfig.routesDirectory)\n ? userConfig.routesDirectory\n : join(ROOT, userConfig.routesDirectory)\n }\n\n const initConfigAndGenerator = () => {\n userConfig = getConfig(options, ROOT)\n generator = new Generator({\n config: userConfig,\n root: ROOT,\n })\n }\n\n const generate = async (opts?: {\n file: string\n event: 'create' | 'update' | 'delete'\n }) => {\n if (routeGenerationDisabled()) {\n return\n }\n let generatorEvent: GeneratorEvent | undefined = undefined\n if (opts) {\n const filePath = normalize(opts.file)\n if (filePath === resolveConfigPath({ configDirectory: ROOT })) {\n initConfigAndGenerator()\n return\n }\n generatorEvent = { path: filePath, type: opts.event }\n }\n\n try {\n await generator.run(generatorEvent)\n globalThis.TSR_ROUTES_BY_ID_MAP = generator.getRoutesByFileMap()\n } catch (e) {\n console.error(e)\n }\n }\n\n return {\n name: 'tanstack:router-generator',\n enforce: 'pre',\n async watchChange(id, { event }) {\n await generate({\n file: id,\n event,\n })\n },\n async buildStart() {\n await generate()\n },\n vite: {\n configResolved() {\n initConfigAndGenerator()\n },\n applyToEnvironment(environment) {\n if (userConfig.plugin?.vite?.environmentName) {\n return userConfig.plugin.vite.environmentName === environment.name\n }\n return true\n },\n async buildStart() {\n await generate()\n },\n sharedDuringBuild: true,\n },\n rspack(compiler) {\n initConfigAndGenerator()\n\n let handle: FSWatcher | null = null\n\n compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, () => generate())\n\n compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {\n if (handle) {\n return\n }\n\n // rspack watcher doesn't register newly created files\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n handle = chokidar\n .watch(routesDirectoryPath, { ignoreInitial: true })\n .on('add', (file) => generate({ file, event: 'create' }))\n\n await generate()\n })\n\n compiler.hooks.watchClose.tap(PLUGIN_NAME, async () => {\n if (handle) {\n await handle.close()\n }\n })\n },\n webpack(compiler) {\n initConfigAndGenerator()\n\n let handle: FSWatcher | null = null\n\n compiler.hooks.beforeRun.tapPromise(PLUGIN_NAME, () => generate())\n\n compiler.hooks.watchRun.tapPromise(PLUGIN_NAME, async () => {\n if (handle) {\n return\n }\n\n // webpack watcher doesn't register newly created files\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n handle = chokidar\n .watch(routesDirectoryPath, { ignoreInitial: true })\n .on('add', (file) => generate({ file, event: 'create' }))\n\n await generate()\n })\n\n compiler.hooks.watchClose.tap(PLUGIN_NAME, async () => {\n if (handle) {\n await handle.close()\n }\n })\n\n compiler.hooks.done.tap(PLUGIN_NAME, () => {\n console.info('✅ ' + PLUGIN_NAME + ': route-tree generation done')\n })\n },\n }\n}\n"],"names":[],"mappings":";;;AASA,MAAM,cAAc;AAEb,MAAM,iCAET,CAAC,UAAU,OAAO;AACd,QAAA,OAAe,QAAQ,IAAI;AACjC,MAAI,aAAa;AACb,MAAA;AAEE,QAAA,0BAA0B,MAC9B,WAAW,0BAA0B;AACvC,QAAM,yBAAyB,MAAM;AAC5B,WAAA,WAAW,WAAW,eAAe,IACxC,WAAW,kBACX,KAAK,MAAM,WAAW,eAAe;AAAA,EAC3C;AAEA,QAAM,yBAAyB,MAAM;AACtB,iBAAA,UAAU,SAAS,IAAI;AACpC,gBAAY,IAAI,UAAU;AAAA,MACxB,QAAQ;AAAA,MACR,MAAM;AAAA,IAAA,CACP;AAAA,EACH;AAEM,QAAA,WAAW,OAAO,SAGlB;AACJ,QAAI,2BAA2B;AAC7B;AAAA,IAAA;AAEF,QAAI,iBAA6C;AACjD,QAAI,MAAM;AACF,YAAA,WAAW,UAAU,KAAK,IAAI;AACpC,UAAI,aAAa,kBAAkB,EAAE,iBAAiB,KAAM,CAAA,GAAG;AACtC,+BAAA;AACvB;AAAA,MAAA;AAEF,uBAAiB,EAAE,MAAM,UAAU,MAAM,KAAK,MAAM;AAAA,IAAA;AAGlD,QAAA;AACI,YAAA,UAAU,IAAI,cAAc;AACvB,iBAAA,uBAAuB,UAAU,mBAAmB;AAAA,aACxD,GAAG;AACV,cAAQ,MAAM,CAAC;AAAA,IAAA;AAAA,EAEnB;AAEO,SAAA;AAAA,IACL,MAA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AAIF,cAAM,sBAAsB,uBAAuB;AAC7C,cAAA,WAAW,MAAM,OAAO,UAAU;AACxC,iBAAS,SACN,MAAM,qBAAqB,EAAE,eAAe,KAAA,CAAM,EAClD,GAAG,OAAO,CAAC,SAAS,SAAS,EAAE,MAAM,OAAO,SAAA,CAAU,CAAC;AAE1D,cAAM,SAAS;AAAA,MAAA,CAChB;AAED,eAAS,MAAM,WAAW,IAAI,aAAa,YAAY;AACrD,YAAI,QAAQ;AACV,gBAAM,OAAO,MAAM;AAAA,QAAA;AAAA,MACrB,CACD;AAED,eAAS,MAAM,KAAK,IAAI,aAAa,MAAM;AACjC,gBAAA,KAAK,OAAO,cAAc,8BAA8B;AAAA,MAAA,CACjE;AAAA,IAAA;AAAA,EAEL;AACF;"}
@@ -1,8 +1,3 @@
1
- import { Config } from './config.js';
2
1
  import { UnpluginFactory } from 'unplugin';
3
- /**
4
- * This plugin adds HMR support for file routes.
5
- * It is only added to the composed plugin in dev when autoCodeSplitting is disabled, since the code splitting plugin
6
- * handles HMR for code-split routes itself.
7
- */
2
+ import { Config } from './config.js';
8
3
  export declare const unpluginRouterHmrFactory: UnpluginFactory<Partial<Config> | undefined>;
@@ -1,7 +1,15 @@
1
1
  import { parseAst, generateFromAst, logDiff } from "@tanstack/router-utils";
2
2
  import { routeHmrStatement } from "./route-hmr-statement.js";
3
3
  import { debug } from "./utils.js";
4
- const unpluginRouterHmrFactory = () => {
4
+ import { getConfig } from "./config.js";
5
+ const includeCode = [
6
+ "createFileRoute(",
7
+ "createRootRoute(",
8
+ "createRootRouteWithContext("
9
+ ];
10
+ const unpluginRouterHmrFactory = (options = {}) => {
11
+ let ROOT = process.cwd();
12
+ let userConfig = options;
5
13
  return {
6
14
  name: "tanstack-router:hmr",
7
15
  enforce: "pre",
@@ -9,7 +17,9 @@ const unpluginRouterHmrFactory = () => {
9
17
  filter: {
10
18
  // this is necessary for webpack / rspack to avoid matching .html files
11
19
  id: /\.(m|c)?(j|t)sx?$/,
12
- code: "createFileRoute("
20
+ code: {
21
+ include: includeCode
22
+ }
13
23
  },
14
24
  handler(code, id) {
15
25
  var _a;
@@ -30,6 +40,19 @@ const unpluginRouterHmrFactory = () => {
30
40
  }
31
41
  return result;
32
42
  }
43
+ },
44
+ vite: {
45
+ configResolved(config) {
46
+ ROOT = config.root;
47
+ userConfig = getConfig(options, ROOT);
48
+ },
49
+ applyToEnvironment(environment) {
50
+ var _a, _b;
51
+ if ((_b = (_a = userConfig.plugin) == null ? void 0 : _a.vite) == null ? void 0 : _b.environmentName) {
52
+ return userConfig.plugin.vite.environmentName === environment.name;
53
+ }
54
+ return true;
55
+ }
33
56
  }
34
57
  };
35
58
  };