@tanstack/router-plugin 1.167.31 → 1.167.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/context.cjs +3 -0
- package/dist/cjs/context.d.cts +2 -0
- package/dist/cjs/core/code-splitter/compilers.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/compilers.d.cts +1 -0
- package/dist/cjs/core/router-code-splitter-plugin.cjs +12 -3
- package/dist/cjs/core/router-code-splitter-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-code-splitter-plugin.d.cts +2 -0
- package/dist/cjs/core/router-composed-plugin.cjs +7 -6
- package/dist/cjs/core/router-composed-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-generator-plugin.cjs +7 -2
- package/dist/cjs/core/router-generator-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-generator-plugin.d.cts +2 -0
- package/dist/cjs/core/router-hmr-plugin.cjs +13 -7
- package/dist/cjs/core/router-hmr-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-hmr-plugin.d.cts +2 -0
- package/dist/cjs/core/router-plugin-context.cjs +8 -0
- package/dist/cjs/core/router-plugin-context.cjs.map +1 -0
- package/dist/cjs/core/router-plugin-context.d.cts +5 -0
- package/dist/cjs/esbuild.cjs +10 -2
- package/dist/cjs/esbuild.cjs.map +1 -1
- package/dist/cjs/esbuild.d.cts +5 -95
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/index.d.cts +2 -0
- package/dist/cjs/rspack.cjs +10 -2
- package/dist/cjs/rspack.cjs.map +1 -1
- package/dist/cjs/rspack.d.cts +5 -49
- package/dist/cjs/vite.cjs +11 -2
- package/dist/cjs/vite.cjs.map +1 -1
- package/dist/cjs/vite.d.cts +6 -96
- package/dist/cjs/webpack.cjs +10 -2
- package/dist/cjs/webpack.cjs.map +1 -1
- package/dist/cjs/webpack.d.cts +4 -49
- package/dist/esm/context.d.ts +2 -0
- package/dist/esm/context.js +2 -0
- package/dist/esm/core/code-splitter/compilers.d.ts +1 -0
- package/dist/esm/core/code-splitter/compilers.js.map +1 -1
- package/dist/esm/core/router-code-splitter-plugin.d.ts +2 -0
- package/dist/esm/core/router-code-splitter-plugin.js +12 -4
- package/dist/esm/core/router-code-splitter-plugin.js.map +1 -1
- package/dist/esm/core/router-composed-plugin.js +10 -9
- package/dist/esm/core/router-composed-plugin.js.map +1 -1
- package/dist/esm/core/router-generator-plugin.d.ts +2 -0
- package/dist/esm/core/router-generator-plugin.js +7 -3
- package/dist/esm/core/router-generator-plugin.js.map +1 -1
- package/dist/esm/core/router-hmr-plugin.d.ts +2 -0
- package/dist/esm/core/router-hmr-plugin.js +13 -7
- package/dist/esm/core/router-hmr-plugin.js.map +1 -1
- package/dist/esm/core/router-plugin-context.d.ts +5 -0
- package/dist/esm/core/router-plugin-context.js +8 -0
- package/dist/esm/core/router-plugin-context.js.map +1 -0
- package/dist/esm/esbuild.d.ts +5 -95
- package/dist/esm/esbuild.js +12 -4
- package/dist/esm/esbuild.js.map +1 -1
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +2 -1
- package/dist/esm/rspack.d.ts +5 -49
- package/dist/esm/rspack.js +12 -4
- package/dist/esm/rspack.js.map +1 -1
- package/dist/esm/vite.d.ts +6 -96
- package/dist/esm/vite.js +14 -6
- package/dist/esm/vite.js.map +1 -1
- package/dist/esm/webpack.d.ts +4 -49
- package/dist/esm/webpack.js +12 -4
- package/dist/esm/webpack.js.map +1 -1
- package/package.json +13 -7
- package/src/context.ts +2 -0
- package/src/core/code-splitter/compilers.ts +1 -0
- package/src/core/router-code-splitter-plugin.ts +15 -4
- package/src/core/router-composed-plugin.ts +16 -11
- package/src/core/router-generator-plugin.ts +13 -4
- package/src/core/router-hmr-plugin.ts +22 -7
- package/src/core/router-plugin-context.ts +11 -0
- package/src/esbuild.ts +27 -9
- package/src/index.ts +2 -0
- package/src/rspack.ts +30 -12
- package/src/vite.ts +29 -9
- package/src/webpack.ts +27 -12
- package/bin/intent.js +0 -25
- package/src/global.d.ts +0 -7
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-code-splitter-plugin.js","names":[],"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 compileCodeSplitSharedRoute,\n compileCodeSplitVirtualRoute,\n computeSharedBindings,\n detectCodeSplitGroupingsFromRoute,\n} from './code-splitter/compilers'\nimport { getReferenceRouteCompilerPlugins } from './code-splitter/plugins/framework-plugins'\nimport {\n defaultCodeSplitGroupings,\n splitRouteIdentNodes,\n tsrShared,\n tsrSplit,\n} from './constants'\nimport { decodeIdentifier } from './code-splitter/path-ids'\nimport { debug, normalizePath } from './utils'\nimport type { CodeSplitGroupings, SplitRouteIdentNodes } from './constants'\nimport type { GetRoutesByFileMapResultValue } from '@tanstack/router-generator'\nimport type { Config } from './config'\nimport type {\n UnpluginFactory,\n TransformResult as UnpluginTransformResult,\n} from 'unplugin'\n\nconst CODE_SPLITTER_PLUGIN_NAME =\n 'tanstack-router:code-splitter:compile-reference-file'\n\ntype TransformationPluginInfo = {\n pluginNames: Array<string>\n pkg: string\n usage: string\n}\n\n/**\n * JSX transformation plugins grouped by framework.\n * These plugins must come AFTER the TanStack Router plugin in the Vite config.\n */\nconst TRANSFORMATION_PLUGINS_BY_FRAMEWORK: Record<\n string,\n Array<TransformationPluginInfo>\n> = {\n react: [\n {\n // Babel-based React plugin\n pluginNames: ['vite:react-babel', 'vite:react-refresh'],\n pkg: '@vitejs/plugin-react',\n usage: 'react()',\n },\n {\n // SWC-based React plugin\n pluginNames: ['vite:react-swc', 'vite:react-swc:resolve-runtime'],\n pkg: '@vitejs/plugin-react-swc',\n usage: 'reactSwc()',\n },\n {\n // OXC-based React plugin (deprecated but should still be handled)\n pluginNames: ['vite:react-oxc:config', 'vite:react-oxc:refresh-runtime'],\n pkg: '@vitejs/plugin-react-oxc',\n usage: 'reactOxc()',\n },\n ],\n solid: [\n {\n pluginNames: ['solid'],\n pkg: 'vite-plugin-solid',\n usage: 'solid()',\n },\n ],\n}\n\nexport const unpluginRouterCodeSplitterFactory: UnpluginFactory<\n Partial<Config | (() => Config)> | undefined\n> = (options = {}, { framework: _framework }) => {\n let ROOT: string = process.cwd()\n let userConfig: Config\n\n function initUserConfig() {\n if (typeof options === 'function') {\n userConfig = options()\n } else {\n userConfig = getConfig(options, ROOT)\n }\n }\n const isProduction = process.env.NODE_ENV === 'production'\n // Map from normalized route file path → set of shared binding names.\n // Populated by the reference compiler, consumed by virtual and shared compilers.\n const sharedBindingsMap = new Map<string, Set<string>>()\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 !== undefined) {\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.routeId,\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 // Compute shared bindings before compiling the reference route\n const sharedBindings = computeSharedBindings({\n code,\n codeSplitGroupings: splitGroupings,\n })\n if (sharedBindings.size > 0) {\n sharedBindingsMap.set(id, sharedBindings)\n } else {\n sharedBindingsMap.delete(id)\n }\n\n const addHmr =\n (userConfig.codeSplittingOptions?.addHmr ?? true) && !isProduction\n const hmrStyle = userConfig.plugin?.hmr?.style ?? 'vite'\n\n const compiledReferenceRoute = compileCodeSplitReferenceRoute({\n code,\n codeSplitGroupings: splitGroupings,\n targetFramework: userConfig.target,\n filename: id,\n id,\n deleteNodes: userConfig.codeSplittingOptions?.deleteNodes\n ? new Set(userConfig.codeSplittingOptions.deleteNodes)\n : undefined,\n addHmr,\n hmrStyle,\n hmrRouteId: generatorNodeInfo.routeId,\n sharedBindings: sharedBindings.size > 0 ? sharedBindings : undefined,\n compilerPlugins: getReferenceRouteCompilerPlugins({\n targetFramework: userConfig.target,\n addHmr,\n hmrStyle,\n }),\n })\n\n if (compiledReferenceRoute === null) {\n if (debug) {\n console.info(\n `No changes made to route \"${id}\", skipping code-splitting.`,\n )\n }\n return null\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 baseId = id.split('?')[0]!\n const resolvedSharedBindings = sharedBindingsMap.get(baseId)\n\n const result = compileCodeSplitVirtualRoute({\n code,\n filename: id,\n splitTargets: grouping,\n sharedBindings: resolvedSharedBindings,\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, tsrShared],\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 normalizedId = normalizePath(id)\n const generatorFileInfo =\n globalThis.TSR_ROUTES_BY_ID_MAP?.get(normalizedId)\n if (\n generatorFileInfo &&\n includedCode.some((included) => code.includes(included))\n ) {\n return handleCompilingReferenceFile(\n code,\n normalizedId,\n generatorFileInfo,\n )\n }\n\n return null\n },\n },\n\n vite: {\n configResolved(config) {\n ROOT = config.root\n initUserConfig()\n\n // Validate plugin order - router must come before JSX transformation plugins\n const routerPluginIndex = config.plugins.findIndex(\n (p) => p.name === CODE_SPLITTER_PLUGIN_NAME,\n )\n\n if (routerPluginIndex === -1) return\n\n const frameworkPlugins =\n TRANSFORMATION_PLUGINS_BY_FRAMEWORK[userConfig.target]\n if (!frameworkPlugins) return\n\n for (const transformPlugin of frameworkPlugins) {\n const transformPluginIndex = config.plugins.findIndex((p) =>\n transformPlugin.pluginNames.includes(p.name),\n )\n\n if (\n transformPluginIndex !== -1 &&\n transformPluginIndex < routerPluginIndex\n ) {\n throw new Error(\n `Plugin order error: '${transformPlugin.pkg}' is placed before '@tanstack/router-plugin'.\\n\\n` +\n `The TanStack Router plugin must come BEFORE JSX transformation plugins.\\n\\n` +\n `Please update your Vite config:\\n\\n` +\n ` plugins: [\\n` +\n ` tanstackRouter(),\\n` +\n ` ${transformPlugin.usage},\\n` +\n ` ]\\n`,\n )\n }\n }\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 initUserConfig()\n },\n\n webpack() {\n ROOT = process.cwd()\n initUserConfig()\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 const normalizedId = normalizePath(fileURLToPath(url))\n return handleCompilingVirtualFile(code, normalizedId)\n },\n },\n\n vite: {\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 {\n name: 'tanstack-router:code-splitter:compile-shared-file',\n enforce: 'pre',\n\n transform: {\n filter: {\n id: /tsr-shared/,\n },\n handler(code, id) {\n const url = pathToFileURL(id)\n url.searchParams.delete('v')\n const normalizedId = normalizePath(fileURLToPath(url))\n const [baseId] = normalizedId.split('?')\n\n if (!baseId) return null\n\n const sharedBindings = sharedBindingsMap.get(baseId)\n if (!sharedBindings || sharedBindings.size === 0) return null\n\n if (debug) console.info('Compiling Shared Module: ', id)\n\n const result = compileCodeSplitSharedRoute({\n code,\n sharedBindings,\n filename: normalizedId,\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\n vite: {\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 ]\n}\n"],"mappings":";;;;;;;;;;;;;AAgCA,IAAM,4BACJ;;;;;AAYF,IAAM,sCAGF;CACF,OAAO;EACL;GA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EV;GACF;EACF"}
|
|
1
|
+
{"version":3,"file":"router-code-splitter-plugin.js","names":[],"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 compileCodeSplitSharedRoute,\n compileCodeSplitVirtualRoute,\n computeSharedBindings,\n detectCodeSplitGroupingsFromRoute,\n} from './code-splitter/compilers'\nimport { getReferenceRouteCompilerPlugins } from './code-splitter/plugins/framework-plugins'\nimport {\n defaultCodeSplitGroupings,\n splitRouteIdentNodes,\n tsrShared,\n tsrSplit,\n} from './constants'\nimport { decodeIdentifier } from './code-splitter/path-ids'\nimport { debug, normalizePath } from './utils'\nimport { createRouterPluginContext } from './router-plugin-context'\nimport type { CodeSplitGroupings, SplitRouteIdentNodes } from './constants'\nimport type { GetRoutesByFileMapResultValue } from '@tanstack/router-generator'\nimport type { Config } from './config'\nimport type { RouterPluginContext } from './router-plugin-context'\nimport type {\n UnpluginFactory,\n TransformResult as UnpluginTransformResult,\n} from 'unplugin'\n\nconst CODE_SPLITTER_PLUGIN_NAME =\n 'tanstack-router:code-splitter:compile-reference-file'\n\ntype TransformationPluginInfo = {\n pluginNames: Array<string>\n pkg: string\n usage: string\n}\n\n/**\n * JSX transformation plugins grouped by framework.\n * These plugins must come AFTER the TanStack Router plugin in the Vite config.\n */\nconst TRANSFORMATION_PLUGINS_BY_FRAMEWORK: Record<\n string,\n Array<TransformationPluginInfo>\n> = {\n react: [\n {\n // Babel-based React plugin\n pluginNames: ['vite:react-babel', 'vite:react-refresh'],\n pkg: '@vitejs/plugin-react',\n usage: 'react()',\n },\n {\n // SWC-based React plugin\n pluginNames: ['vite:react-swc', 'vite:react-swc:resolve-runtime'],\n pkg: '@vitejs/plugin-react-swc',\n usage: 'reactSwc()',\n },\n {\n // OXC-based React plugin (deprecated but should still be handled)\n pluginNames: ['vite:react-oxc:config', 'vite:react-oxc:refresh-runtime'],\n pkg: '@vitejs/plugin-react-oxc',\n usage: 'reactOxc()',\n },\n ],\n solid: [\n {\n pluginNames: ['solid'],\n pkg: 'vite-plugin-solid',\n usage: 'solid()',\n },\n ],\n}\n\nexport function createRouterCodeSplitterPlugin(\n options: Partial<Config | (() => Config)> | undefined = {},\n routerPluginContext: RouterPluginContext,\n): ReturnType<UnpluginFactory<Partial<Config | (() => Config)> | undefined>> {\n let ROOT: string = process.cwd()\n let userConfig: Config\n\n function initUserConfig() {\n if (typeof options === 'function') {\n userConfig = options()\n } else {\n userConfig = getConfig(options, ROOT)\n }\n }\n const isProduction = process.env.NODE_ENV === 'production'\n // Map from normalized route file path → set of shared binding names.\n // Populated by the reference compiler, consumed by virtual and shared compilers.\n const sharedBindingsMap = new Map<string, Set<string>>()\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 filename: id,\n })\n\n if (fromCode.groupings !== undefined) {\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.routeId,\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 // Compute shared bindings before compiling the reference route\n const sharedBindings = computeSharedBindings({\n code,\n filename: id,\n codeSplitGroupings: splitGroupings,\n })\n if (sharedBindings.size > 0) {\n sharedBindingsMap.set(id, sharedBindings)\n } else {\n sharedBindingsMap.delete(id)\n }\n\n const addHmr =\n (userConfig.codeSplittingOptions?.addHmr ?? true) && !isProduction\n const hmrStyle = userConfig.plugin?.hmr?.style ?? 'vite'\n\n const compiledReferenceRoute = compileCodeSplitReferenceRoute({\n code,\n codeSplitGroupings: splitGroupings,\n targetFramework: userConfig.target,\n filename: id,\n id,\n deleteNodes: userConfig.codeSplittingOptions?.deleteNodes\n ? new Set(userConfig.codeSplittingOptions.deleteNodes)\n : undefined,\n addHmr,\n hmrStyle,\n hmrRouteId: generatorNodeInfo.routeId,\n sharedBindings: sharedBindings.size > 0 ? sharedBindings : undefined,\n compilerPlugins: getReferenceRouteCompilerPlugins({\n targetFramework: userConfig.target,\n addHmr,\n hmrStyle,\n }),\n })\n\n if (compiledReferenceRoute === null) {\n if (debug) {\n console.info(\n `No changes made to route \"${id}\", skipping code-splitting.`,\n )\n }\n return null\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 baseId = id.split('?')[0]!\n const resolvedSharedBindings = sharedBindingsMap.get(baseId)\n\n const result = compileCodeSplitVirtualRoute({\n code,\n filename: id,\n splitTargets: grouping,\n sharedBindings: resolvedSharedBindings,\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, tsrShared],\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 normalizedId = normalizePath(id)\n const generatorFileInfo =\n routerPluginContext.routesByFile.get(normalizedId)\n if (\n generatorFileInfo &&\n includedCode.some((included) => code.includes(included))\n ) {\n return handleCompilingReferenceFile(\n code,\n normalizedId,\n generatorFileInfo,\n )\n }\n\n return null\n },\n },\n\n vite: {\n configResolved(config) {\n ROOT = config.root\n initUserConfig()\n\n // Validate plugin order - router must come before JSX transformation plugins\n const routerPluginIndex = config.plugins.findIndex(\n (p) => p.name === CODE_SPLITTER_PLUGIN_NAME,\n )\n\n if (routerPluginIndex === -1) return\n\n const frameworkPlugins =\n TRANSFORMATION_PLUGINS_BY_FRAMEWORK[userConfig.target]\n if (!frameworkPlugins) return\n\n for (const transformPlugin of frameworkPlugins) {\n const transformPluginIndex = config.plugins.findIndex((p) =>\n transformPlugin.pluginNames.includes(p.name),\n )\n\n if (\n transformPluginIndex !== -1 &&\n transformPluginIndex < routerPluginIndex\n ) {\n throw new Error(\n `Plugin order error: '${transformPlugin.pkg}' is placed before '@tanstack/router-plugin'.\\n\\n` +\n `The TanStack Router plugin must come BEFORE JSX transformation plugins.\\n\\n` +\n `Please update your Vite config:\\n\\n` +\n ` plugins: [\\n` +\n ` tanstackRouter(),\\n` +\n ` ${transformPlugin.usage},\\n` +\n ` ]\\n`,\n )\n }\n }\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 initUserConfig()\n },\n\n webpack() {\n ROOT = process.cwd()\n initUserConfig()\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 const normalizedId = normalizePath(fileURLToPath(url))\n return handleCompilingVirtualFile(code, normalizedId)\n },\n },\n\n vite: {\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 {\n name: 'tanstack-router:code-splitter:compile-shared-file',\n enforce: 'pre',\n\n transform: {\n filter: {\n id: /tsr-shared/,\n },\n handler(code, id) {\n const url = pathToFileURL(id)\n url.searchParams.delete('v')\n const normalizedId = normalizePath(fileURLToPath(url))\n const [baseId] = normalizedId.split('?')\n\n if (!baseId) return null\n\n const sharedBindings = sharedBindingsMap.get(baseId)\n if (!sharedBindings || sharedBindings.size === 0) return null\n\n if (debug) console.info('Compiling Shared Module: ', id)\n\n const result = compileCodeSplitSharedRoute({\n code,\n sharedBindings,\n filename: normalizedId,\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\n vite: {\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 ]\n}\n\nexport const unpluginRouterCodeSplitterFactory: UnpluginFactory<\n Partial<Config | (() => Config)> | undefined\n> = (options = {}) => {\n return createRouterCodeSplitterPlugin(options, createRouterPluginContext())\n}\n"],"mappings":";;;;;;;;;;;;;;AAkCA,IAAM,4BACJ;;;;;AAYF,IAAM,sCAGF;CACF,OAAO;EACL;GAEE,aAAa,CAAC,oBAAoB,qBAAqB;GACvD,KAAK;GACL,OAAO;GACR;EACD;GAEE,aAAa,CAAC,kBAAkB,iCAAiC;GACjE,KAAK;GACL,OAAO;GACR;EACD;GAEE,aAAa,CAAC,yBAAyB,iCAAiC;GACxE,KAAK;GACL,OAAO;GACR;EACF;CACD,OAAO,CACL;EACE,aAAa,CAAC,QAAQ;EACtB,KAAK;EACL,OAAO;EACR,CACF;CACF;AAED,SAAgB,+BACd,UAAwD,EAAE,EAC1D,qBAC2E;CAC3E,IAAI,OAAe,QAAQ,KAAK;CAChC,IAAI;CAEJ,SAAS,iBAAiB;AACxB,MAAI,OAAO,YAAY,WACrB,cAAa,SAAS;MAEtB,cAAa,UAAU,SAAS,KAAK;;CAGzC,MAAM,eAAA,QAAA,IAAA,aAAwC;CAG9C,MAAM,oCAAoB,IAAI,KAA0B;CAExD,MAAM,oCAAoC;AACxC,SACE,WAAW,sBAAsB,mBACjC;;CAGJ,MAAM,yBAAyB;AAC7B,SAAO,WAAW,sBAAsB;;CAG1C,MAAM,gCACJ,MACA,IACA,sBAC4B;AAC5B,MAAI,MAAO,SAAQ,KAAK,qBAAqB,GAAG;EAEhD,MAAM,WAAW,kCAAkC;GACjD;GACA,UAAU;GACX,CAAC;AAEF,MAAI,SAAS,cAAc,KAAA,GAAW;GACpC,MAAM,MAAM,qBAAqB,UAAU,SAAS,UAAU;AAC9D,OAAI,CAAC,IAAI,SAAS;IAChB,MAAM,UAAU,IAAI,MAAM,OAAO,KAAK,MAAM,EAAE,QAAQ,CAAC,KAAK,KAAK;AACjE,UAAM,IAAI,MACR,gCAAgC,GAAG,kBAAkB,UACtD;;;EAML,MAAM,sBAFoB,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AAK;AAC1B,cAAQ,IAAI,aAAa,OAAO,OAAO,OAAO;;AAGhD,YAAO;;IAEV;GAED,MAAM,EACJ,mBAAmB,aAAa;AAC9B,QAAI,WAAW,QAAQ,MAAM,gBAC3B,QAAO,WAAW,OAAO,KAAK,oBAAoB,YAAY;AAEhE,WAAO;MAEV;GACF;EACF;;AAGH,IAAa,qCAER,UAAU,EAAE,KAAK;AACpB,QAAO,+BAA+B,SAAS,2BAA2B,CAAC"}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { createRouterPluginContext } from "./router-plugin-context.js";
|
|
2
|
+
import { createRouterCodeSplitterPlugin } from "./router-code-splitter-plugin.js";
|
|
3
|
+
import { createRouterGeneratorPlugin } from "./router-generator-plugin.js";
|
|
4
|
+
import { createRouterHmrPlugin } from "./router-hmr-plugin.js";
|
|
4
5
|
import { getConfig } from "@tanstack/router-generator";
|
|
5
6
|
//#region src/core/router-composed-plugin.ts
|
|
6
7
|
var INLINE_CSS_DEFAULT_DEFINES = {
|
|
@@ -13,16 +14,16 @@ function applyWebpackInlineCssDefaultDefinePlugin(compiler) {
|
|
|
13
14
|
function applyRspackInlineCssDefaultDefinePlugin(compiler) {
|
|
14
15
|
new compiler.webpack.DefinePlugin(INLINE_CSS_DEFAULT_DEFINES).apply(compiler);
|
|
15
16
|
}
|
|
16
|
-
var unpluginRouterComposedFactory = (options = {},
|
|
17
|
+
var unpluginRouterComposedFactory = (options = {}, _meta) => {
|
|
17
18
|
const ROOT = process.cwd();
|
|
18
19
|
const userConfig = getConfig(typeof options === "function" ? options() : options, ROOT);
|
|
19
|
-
const
|
|
20
|
-
|
|
20
|
+
const routerPluginContext = createRouterPluginContext();
|
|
21
|
+
const getPlugin = (plugin) => {
|
|
21
22
|
if (!Array.isArray(plugin)) return [plugin];
|
|
22
23
|
return plugin;
|
|
23
24
|
};
|
|
24
|
-
const routerGenerator = getPlugin(
|
|
25
|
-
const routerCodeSplitter = getPlugin(
|
|
25
|
+
const routerGenerator = getPlugin(createRouterGeneratorPlugin(options, routerPluginContext));
|
|
26
|
+
const routerCodeSplitter = getPlugin(createRouterCodeSplitterPlugin(options, routerPluginContext));
|
|
26
27
|
const result = [{
|
|
27
28
|
name: "tanstack:router-inline-css-defaults",
|
|
28
29
|
vite: { config() {
|
|
@@ -43,7 +44,7 @@ var unpluginRouterComposedFactory = (options = {}, meta) => {
|
|
|
43
44
|
}, ...routerGenerator];
|
|
44
45
|
if (userConfig.autoCodeSplitting) result.push(...routerCodeSplitter);
|
|
45
46
|
if (!(process.env.NODE_ENV === "production") && !userConfig.autoCodeSplitting) {
|
|
46
|
-
const routerHmr = getPlugin(
|
|
47
|
+
const routerHmr = getPlugin(createRouterHmrPlugin(options, routerPluginContext));
|
|
47
48
|
result.push(...routerHmr);
|
|
48
49
|
}
|
|
49
50
|
return result;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-composed-plugin.js","names":[],"sources":["../../../src/core/router-composed-plugin.ts"],"sourcesContent":["import { getConfig } from '@tanstack/router-generator'\nimport {
|
|
1
|
+
{"version":3,"file":"router-composed-plugin.js","names":[],"sources":["../../../src/core/router-composed-plugin.ts"],"sourcesContent":["import { getConfig } from '@tanstack/router-generator'\nimport { createRouterGeneratorPlugin } from './router-generator-plugin'\nimport { createRouterCodeSplitterPlugin } from './router-code-splitter-plugin'\nimport { createRouterHmrPlugin } from './router-hmr-plugin'\nimport { createRouterPluginContext } from './router-plugin-context'\nimport type { Config } from './config'\nimport type {\n RspackCompiler,\n UnpluginFactory,\n UnpluginOptions,\n WebpackCompiler,\n} from 'unplugin'\n\nconst INLINE_CSS_DEFAULT_DEFINES = {\n 'process.env.TSS_INLINE_CSS_ENABLED': JSON.stringify('false'),\n 'import.meta.env.TSS_INLINE_CSS_ENABLED': JSON.stringify('false'),\n}\n\ntype EsbuildOptionsWithDefine = Parameters<\n NonNullable<NonNullable<UnpluginOptions['esbuild']>['config']>\n>[0]\n\nfunction applyWebpackInlineCssDefaultDefinePlugin(compiler: WebpackCompiler) {\n new compiler.webpack.DefinePlugin(INLINE_CSS_DEFAULT_DEFINES).apply(compiler)\n}\n\nfunction applyRspackInlineCssDefaultDefinePlugin(compiler: RspackCompiler) {\n new compiler.webpack.DefinePlugin(INLINE_CSS_DEFAULT_DEFINES).apply(compiler)\n}\n\nexport const unpluginRouterComposedFactory: UnpluginFactory<\n Partial<Config | (() => Config)> | undefined\n> = (options = {}, _meta) => {\n const ROOT: string = process.cwd()\n const userConfig = getConfig(\n (typeof options === 'function' ? options() : options) as Partial<Config>,\n ROOT,\n )\n const routerPluginContext = createRouterPluginContext()\n\n const getPlugin = (plugin: ReturnType<UnpluginFactory<any>>) => {\n if (!Array.isArray(plugin)) {\n return [plugin]\n }\n return plugin\n }\n\n const routerGenerator = getPlugin(\n createRouterGeneratorPlugin(options, routerPluginContext),\n )\n const routerCodeSplitter = getPlugin(\n createRouterCodeSplitterPlugin(options, routerPluginContext),\n )\n\n const result = [\n {\n name: 'tanstack:router-inline-css-defaults',\n vite: {\n config() {\n return {\n define: {\n ...INLINE_CSS_DEFAULT_DEFINES,\n },\n }\n },\n },\n webpack(compiler: WebpackCompiler) {\n applyWebpackInlineCssDefaultDefinePlugin(compiler)\n },\n rspack(compiler: RspackCompiler) {\n applyRspackInlineCssDefaultDefinePlugin(compiler)\n },\n esbuild: {\n config(options: EsbuildOptionsWithDefine) {\n options.define = {\n ...INLINE_CSS_DEFAULT_DEFINES,\n ...options.define,\n }\n },\n },\n },\n ...routerGenerator,\n ]\n if (userConfig.autoCodeSplitting) {\n result.push(...routerCodeSplitter)\n }\n\n const isProduction = process.env.NODE_ENV === 'production'\n\n if (!isProduction && !userConfig.autoCodeSplitting) {\n const routerHmr = getPlugin(\n createRouterHmrPlugin(options, routerPluginContext),\n )\n result.push(...routerHmr)\n }\n return result\n}\n"],"mappings":";;;;;;AAaA,IAAM,6BAA6B;CACjC,sCAAsC,K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|
|
3
|
+
import { RouterPluginContext } from './router-plugin-context.js';
|
|
4
|
+
export declare function createRouterGeneratorPlugin(options: Partial<Config | (() => Config)> | undefined, routerPluginContext: RouterPluginContext): ReturnType<UnpluginFactory<Partial<Config | (() => Config)> | undefined>>;
|
|
3
5
|
export declare const unpluginRouterGeneratorFactory: UnpluginFactory<Partial<Config | (() => Config)> | undefined>;
|
|
@@ -1,9 +1,10 @@
|
|
|
1
1
|
import { getConfig as getConfig$1 } from "./config.js";
|
|
2
|
+
import { createRouterPluginContext } from "./router-plugin-context.js";
|
|
2
3
|
import { Generator, resolveConfigPath } from "@tanstack/router-generator";
|
|
3
4
|
import { isAbsolute, join, normalize } from "node:path";
|
|
4
5
|
//#region src/core/router-generator-plugin.ts
|
|
5
6
|
var PLUGIN_NAME = "unplugin:router-generator";
|
|
6
|
-
|
|
7
|
+
function createRouterGeneratorPlugin(options = {}, routerPluginContext) {
|
|
7
8
|
let ROOT = process.cwd();
|
|
8
9
|
let userConfig;
|
|
9
10
|
let generator;
|
|
@@ -36,7 +37,7 @@ var unpluginRouterGeneratorFactory = (options = {}) => {
|
|
|
36
37
|
}
|
|
37
38
|
try {
|
|
38
39
|
await generator.run(generatorEvent);
|
|
39
|
-
|
|
40
|
+
routerPluginContext.routesByFile = generator.getRoutesByFileMap();
|
|
40
41
|
} catch (e) {
|
|
41
42
|
console.error(e);
|
|
42
43
|
}
|
|
@@ -95,8 +96,11 @@ var unpluginRouterGeneratorFactory = (options = {}) => {
|
|
|
95
96
|
initConfigAndGenerator();
|
|
96
97
|
} }
|
|
97
98
|
};
|
|
99
|
+
}
|
|
100
|
+
var unpluginRouterGeneratorFactory = (options = {}) => {
|
|
101
|
+
return createRouterGeneratorPlugin(options, createRouterPluginContext());
|
|
98
102
|
};
|
|
99
103
|
//#endregion
|
|
100
|
-
export { unpluginRouterGeneratorFactory };
|
|
104
|
+
export { createRouterGeneratorPlugin, unpluginRouterGeneratorFactory };
|
|
101
105
|
|
|
102
106
|
//# sourceMappingURL=router-generator-plugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-generator-plugin.js","names":[],"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
|
|
1
|
+
{"version":3,"file":"router-generator-plugin.js","names":[],"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'\nimport { createRouterPluginContext } from './router-plugin-context'\n\nimport type { GeneratorEvent } from '@tanstack/router-generator'\nimport type { FSWatcher } from 'chokidar'\nimport type { UnpluginFactory } from 'unplugin'\nimport type { Config } from './config'\nimport type { RouterPluginContext } from './router-plugin-context'\n\nconst PLUGIN_NAME = 'unplugin:router-generator'\n\nexport function createRouterGeneratorPlugin(\n options: Partial<Config | (() => Config)> | undefined = {},\n routerPluginContext: RouterPluginContext,\n): ReturnType<UnpluginFactory<Partial<Config | (() => Config)> | undefined>> {\n let ROOT: string = process.cwd()\n let userConfig: 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 = (opts?: { root?: string }) => {\n if (opts?.root) {\n ROOT = opts.root\n }\n if (typeof options === 'function') {\n userConfig = options()\n } else {\n userConfig = getConfig(options, ROOT)\n }\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 routerPluginContext.routesByFile = 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 vite: {\n async configResolved(config) {\n initConfigAndGenerator({ root: config.root })\n await generate()\n },\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 esbuild: {\n config() {\n initConfigAndGenerator()\n },\n },\n }\n}\n\nexport const unpluginRouterGeneratorFactory: UnpluginFactory<\n Partial<Config | (() => Config)> | undefined\n> = (options = {}) => {\n return createRouterGeneratorPlugin(options, createRouterPluginContext())\n}\n"],"mappings":";;;;;AAWA,IAAM,cAAc;AAEpB,SAAgB,4BACd,UAAwD,EAAE,EAC1D,qBAC2E;CAC3E,IAAI,OAAe,QAAQ,KAAK;CAChC,IAAI;CACJ,IAAI;CAEJ,MAAM,gCACJ,WAAW,0BAA0B;CACvC,MAAM,+BAA+B;AACnC,SAAO,WAAW,WAAW,gBAAgB,GACzC,WAAW,kBACX,KAAK,MAAM,WAAW,gBAAgB;;CAG5C,MAAM,0BAA0B,SAA6B;AAC3D,MAAI,MAAM,KACR,QAAO,KAAK;AAEd,MAAI,OAAO,YAAY,WACrB,cAAa,SAAS;MAEtB,cAAa,YAAU,SAAS,KAAK;AAEvC,cAAY,IAAI,UAAU;GACxB,QAAQ;GACR,MAAM;GACP,CAAC;;CAGJ,MAAM,WAAW,OAAO,SAGlB;AACJ,MAAI,yBAAyB,CAC3B;EAEF,IAAI,iBAA6C,KAAA;AACjD,MAAI,MAAM;GACR,MAAM,WAAW,UAAU,KAAK,KAAK;AACrC,OAAI,aAAa,kBAAkB,EAAE,iBAAiB,MAAM,CAAC,EAAE;AAC7D,4BAAwB;AACxB;;AAEF,oBAAiB;IAAE,MAAM;IAAU,MAAM,KAAK;IAAO;;AAGvD,MAAI;AACF,SAAM,UAAU,IAAI,eAAe;AACnC,uBAAoB,eAAe,UAAU,oBAAoB;WAC1D,GAAG;AACV,WAAQ,MAAM,EAAE;;;AAIpB,QAAO;EACL,MAAM;EACN,SAAS;EACT,MAAM,YAAY,IAAI,EAAE,SAAS;AAC/B,SAAM,SAAS;IACb,MAAM;IACN;IACD,CAAC;;EAEJ,MAAM,EACJ,M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luginFactory } from 'unplugin';
|
|
2
2
|
import { Config } from './config.js';
|
|
3
|
+
import { RouterPluginContext } from './router-plugin-context.js';
|
|
4
|
+
export declare function createRouterHmrPlugin(options: Partial<Config | (() => Config)> | undefined, routerPluginContext: RouterPluginContext): ReturnType<UnpluginFactory<Partial<Config> | undefined>>;
|
|
3
5
|
export declare const unpluginRouterHmrFactory: UnpluginFactory<Partial<Config> | undefined>;
|
|
@@ -15,9 +15,12 @@ var includeCode = [
|
|
|
15
15
|
"createRootRoute(",
|
|
16
16
|
"createRootRouteWithContext("
|
|
17
17
|
];
|
|
18
|
-
|
|
18
|
+
function createRouterHmrPlugin(options = {}, routerPluginContext) {
|
|
19
19
|
let ROOT = process.cwd();
|
|
20
|
-
|
|
20
|
+
const resolveUserConfig = () => {
|
|
21
|
+
return getConfig(typeof options === "function" ? options() : options, ROOT);
|
|
22
|
+
};
|
|
23
|
+
let userConfig = resolveUserConfig();
|
|
21
24
|
return {
|
|
22
25
|
name: "tanstack-router:hmr",
|
|
23
26
|
enforce: "pre",
|
|
@@ -28,7 +31,7 @@ var unpluginRouterHmrFactory = (options = {}) => {
|
|
|
28
31
|
},
|
|
29
32
|
handler(code, id) {
|
|
30
33
|
const normalizedId = normalizePath(id);
|
|
31
|
-
const routeEntry =
|
|
34
|
+
const routeEntry = routerPluginContext.routesByFile.get(normalizedId);
|
|
32
35
|
if (!routeEntry) return null;
|
|
33
36
|
if (debug) console.info("Adding HMR handling to route ", normalizedId);
|
|
34
37
|
const hmrStyle = userConfig.plugin?.hmr?.style ?? "vite";
|
|
@@ -57,7 +60,10 @@ var unpluginRouterHmrFactory = (options = {}) => {
|
|
|
57
60
|
return compiled;
|
|
58
61
|
}
|
|
59
62
|
}
|
|
60
|
-
const ast = parseAst({
|
|
63
|
+
const ast = parseAst({
|
|
64
|
+
code,
|
|
65
|
+
filename: normalizedId
|
|
66
|
+
});
|
|
61
67
|
ast.program.body.push(...createRouteHmrStatement([], {
|
|
62
68
|
hmrStyle,
|
|
63
69
|
targetFramework: userConfig.target,
|
|
@@ -78,7 +84,7 @@ var unpluginRouterHmrFactory = (options = {}) => {
|
|
|
78
84
|
vite: {
|
|
79
85
|
configResolved(config) {
|
|
80
86
|
ROOT = config.root;
|
|
81
|
-
userConfig =
|
|
87
|
+
userConfig = resolveUserConfig();
|
|
82
88
|
},
|
|
83
89
|
applyToEnvironment(environment) {
|
|
84
90
|
if (userConfig.plugin?.vite?.environmentName) return userConfig.plugin.vite.environmentName === environment.name;
|
|
@@ -86,8 +92,8 @@ var unpluginRouterHmrFactory = (options = {}) => {
|
|
|
86
92
|
}
|
|
87
93
|
}
|
|
88
94
|
};
|
|
89
|
-
}
|
|
95
|
+
}
|
|
90
96
|
//#endregion
|
|
91
|
-
export {
|
|
97
|
+
export { createRouterHmrPlugin };
|
|
92
98
|
|
|
93
99
|
//# sourceMappingURL=router-hmr-plugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-hmr-plugin.js","names":[],"sources":["../../../src/core/router-hmr-plugin.ts"],"sourcesContent":["import { generateFromAst, logDiff, parseAst } from '@tanstack/router-utils'\nimport { compileCodeSplitReferenceRoute } from './code-splitter/compilers'\nimport { getReferenceRouteCompilerPlugins } from './code-splitter/plugins/framework-plugins'\nimport { createRouteHmrStatement } from './hmr'\nimport { debug, normalizePath } from './utils'\nimport { getConfig } from './config'\nimport type { UnpluginFactory } from 'unplugin'\nimport type { Config } from './config'\n\n/**\n * This plugin adds HMR support for file routes.\n * It is only added to the composed plugin in dev when autoCodeSplitting is disabled, since the code splitting plugin\n * handles HMR for code-split routes itself.\n */\n\nconst includeCode = [\n 'createFileRoute(',\n 'createRootRoute(',\n 'createRootRouteWithContext(',\n]\nexport
|
|
1
|
+
{"version":3,"file":"router-hmr-plugin.js","names":[],"sources":["../../../src/core/router-hmr-plugin.ts"],"sourcesContent":["import { generateFromAst, logDiff, parseAst } from '@tanstack/router-utils'\nimport { compileCodeSplitReferenceRoute } from './code-splitter/compilers'\nimport { getReferenceRouteCompilerPlugins } from './code-splitter/plugins/framework-plugins'\nimport { createRouteHmrStatement } from './hmr'\nimport { debug, normalizePath } from './utils'\nimport { getConfig } from './config'\nimport { createRouterPluginContext } from './router-plugin-context'\nimport type { UnpluginFactory } from 'unplugin'\nimport type { Config } from './config'\nimport type { RouterPluginContext } from './router-plugin-context'\n\n/**\n * This plugin adds HMR support for file routes.\n * It is only added to the composed plugin in dev when autoCodeSplitting is disabled, since the code splitting plugin\n * handles HMR for code-split routes itself.\n */\n\nconst includeCode = [\n 'createFileRoute(',\n 'createRootRoute(',\n 'createRootRouteWithContext(',\n]\n\nexport function createRouterHmrPlugin(\n options: Partial<Config | (() => Config)> | undefined = {},\n routerPluginContext: RouterPluginContext,\n): ReturnType<UnpluginFactory<Partial<Config> | undefined>> {\n let ROOT: string = process.cwd()\n\n const resolveUserConfig = () => {\n return getConfig(typeof options === 'function' ? options() : options, ROOT)\n }\n\n let userConfig = resolveUserConfig()\n\n return {\n name: 'tanstack-router:hmr',\n enforce: 'pre',\n transform: {\n filter: {\n // this is necessary for webpack / rspack to avoid matching .html files\n id: /\\.(m|c)?(j|t)sx?$/,\n code: {\n include: includeCode,\n },\n },\n handler(code, id) {\n const normalizedId = normalizePath(id)\n const routeEntry = routerPluginContext.routesByFile.get(normalizedId)\n if (!routeEntry) {\n return null\n }\n\n if (debug) console.info('Adding HMR handling to route ', normalizedId)\n\n const hmrStyle = userConfig.plugin?.hmr?.style ?? 'vite'\n\n if (userConfig.target === 'react') {\n const compilerPlugins = getReferenceRouteCompilerPlugins({\n targetFramework: 'react',\n addHmr: true,\n hmrStyle,\n })\n const compiled = compileCodeSplitReferenceRoute({\n code,\n filename: normalizedId,\n id: normalizedId,\n addHmr: true,\n hmrStyle,\n hmrRouteId: routeEntry.routeId,\n codeSplitGroupings: [],\n targetFramework: 'react',\n compilerPlugins,\n })\n\n if (compiled) {\n if (debug) {\n logDiff(code, compiled.code)\n console.log('Output:\\n', compiled.code + '\\n\\n')\n }\n\n return compiled\n }\n }\n\n const ast = parseAst({ code, filename: normalizedId })\n ast.program.body.push(\n ...createRouteHmrStatement([], {\n hmrStyle,\n targetFramework: userConfig.target,\n routeId: routeEntry.routeId,\n }),\n )\n const result = generateFromAst(ast, {\n sourceMaps: true,\n filename: normalizedId,\n sourceFileName: normalizedId,\n })\n if (debug) {\n logDiff(code, result.code)\n console.log('Output:\\n', result.code + '\\n\\n')\n }\n return result\n },\n },\n vite: {\n configResolved(config) {\n ROOT = config.root\n userConfig = resolveUserConfig()\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}\n\nexport const unpluginRouterHmrFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}) => {\n return createRouterHmrPlugin(options, createRouterPluginContext())\n}\n"],"mappings":";;;;;;;;;;;;AAiBA,IAAM,cAAc;CAClB;CACA;CACA;CACD;AAED,SAAgB,sBACd,UAAwD,EAAE,EAC1D,qBAC0D;CAC1D,IAAI,OAAe,QAAQ,KAAK;CAEhC,MAAM,0BAA0B;AAC9B,SAAO,UAAU,OAAO,YAAY,aAAa,SAAS,GAAG,SAAS,KAAK;;CAG7E,IAAI,aAAa,mBAAmB;AAEpC,QAAO;EACL,MAAM;EACN,SAAS;EACT,WAAW;GACT,QAAQ;IAEN,IAAI;IACJ,MAAM,EACJ,SAAS,aACV;IACF;GACD,QAAQ,MAAM,IAAI;IAChB,MAAM,eAAe,cAAc,GAAG;IACtC,MAAM,aAAa,oBAAoB,aAAa,IAAI,aAAa;AACrE,QAAI,CAAC,WACH,QAAO;AAGT,QAAI,MAAO,SAAQ,KAAK,iCAAiC,aAAa;IAEtE,MAAM,WAAW,WAAW,QAAQ,KAAK,SAAS;AAElD,QAAI,WAAW,WAAW,SAAS;KACjC,MAAM,kBAAkB,iCAAiC;MACvD,iBAAiB;MACjB,QAAQ;MACR;MACD,CAAC;KACF,MAAM,WAAW,+BAA+B;MAC9C;MACA,UAAU;MACV,IAAI;MACJ,QAAQ;MACR;MACA,YAAY,WAAW;MACvB,oBAAoB,EAAE;MACtB,iBAAiB;MACjB;MACD,CAAC;AAEF,SAAI,UAAU;AACZ,UAAI,OAAO;AACT,eAAQ,MAAM,SAAS,KAAK;AAC5B,eAAQ,IAAI,aAAa,SAAS,OAAO,OAAO;;AAGlD,aAAO;;;IAIX,MAAM,MAAM,SAAS;KAAE;KAAM,UAAU;KAAc,CAAC;AACtD,QAAI,QAAQ,KAAK,KACf,GAAG,wBAAwB,EAAE,EAAE;KAC7B;KACA,iBAAiB,WAAW;KAC5B,SAAS,WAAW;KACrB,CAAC,CACH;IACD,MAAM,SAAS,gBAAgB,KAAK;KAClC,YAAY;KACZ,UAAU;KACV,gBAAgB;KACjB,CAAC;AACF,QAAI,OAAO;AACT,aAAQ,MAAM,OAAO,KAAK;AAC1B,aAAQ,IAAI,aAAa,OAAO,OAAO,OAAO;;AAEhD,WAAO;;GAEV;EACD,MAAM;GACJ,eAAe,QAAQ;AACrB,WAAO,OAAO;AACd,iBAAa,mBAAmB;;GAElC,mBAAmB,aAAa;AAC9B,QAAI,WAAW,QAAQ,MAAM,gBAC3B,QAAO,WAAW,OAAO,KAAK,oBAAoB,YAAY;AAEhE,WAAO;;GAEV;EACF"}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"router-plugin-context.js","names":[],"sources":["../../../src/core/router-plugin-context.ts"],"sourcesContent":["import type { GetRoutesByFileMapResult } from '@tanstack/router-generator'\n\nexport type RouterPluginContext = {\n routesByFile: GetRoutesByFileMapResult\n}\n\nexport function createRouterPluginContext(): RouterPluginContext {\n return {\n routesByFile: new Map(),\n }\n}\n"],"mappings":";AAMA,SAAgB,4BAAiD;AAC/D,QAAO,EACL,8BAAc,IAAI,KAAK,EACxB"}
|
package/dist/esm/esbuild.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { configSchema, CodeSplittingOptions, Config } from './core/config.js';
|
|
2
|
+
import { RouterPluginContext } from './core/router-plugin-context.js';
|
|
3
|
+
type RouterPluginOptions = Partial<Config | (() => Config)> | undefined;
|
|
2
4
|
/**
|
|
3
5
|
* @example
|
|
4
6
|
* ```ts
|
|
@@ -8,53 +10,7 @@ import { configSchema, CodeSplittingOptions, Config } from './core/config.js';
|
|
|
8
10
|
* }
|
|
9
11
|
* ```
|
|
10
12
|
*/
|
|
11
|
-
declare const TanStackRouterGeneratorEsbuild: (options?:
|
|
12
|
-
target: "react" | "solid" | "vue";
|
|
13
|
-
routeFileIgnorePrefix: string;
|
|
14
|
-
routesDirectory: string;
|
|
15
|
-
quoteStyle: "single" | "double";
|
|
16
|
-
semicolons: boolean;
|
|
17
|
-
disableLogging: boolean;
|
|
18
|
-
routeTreeFileHeader: string[];
|
|
19
|
-
indexToken: string | RegExp | {
|
|
20
|
-
regex: string;
|
|
21
|
-
flags?: string | undefined;
|
|
22
|
-
};
|
|
23
|
-
routeToken: string | RegExp | {
|
|
24
|
-
regex: string;
|
|
25
|
-
flags?: string | undefined;
|
|
26
|
-
};
|
|
27
|
-
generatedRouteTree: string;
|
|
28
|
-
disableTypes: boolean;
|
|
29
|
-
addExtensions: string | boolean;
|
|
30
|
-
enableRouteTreeFormatting: boolean;
|
|
31
|
-
tmpDir: string;
|
|
32
|
-
importRoutesUsingAbsolutePaths: boolean;
|
|
33
|
-
enableRouteGeneration?: boolean | undefined;
|
|
34
|
-
codeSplittingOptions?: CodeSplittingOptions | undefined;
|
|
35
|
-
plugin?: {
|
|
36
|
-
vite?: {
|
|
37
|
-
environmentName?: string | undefined;
|
|
38
|
-
} | undefined;
|
|
39
|
-
hmr?: {
|
|
40
|
-
style?: "vite" | "webpack" | undefined;
|
|
41
|
-
} | undefined;
|
|
42
|
-
} | undefined;
|
|
43
|
-
virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
|
|
44
|
-
routeFilePrefix?: string | undefined;
|
|
45
|
-
routeFileIgnorePattern?: string | undefined;
|
|
46
|
-
pathParamsAllowedCharacters?: (";" | ":" | "@" | "&" | "=" | "+" | "$" | ",")[] | undefined;
|
|
47
|
-
routeTreeFileFooter?: string[] | ((...args: unknown[]) => string[]) | undefined;
|
|
48
|
-
autoCodeSplitting?: boolean | undefined;
|
|
49
|
-
customScaffolding?: {
|
|
50
|
-
routeTemplate?: string | undefined;
|
|
51
|
-
lazyRouteTemplate?: string | undefined;
|
|
52
|
-
} | undefined;
|
|
53
|
-
experimental?: {
|
|
54
|
-
enableCodeSplitting?: boolean | undefined;
|
|
55
|
-
} | undefined;
|
|
56
|
-
plugins?: import('@tanstack/router-generator').GeneratorPlugin[] | undefined;
|
|
57
|
-
} | (() => Config)> | undefined) => import('unplugin').EsbuildPlugin;
|
|
13
|
+
declare const TanStackRouterGeneratorEsbuild: (options?: RouterPluginOptions, routerPluginContext?: RouterPluginContext) => import('unplugin').EsbuildPlugin;
|
|
58
14
|
/**
|
|
59
15
|
* @example
|
|
60
16
|
* ```ts
|
|
@@ -64,53 +20,7 @@ declare const TanStackRouterGeneratorEsbuild: (options?: Partial<{
|
|
|
64
20
|
* }
|
|
65
21
|
* ```
|
|
66
22
|
*/
|
|
67
|
-
declare const TanStackRouterCodeSplitterEsbuild: (options?:
|
|
68
|
-
target: "react" | "solid" | "vue";
|
|
69
|
-
routeFileIgnorePrefix: string;
|
|
70
|
-
routesDirectory: string;
|
|
71
|
-
quoteStyle: "single" | "double";
|
|
72
|
-
semicolons: boolean;
|
|
73
|
-
disableLogging: boolean;
|
|
74
|
-
routeTreeFileHeader: string[];
|
|
75
|
-
indexToken: string | RegExp | {
|
|
76
|
-
regex: string;
|
|
77
|
-
flags?: string | undefined;
|
|
78
|
-
};
|
|
79
|
-
routeToken: string | RegExp | {
|
|
80
|
-
regex: string;
|
|
81
|
-
flags?: string | undefined;
|
|
82
|
-
};
|
|
83
|
-
generatedRouteTree: string;
|
|
84
|
-
disableTypes: boolean;
|
|
85
|
-
addExtensions: string | boolean;
|
|
86
|
-
enableRouteTreeFormatting: boolean;
|
|
87
|
-
tmpDir: string;
|
|
88
|
-
importRoutesUsingAbsolutePaths: boolean;
|
|
89
|
-
enableRouteGeneration?: boolean | undefined;
|
|
90
|
-
codeSplittingOptions?: CodeSplittingOptions | undefined;
|
|
91
|
-
plugin?: {
|
|
92
|
-
vite?: {
|
|
93
|
-
environmentName?: string | undefined;
|
|
94
|
-
} | undefined;
|
|
95
|
-
hmr?: {
|
|
96
|
-
style?: "vite" | "webpack" | undefined;
|
|
97
|
-
} | undefined;
|
|
98
|
-
} | undefined;
|
|
99
|
-
virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
|
|
100
|
-
routeFilePrefix?: string | undefined;
|
|
101
|
-
routeFileIgnorePattern?: string | undefined;
|
|
102
|
-
pathParamsAllowedCharacters?: (";" | ":" | "@" | "&" | "=" | "+" | "$" | ",")[] | undefined;
|
|
103
|
-
routeTreeFileFooter?: string[] | ((...args: unknown[]) => string[]) | undefined;
|
|
104
|
-
autoCodeSplitting?: boolean | undefined;
|
|
105
|
-
customScaffolding?: {
|
|
106
|
-
routeTemplate?: string | undefined;
|
|
107
|
-
lazyRouteTemplate?: string | undefined;
|
|
108
|
-
} | undefined;
|
|
109
|
-
experimental?: {
|
|
110
|
-
enableCodeSplitting?: boolean | undefined;
|
|
111
|
-
} | undefined;
|
|
112
|
-
plugins?: import('@tanstack/router-generator').GeneratorPlugin[] | undefined;
|
|
113
|
-
} | (() => Config)> | undefined) => import('unplugin').EsbuildPlugin;
|
|
23
|
+
declare const TanStackRouterCodeSplitterEsbuild: (options?: RouterPluginOptions, routerPluginContext?: RouterPluginContext) => import('unplugin').EsbuildPlugin;
|
|
114
24
|
/**
|
|
115
25
|
* @example
|
|
116
26
|
* ```ts
|
|
@@ -216,4 +126,4 @@ declare const tanstackRouter: (options?: Partial<{
|
|
|
216
126
|
} | (() => Config)> | undefined) => import('unplugin').EsbuildPlugin;
|
|
217
127
|
export default TanStackRouterEsbuild;
|
|
218
128
|
export { configSchema, TanStackRouterGeneratorEsbuild, TanStackRouterCodeSplitterEsbuild, TanStackRouterEsbuild, tanstackRouter, };
|
|
219
|
-
export type { Config, CodeSplittingOptions };
|
|
129
|
+
export type { Config, CodeSplittingOptions, RouterPluginContext };
|
package/dist/esm/esbuild.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { configSchema } from "./core/config.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { createRouterPluginContext } from "./core/router-plugin-context.js";
|
|
3
|
+
import { createRouterCodeSplitterPlugin } from "./core/router-code-splitter-plugin.js";
|
|
4
|
+
import { createRouterGeneratorPlugin } from "./core/router-generator-plugin.js";
|
|
4
5
|
import { unpluginRouterComposedFactory } from "./core/router-composed-plugin.js";
|
|
5
6
|
import { createEsbuildPlugin } from "unplugin";
|
|
6
7
|
//#region src/esbuild.ts
|
|
8
|
+
var defaultRouterPluginContext = createRouterPluginContext();
|
|
7
9
|
/**
|
|
8
10
|
* @example
|
|
9
11
|
* ```ts
|
|
@@ -13,7 +15,10 @@ import { createEsbuildPlugin } from "unplugin";
|
|
|
13
15
|
* }
|
|
14
16
|
* ```
|
|
15
17
|
*/
|
|
16
|
-
var TanStackRouterGeneratorEsbuild =
|
|
18
|
+
var TanStackRouterGeneratorEsbuild = (options, routerPluginContext) => {
|
|
19
|
+
const pluginContext = routerPluginContext ?? defaultRouterPluginContext;
|
|
20
|
+
return createEsbuildPlugin((pluginOptions) => createRouterGeneratorPlugin(pluginOptions, pluginContext))(options);
|
|
21
|
+
};
|
|
17
22
|
/**
|
|
18
23
|
* @example
|
|
19
24
|
* ```ts
|
|
@@ -23,7 +28,10 @@ var TanStackRouterGeneratorEsbuild = createEsbuildPlugin(unpluginRouterGenerator
|
|
|
23
28
|
* }
|
|
24
29
|
* ```
|
|
25
30
|
*/
|
|
26
|
-
var TanStackRouterCodeSplitterEsbuild =
|
|
31
|
+
var TanStackRouterCodeSplitterEsbuild = (options, routerPluginContext) => {
|
|
32
|
+
const pluginContext = routerPluginContext ?? defaultRouterPluginContext;
|
|
33
|
+
return createEsbuildPlugin((pluginOptions) => createRouterCodeSplitterPlugin(pluginOptions, pluginContext))(options);
|
|
34
|
+
};
|
|
27
35
|
/**
|
|
28
36
|
* @example
|
|
29
37
|
* ```ts
|
package/dist/esm/esbuild.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"esbuild.js","names":[],"sources":["../../src/esbuild.ts"],"sourcesContent":["import { createEsbuildPlugin } from 'unplugin'\n\nimport { configSchema } from './core/config'\nimport {
|
|
1
|
+
{"version":3,"file":"esbuild.js","names":[],"sources":["../../src/esbuild.ts"],"sourcesContent":["import { createEsbuildPlugin } from 'unplugin'\n\nimport { configSchema } from './core/config'\nimport { createRouterCodeSplitterPlugin } from './core/router-code-splitter-plugin'\nimport { createRouterGeneratorPlugin } from './core/router-generator-plugin'\nimport { unpluginRouterComposedFactory } from './core/router-composed-plugin'\nimport { createRouterPluginContext } from './core/router-plugin-context'\n\nimport type { CodeSplittingOptions, Config } from './core/config'\nimport type { RouterPluginContext } from './core/router-plugin-context'\n\ntype RouterPluginOptions = Partial<Config | (() => Config)> | undefined\n\nconst defaultRouterPluginContext = createRouterPluginContext()\n\n/**\n * @example\n * ```ts\n * export default {\n * plugins: [TanStackRouterGeneratorEsbuild()],\n * // ...\n * }\n * ```\n */\nconst TanStackRouterGeneratorEsbuild = (\n options?: RouterPluginOptions,\n routerPluginContext?: RouterPluginContext,\n) => {\n const pluginContext = routerPluginContext ?? defaultRouterPluginContext\n return createEsbuildPlugin((pluginOptions: RouterPluginOptions) =>\n createRouterGeneratorPlugin(pluginOptions, pluginContext),\n )(options)\n}\n\n/**\n * @example\n * ```ts\n * export default {\n * plugins: [TanStackRouterCodeSplitterEsbuild()],\n * // ...\n * }\n * ```\n */\nconst TanStackRouterCodeSplitterEsbuild = (\n options?: RouterPluginOptions,\n routerPluginContext?: RouterPluginContext,\n) => {\n const pluginContext = routerPluginContext ?? defaultRouterPluginContext\n return createEsbuildPlugin((pluginOptions: RouterPluginOptions) =>\n createRouterCodeSplitterPlugin(pluginOptions, pluginContext),\n )(options)\n}\n\n/**\n * @example\n * ```ts\n * export default {\n * plugins: [tanstackRouter()],\n * // ...\n * }\n * ```\n */\nconst TanStackRouterEsbuild = createEsbuildPlugin(unpluginRouterComposedFactory)\nconst tanstackRouter = TanStackRouterEsbuild\nexport default TanStackRouterEsbuild\n\nexport {\n configSchema,\n TanStackRouterGeneratorEsbuild,\n TanStackRouterCodeSplitterEsbuild,\n TanStackRouterEsbuild,\n tanstackRouter,\n}\n\nexport type { Config, CodeSplittingOptions, RouterPluginContext }\n"],"mappings":";;;;;;;AAaA,IAAM,6BAA6B,2BAA2B;;;;;;;;;;AAW9D,IAAM,kCACJ,SACA,wBACG;CACH,MAAM,gBAAgB,uBAAuB;AAC7C,QAAO,qBAAqB,kBAC1B,4BAA4B,eAAe,cAAc,CAC1D,CAAC,QAAQ;;;;;;;;;;;AAYZ,IAAM,qCACJ,SACA,wBACG;CACH,MAAM,gBAAgB,uBAAuB;AAC7C,QAAO,qBAAqB,kBAC1B,+BAA+B,eAAe,cAAc,CAC7D,CAAC,QAAQ;;;;;;;;;;;AAYZ,IAAM,wBAAwB,oBAAoB,8BAA8B;AAChF,IAAM,iBAAiB"}
|
package/dist/esm/index.d.ts
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
export { configSchema, getConfig } from './core/config.js';
|
|
2
2
|
export { unpluginRouterCodeSplitterFactory } from './core/router-code-splitter-plugin.js';
|
|
3
3
|
export { unpluginRouterGeneratorFactory } from './core/router-generator-plugin.js';
|
|
4
|
+
export { createRouterPluginContext } from './core/router-plugin-context.js';
|
|
4
5
|
export type { Config, ConfigInput, ConfigOutput, CodeSplittingOptions, DeletableNodes, HmrOptions, } from './core/config.js';
|
|
6
|
+
export type { RouterPluginContext } from './core/router-plugin-context.js';
|
|
5
7
|
export { tsrSplit, splitRouteIdentNodes, defaultCodeSplitGroupings, } from './core/constants.js';
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import { configSchema, getConfig } from "./core/config.js";
|
|
2
2
|
import { defaultCodeSplitGroupings, splitRouteIdentNodes, tsrSplit } from "./core/constants.js";
|
|
3
|
+
import { createRouterPluginContext } from "./core/router-plugin-context.js";
|
|
3
4
|
import { unpluginRouterCodeSplitterFactory } from "./core/router-code-splitter-plugin.js";
|
|
4
5
|
import { unpluginRouterGeneratorFactory } from "./core/router-generator-plugin.js";
|
|
5
|
-
export { configSchema, defaultCodeSplitGroupings, getConfig, splitRouteIdentNodes, tsrSplit, unpluginRouterCodeSplitterFactory, unpluginRouterGeneratorFactory };
|
|
6
|
+
export { configSchema, createRouterPluginContext, defaultCodeSplitGroupings, getConfig, splitRouteIdentNodes, tsrSplit, unpluginRouterCodeSplitterFactory, unpluginRouterGeneratorFactory };
|
package/dist/esm/rspack.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
1
|
import { configSchema, CodeSplittingOptions, Config } from './core/config.js';
|
|
2
|
+
import { RouterPluginContext } from './core/router-plugin-context.js';
|
|
3
|
+
type RspackRouterPluginOptions = Partial<Config> | (() => Partial<Config>);
|
|
2
4
|
/**
|
|
3
5
|
* @example
|
|
4
6
|
* ```ts
|
|
@@ -12,53 +14,7 @@ import { configSchema, CodeSplittingOptions, Config } from './core/config.js';
|
|
|
12
14
|
* })
|
|
13
15
|
* ```
|
|
14
16
|
*/
|
|
15
|
-
declare const TanStackRouterGeneratorRspack: (options?:
|
|
16
|
-
target: "react" | "solid" | "vue";
|
|
17
|
-
routeFileIgnorePrefix: string;
|
|
18
|
-
routesDirectory: string;
|
|
19
|
-
quoteStyle: "single" | "double";
|
|
20
|
-
semicolons: boolean;
|
|
21
|
-
disableLogging: boolean;
|
|
22
|
-
routeTreeFileHeader: string[];
|
|
23
|
-
indexToken: string | RegExp | {
|
|
24
|
-
regex: string;
|
|
25
|
-
flags?: string | undefined;
|
|
26
|
-
};
|
|
27
|
-
routeToken: string | RegExp | {
|
|
28
|
-
regex: string;
|
|
29
|
-
flags?: string | undefined;
|
|
30
|
-
};
|
|
31
|
-
generatedRouteTree: string;
|
|
32
|
-
disableTypes: boolean;
|
|
33
|
-
addExtensions: string | boolean;
|
|
34
|
-
enableRouteTreeFormatting: boolean;
|
|
35
|
-
tmpDir: string;
|
|
36
|
-
importRoutesUsingAbsolutePaths: boolean;
|
|
37
|
-
enableRouteGeneration?: boolean | undefined;
|
|
38
|
-
codeSplittingOptions?: CodeSplittingOptions | undefined;
|
|
39
|
-
plugin?: {
|
|
40
|
-
vite?: {
|
|
41
|
-
environmentName?: string | undefined;
|
|
42
|
-
} | undefined;
|
|
43
|
-
hmr?: {
|
|
44
|
-
style?: "vite" | "webpack" | undefined;
|
|
45
|
-
} | undefined;
|
|
46
|
-
} | undefined;
|
|
47
|
-
virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
|
|
48
|
-
routeFilePrefix?: string | undefined;
|
|
49
|
-
routeFileIgnorePattern?: string | undefined;
|
|
50
|
-
pathParamsAllowedCharacters?: (";" | ":" | "@" | "&" | "=" | "+" | "$" | ",")[] | undefined;
|
|
51
|
-
routeTreeFileFooter?: string[] | ((...args: unknown[]) => string[]) | undefined;
|
|
52
|
-
autoCodeSplitting?: boolean | undefined;
|
|
53
|
-
customScaffolding?: {
|
|
54
|
-
routeTemplate?: string | undefined;
|
|
55
|
-
lazyRouteTemplate?: string | undefined;
|
|
56
|
-
} | undefined;
|
|
57
|
-
experimental?: {
|
|
58
|
-
enableCodeSplitting?: boolean | undefined;
|
|
59
|
-
} | undefined;
|
|
60
|
-
plugins?: import('@tanstack/router-generator').GeneratorPlugin[] | undefined;
|
|
61
|
-
} | (() => Config)> | undefined) => import('unplugin').RspackPluginInstance;
|
|
17
|
+
declare const TanStackRouterGeneratorRspack: (options?: RspackRouterPluginOptions, routerPluginContext?: RouterPluginContext) => import('unplugin').RspackPluginInstance;
|
|
62
18
|
/**
|
|
63
19
|
* @example
|
|
64
20
|
* ```ts
|
|
@@ -72,7 +28,7 @@ declare const TanStackRouterGeneratorRspack: (options?: Partial<{
|
|
|
72
28
|
* })
|
|
73
29
|
* ```
|
|
74
30
|
*/
|
|
75
|
-
declare const TanStackRouterCodeSplitterRspack: (options?:
|
|
31
|
+
declare const TanStackRouterCodeSplitterRspack: (options?: RspackRouterPluginOptions, routerPluginContext?: RouterPluginContext) => import('unplugin').RspackPluginInstance;
|
|
76
32
|
/**
|
|
77
33
|
* @example
|
|
78
34
|
* ```ts
|
|
@@ -90,4 +46,4 @@ declare const TanStackRouterRspack: (options?: unknown) => import('unplugin').Rs
|
|
|
90
46
|
declare const tanstackRouter: (options?: unknown) => import('unplugin').RspackPluginInstance;
|
|
91
47
|
export default TanStackRouterRspack;
|
|
92
48
|
export { configSchema, TanStackRouterRspack, TanStackRouterGeneratorRspack, TanStackRouterCodeSplitterRspack, tanstackRouter, };
|
|
93
|
-
export type { Config, CodeSplittingOptions };
|
|
49
|
+
export type { Config, CodeSplittingOptions, RouterPluginContext };
|