@tanstack/router-plugin 1.167.22 → 1.167.23
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/core/code-splitter/compilers.cjs +8 -4
- package/dist/cjs/core/code-splitter/compilers.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/plugins/framework-plugins.cjs +8 -5
- package/dist/cjs/core/code-splitter/plugins/framework-plugins.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/plugins/framework-plugins.d.cts +2 -2
- package/dist/cjs/core/code-splitter/plugins/react-refresh-ignored-route-exports.cjs +5 -9
- package/dist/cjs/core/code-splitter/plugins/react-refresh-ignored-route-exports.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/plugins/react-refresh-ignored-route-exports.d.cts +1 -3
- package/dist/cjs/core/code-splitter/plugins/react-stable-hmr-split-route-components.cjs +6 -4
- package/dist/cjs/core/code-splitter/plugins/react-stable-hmr-split-route-components.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/plugins/react-stable-hmr-split-route-components.d.cts +3 -2
- package/dist/cjs/core/code-splitter/plugins.d.cts +3 -2
- package/dist/cjs/core/config.cjs +1 -1
- package/dist/cjs/core/config.cjs.map +1 -1
- package/dist/cjs/core/config.d.cts +26 -18
- package/dist/cjs/core/{route-hmr-statement.cjs → hmr/handle-route-update.cjs} +39 -25
- package/dist/cjs/core/hmr/handle-route-update.cjs.map +1 -0
- package/dist/cjs/core/hmr/handle-route-update.d.cts +1 -0
- package/dist/cjs/core/hmr/index.d.cts +5 -0
- package/dist/cjs/core/hmr/select-adapter.cjs +20 -0
- package/dist/cjs/core/hmr/select-adapter.cjs.map +1 -0
- package/dist/cjs/core/hmr/select-adapter.d.cts +13 -0
- package/dist/cjs/core/hmr/vite-adapter.cjs +36 -0
- package/dist/cjs/core/hmr/vite-adapter.cjs.map +1 -0
- package/dist/cjs/core/hmr/vite-adapter.d.cts +12 -0
- package/dist/cjs/core/hmr/webpack-adapter.cjs +64 -0
- package/dist/cjs/core/hmr/webpack-adapter.cjs.map +1 -0
- package/dist/cjs/core/hmr/webpack-adapter.d.cts +20 -0
- package/dist/cjs/core/router-code-splitter-plugin.cjs +5 -5
- package/dist/cjs/core/router-code-splitter-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-composed-plugin.cjs +2 -1
- package/dist/cjs/core/router-composed-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-composed-plugin.d.cts +1 -1
- package/dist/cjs/core/router-hmr-plugin.cjs +17 -11
- package/dist/cjs/core/router-hmr-plugin.cjs.map +1 -1
- package/dist/cjs/esbuild.d.cts +14 -14
- package/dist/cjs/rspack.cjs +22 -3
- package/dist/cjs/rspack.cjs.map +1 -1
- package/dist/cjs/rspack.d.cts +3 -3
- package/dist/cjs/vite.d.cts +14 -14
- package/dist/cjs/webpack.cjs +19 -3
- package/dist/cjs/webpack.cjs.map +1 -1
- package/dist/cjs/webpack.d.cts +3 -3
- package/dist/esm/core/code-splitter/compilers.js +7 -3
- package/dist/esm/core/code-splitter/compilers.js.map +1 -1
- package/dist/esm/core/code-splitter/plugins/framework-plugins.d.ts +2 -2
- package/dist/esm/core/code-splitter/plugins/framework-plugins.js +8 -5
- package/dist/esm/core/code-splitter/plugins/framework-plugins.js.map +1 -1
- package/dist/esm/core/code-splitter/plugins/react-refresh-ignored-route-exports.d.ts +1 -3
- package/dist/esm/core/code-splitter/plugins/react-refresh-ignored-route-exports.js +4 -8
- package/dist/esm/core/code-splitter/plugins/react-refresh-ignored-route-exports.js.map +1 -1
- package/dist/esm/core/code-splitter/plugins/react-stable-hmr-split-route-components.d.ts +3 -2
- package/dist/esm/core/code-splitter/plugins/react-stable-hmr-split-route-components.js +5 -3
- package/dist/esm/core/code-splitter/plugins/react-stable-hmr-split-route-components.js.map +1 -1
- package/dist/esm/core/code-splitter/plugins.d.ts +3 -2
- package/dist/esm/core/config.d.ts +26 -18
- package/dist/esm/core/config.js +1 -1
- package/dist/esm/core/config.js.map +1 -1
- package/dist/esm/core/hmr/handle-route-update.d.ts +1 -0
- package/dist/esm/core/{route-hmr-statement.js → hmr/handle-route-update.js} +39 -23
- package/dist/esm/core/hmr/handle-route-update.js.map +1 -0
- package/dist/esm/core/hmr/index.d.ts +5 -0
- package/dist/esm/core/hmr/select-adapter.d.ts +13 -0
- package/dist/esm/core/hmr/select-adapter.js +20 -0
- package/dist/esm/core/hmr/select-adapter.js.map +1 -0
- package/dist/esm/core/hmr/vite-adapter.d.ts +12 -0
- package/dist/esm/core/hmr/vite-adapter.js +34 -0
- package/dist/esm/core/hmr/vite-adapter.js.map +1 -0
- package/dist/esm/core/hmr/webpack-adapter.d.ts +20 -0
- package/dist/esm/core/hmr/webpack-adapter.js +62 -0
- package/dist/esm/core/hmr/webpack-adapter.js.map +1 -0
- package/dist/esm/core/router-code-splitter-plugin.js +5 -5
- package/dist/esm/core/router-code-splitter-plugin.js.map +1 -1
- package/dist/esm/core/router-composed-plugin.d.ts +1 -1
- package/dist/esm/core/router-composed-plugin.js +2 -1
- package/dist/esm/core/router-composed-plugin.js.map +1 -1
- package/dist/esm/core/router-hmr-plugin.js +17 -11
- package/dist/esm/core/router-hmr-plugin.js.map +1 -1
- package/dist/esm/esbuild.d.ts +14 -14
- package/dist/esm/rspack.d.ts +3 -3
- package/dist/esm/rspack.js +22 -3
- package/dist/esm/rspack.js.map +1 -1
- package/dist/esm/vite.d.ts +14 -14
- package/dist/esm/webpack.d.ts +3 -3
- package/dist/esm/webpack.js +19 -3
- package/dist/esm/webpack.js.map +1 -1
- package/package.json +5 -5
- package/src/core/code-splitter/compilers.ts +4 -2
- package/src/core/code-splitter/plugins/framework-plugins.ts +7 -8
- package/src/core/code-splitter/plugins/react-refresh-ignored-route-exports.ts +2 -8
- package/src/core/code-splitter/plugins/react-stable-hmr-split-route-components.ts +10 -6
- package/src/core/code-splitter/plugins.ts +3 -2
- package/src/core/config.ts +11 -2
- package/src/core/{route-hmr-statement.ts → hmr/handle-route-update.ts} +85 -39
- package/src/core/hmr/index.ts +5 -0
- package/src/core/hmr/select-adapter.ts +32 -0
- package/src/core/hmr/vite-adapter.ts +47 -0
- package/src/core/hmr/webpack-adapter.ts +110 -0
- package/src/core/router-code-splitter-plugin.ts +5 -7
- package/src/core/router-composed-plugin.ts +8 -3
- package/src/core/router-hmr-plugin.ts +12 -9
- package/src/rspack.ts +37 -9
- package/src/webpack.ts +22 -9
- package/dist/cjs/core/hmr-hot-expression.cjs +0 -27
- package/dist/cjs/core/hmr-hot-expression.cjs.map +0 -1
- package/dist/cjs/core/hmr-hot-expression.d.cts +0 -6
- package/dist/cjs/core/route-hmr-statement.cjs.map +0 -1
- package/dist/cjs/core/route-hmr-statement.d.cts +0 -4
- package/dist/esm/core/hmr-hot-expression.d.ts +0 -6
- package/dist/esm/core/hmr-hot-expression.js +0 -23
- package/dist/esm/core/hmr-hot-expression.js.map +0 -1
- package/dist/esm/core/route-hmr-statement.d.ts +0 -4
- package/dist/esm/core/route-hmr-statement.js.map +0 -1
- package/src/core/hmr-hot-expression.ts +0 -31
|
@@ -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 { resolveHmrHotExpression } from './hmr-hot-expression'\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.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 // 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 hmrHotExpression = resolveHmrHotExpression(\n userConfig.plugin?.hmr?.hotExpression,\n )\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 hmrHotExpression,\n sharedBindings: sharedBindings.size > 0 ? sharedBindings : undefined,\n compilerPlugins: getReferenceRouteCompilerPlugins({\n targetFramework: userConfig.target,\n addHmr,\n hmrHotExpression,\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":";;;;;;;;;;;;;;AAiCA,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,IAAa,qCAER,UAAU,EAAE,EAAE,EAAE,WAAW,iBAAiB;CAC/C,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,s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AQ,MAAM,IAAI;KAChB,MAAM,MAAM,cAAc,GAAG;AAC7B,SAAI,aAAa,OAAO,IAAI;KAC5B,MAAM,eAAe,cAAc,cAAc,IAAI,CAAC;KACtD,MAAM,CAAC,UAAU,aAAa,MAAM,IAAI;AAExC,SAAI,CAAC,OAAQ,QAAO;KAEpB,MAAM,iBAAiB,kBAAkB,IAAI,OAAO;AACpD,SAAI,CAAC,kBAAkB,eAAe,SAAS,EAAG,QAAO;AAEzD,SAAI,MAAO,SAAQ,KAAK,6BAA6B,GAAG;KAExD,MAAM,SAAS,4BAA4B;MACzC;MACA;MACA,UAAU;MACX,CAAC;AAEF,SAAI,OAAO;AACT,cAAQ,MAAM,OAAO,KAAK;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"}
|
|
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;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,IAAa,qCAER,UAAU,EAAE,EAAE,EAAE,WAAW,iBAAiB;CAC/C,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,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Ac,GAAG;AAC7B,SAAI,aAAa,OAAO,IAAI;KAC5B,MAAM,eAAe,cAAc,cAAc,IAAI,CAAC;KACtD,MAAM,CAAC,UAAU,aAAa,MAAM,IAAI;AAExC,SAAI,CAAC,OAAQ,QAAO;KAEpB,MAAM,iBAAiB,kBAAkB,IAAI,OAAO;AACpD,SAAI,CAAC,kBAAkB,eAAe,SAAS,EAAG,QAAO;AAEzD,SAAI,MAAO,SAAQ,KAAK,6BAA6B,GAAG;KAExD,MAAM,SAAS,4BAA4B;MACzC;MACA;MACA,UAAU;MACX,CAAC;AAEF,SAAI,OAAO;AACT,cAAQ,MAAM,OAAO,KAAK;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"}
|
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
import { Config } from './config.js';
|
|
2
2
|
import { UnpluginFactory } from 'unplugin';
|
|
3
|
-
export declare const unpluginRouterComposedFactory: UnpluginFactory<Partial<Config> | undefined>;
|
|
3
|
+
export declare const unpluginRouterComposedFactory: UnpluginFactory<Partial<Config | (() => Config)> | undefined>;
|
|
@@ -4,7 +4,8 @@ import { unpluginRouterHmrFactory } from "./router-hmr-plugin.js";
|
|
|
4
4
|
import { getConfig } from "@tanstack/router-generator";
|
|
5
5
|
//#region src/core/router-composed-plugin.ts
|
|
6
6
|
var unpluginRouterComposedFactory = (options = {}, meta) => {
|
|
7
|
-
const
|
|
7
|
+
const ROOT = process.cwd();
|
|
8
|
+
const userConfig = getConfig(typeof options === "function" ? options() : options, ROOT);
|
|
8
9
|
const getPlugin = (pluginFactory) => {
|
|
9
10
|
const plugin = pluginFactory(options, meta);
|
|
10
11
|
if (!Array.isArray(plugin)) return [plugin];
|
|
@@ -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 { unpluginRouterGeneratorFactory } from './router-generator-plugin'\nimport { unpluginRouterCodeSplitterFactory } from './router-code-splitter-plugin'\nimport { unpluginRouterHmrFactory } from './router-hmr-plugin'\nimport type { Config } from './config'\nimport type { UnpluginFactory } from 'unplugin'\n\nexport const unpluginRouterComposedFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}, meta) => {\n const ROOT: string = process.cwd()\n const userConfig = getConfig(options
|
|
1
|
+
{"version":3,"file":"router-composed-plugin.js","names":[],"sources":["../../../src/core/router-composed-plugin.ts"],"sourcesContent":["import { getConfig } from '@tanstack/router-generator'\nimport { unpluginRouterGeneratorFactory } from './router-generator-plugin'\nimport { unpluginRouterCodeSplitterFactory } from './router-code-splitter-plugin'\nimport { unpluginRouterHmrFactory } from './router-hmr-plugin'\nimport type { Config } from './config'\nimport type { UnpluginFactory } from 'unplugin'\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\n const getPlugin = (\n pluginFactory: UnpluginFactory<Partial<Config | (() => Config)>>,\n ) => {\n const plugin = pluginFactory(options, meta)\n if (!Array.isArray(plugin)) {\n return [plugin]\n }\n return plugin\n }\n\n const routerGenerator = getPlugin(unpluginRouterGeneratorFactory)\n const routerCodeSplitter = getPlugin(unpluginRouterCodeSplitterFactory)\n\n const result = [...routerGenerator]\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(unpluginRouterHmrFactory)\n result.push(...routerHmr)\n }\n return result\n}\n"],"mappings":";;;;;AAOA,IAAa,iCAER,UAAU,EAAE,EAAE,SAAS;CAC1B,MAAM,OAAe,QAAQ,KAAK;CAClC,MAAM,aAAa,UAChB,OAAO,YAAY,aAAa,SAAS,GAAG,SAC7C,KACD;CAED,MAAM,aACJ,kBACG;EACH,MAAM,SAAS,cAAc,SAAS,KAAK;AAC3C,MAAI,CAAC,MAAM,QAAQ,OAAO,CACxB,QAAO,CAAC,OAAO;AAEjB,SAAO;;CAGT,MAAM,kBAAkB,UAAU,+BAA+B;CACjE,MAAM,qBAAqB,UAAU,kCAAkC;CAEvE,MAAM,SAAS,CAAC,GAAG,gBAAgB;AACnC,KAAI,WAAW,kBACb,QAAO,KAAK,GAAG,mBAAmB;AAKpC,KAAI,EAAA,QAAA,IAAA,aAF0C,iBAEzB,CAAC,WAAW,mBAAmB;EAClD,MAAM,YAAY,UAAU,yBAAyB;AACrD,SAAO,KAAK,GAAG,UAAU;;AAE3B,QAAO"}
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { getConfig } from "./config.js";
|
|
2
|
-
import {
|
|
3
|
-
import { createRouteHmrStatement } from "./route-hmr-statement.js";
|
|
2
|
+
import { createRouteHmrStatement } from "./hmr/select-adapter.js";
|
|
4
3
|
import { debug, normalizePath } from "./utils.js";
|
|
5
4
|
import { compileCodeSplitReferenceRoute } from "./code-splitter/compilers.js";
|
|
6
5
|
import { getReferenceRouteCompilerPlugins } from "./code-splitter/plugins/framework-plugins.js";
|
|
@@ -29,23 +28,26 @@ var unpluginRouterHmrFactory = (options = {}) => {
|
|
|
29
28
|
},
|
|
30
29
|
handler(code, id) {
|
|
31
30
|
const normalizedId = normalizePath(id);
|
|
32
|
-
|
|
31
|
+
const routeEntry = globalThis.TSR_ROUTES_BY_ID_MAP?.get(normalizedId);
|
|
32
|
+
if (!routeEntry) return null;
|
|
33
33
|
if (debug) console.info("Adding HMR handling to route ", normalizedId);
|
|
34
|
-
const
|
|
34
|
+
const hmrStyle = userConfig.plugin?.hmr?.style ?? "vite";
|
|
35
35
|
if (userConfig.target === "react") {
|
|
36
|
+
const compilerPlugins = getReferenceRouteCompilerPlugins({
|
|
37
|
+
targetFramework: "react",
|
|
38
|
+
addHmr: true,
|
|
39
|
+
hmrStyle
|
|
40
|
+
});
|
|
36
41
|
const compiled = compileCodeSplitReferenceRoute({
|
|
37
42
|
code,
|
|
38
43
|
filename: normalizedId,
|
|
39
44
|
id: normalizedId,
|
|
40
45
|
addHmr: true,
|
|
41
|
-
|
|
46
|
+
hmrStyle,
|
|
47
|
+
hmrRouteId: routeEntry.routeId,
|
|
42
48
|
codeSplitGroupings: [],
|
|
43
49
|
targetFramework: "react",
|
|
44
|
-
compilerPlugins
|
|
45
|
-
targetFramework: "react",
|
|
46
|
-
addHmr: true,
|
|
47
|
-
hmrHotExpression
|
|
48
|
-
})
|
|
50
|
+
compilerPlugins
|
|
49
51
|
});
|
|
50
52
|
if (compiled) {
|
|
51
53
|
if (debug) {
|
|
@@ -56,7 +58,11 @@ var unpluginRouterHmrFactory = (options = {}) => {
|
|
|
56
58
|
}
|
|
57
59
|
}
|
|
58
60
|
const ast = parseAst({ code });
|
|
59
|
-
ast.program.body.push(createRouteHmrStatement([], {
|
|
61
|
+
ast.program.body.push(...createRouteHmrStatement([], {
|
|
62
|
+
hmrStyle,
|
|
63
|
+
targetFramework: userConfig.target,
|
|
64
|
+
routeId: routeEntry.routeId
|
|
65
|
+
}));
|
|
60
66
|
const result = generateFromAst(ast, {
|
|
61
67
|
sourceMaps: true,
|
|
62
68
|
filename: normalizedId,
|
|
@@ -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 './
|
|
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 const unpluginRouterHmrFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}) => {\n let ROOT: string = process.cwd()\n let userConfig = options as Config\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 = globalThis.TSR_ROUTES_BY_ID_MAP?.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 })\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 = 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}\n"],"mappings":";;;;;;;;;;;;AAeA,IAAM,cAAc;CAClB;CACA;CACA;CACD;AACD,IAAa,4BAER,UAAU,EAAE,KAAK;CACpB,IAAI,OAAe,QAAQ,KAAK;CAChC,IAAI,aAAa;AAEjB,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,WAAW,sBAAsB,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,EAAE,MAAM,CAAC;AAC9B,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,UAAU,SAAS,KAAK;;GAEvC,mBAAmB,aAAa;AAC9B,QAAI,WAAW,QAAQ,MAAM,gBAC3B,QAAO,WAAW,OAAO,KAAK,oBAAoB,YAAY;AAEhE,WAAO;;GAEV;EACF"}
|
package/dist/esm/esbuild.d.ts
CHANGED
|
@@ -33,12 +33,12 @@ declare const TanStackRouterGeneratorEsbuild: (options?: Partial<{
|
|
|
33
33
|
enableRouteGeneration?: boolean | undefined;
|
|
34
34
|
codeSplittingOptions?: CodeSplittingOptions | undefined;
|
|
35
35
|
plugin?: {
|
|
36
|
-
hmr?: {
|
|
37
|
-
hotExpression?: string | undefined;
|
|
38
|
-
} | undefined;
|
|
39
36
|
vite?: {
|
|
40
37
|
environmentName?: string | undefined;
|
|
41
38
|
} | undefined;
|
|
39
|
+
hmr?: {
|
|
40
|
+
style?: "vite" | "webpack" | undefined;
|
|
41
|
+
} | undefined;
|
|
42
42
|
} | undefined;
|
|
43
43
|
virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
|
|
44
44
|
routeFilePrefix?: string | undefined;
|
|
@@ -89,12 +89,12 @@ declare const TanStackRouterCodeSplitterEsbuild: (options?: Partial<{
|
|
|
89
89
|
enableRouteGeneration?: boolean | undefined;
|
|
90
90
|
codeSplittingOptions?: CodeSplittingOptions | undefined;
|
|
91
91
|
plugin?: {
|
|
92
|
-
hmr?: {
|
|
93
|
-
hotExpression?: string | undefined;
|
|
94
|
-
} | undefined;
|
|
95
92
|
vite?: {
|
|
96
93
|
environmentName?: string | undefined;
|
|
97
94
|
} | undefined;
|
|
95
|
+
hmr?: {
|
|
96
|
+
style?: "vite" | "webpack" | undefined;
|
|
97
|
+
} | undefined;
|
|
98
98
|
} | undefined;
|
|
99
99
|
virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
|
|
100
100
|
routeFilePrefix?: string | undefined;
|
|
@@ -145,12 +145,12 @@ declare const TanStackRouterEsbuild: (options?: Partial<{
|
|
|
145
145
|
enableRouteGeneration?: boolean | undefined;
|
|
146
146
|
codeSplittingOptions?: CodeSplittingOptions | undefined;
|
|
147
147
|
plugin?: {
|
|
148
|
-
hmr?: {
|
|
149
|
-
hotExpression?: string | undefined;
|
|
150
|
-
} | undefined;
|
|
151
148
|
vite?: {
|
|
152
149
|
environmentName?: string | undefined;
|
|
153
150
|
} | undefined;
|
|
151
|
+
hmr?: {
|
|
152
|
+
style?: "vite" | "webpack" | undefined;
|
|
153
|
+
} | undefined;
|
|
154
154
|
} | undefined;
|
|
155
155
|
virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
|
|
156
156
|
routeFilePrefix?: string | undefined;
|
|
@@ -166,7 +166,7 @@ declare const TanStackRouterEsbuild: (options?: Partial<{
|
|
|
166
166
|
enableCodeSplitting?: boolean | undefined;
|
|
167
167
|
} | undefined;
|
|
168
168
|
plugins?: import('@tanstack/router-generator').GeneratorPlugin[] | undefined;
|
|
169
|
-
}> | undefined) => import('unplugin').EsbuildPlugin;
|
|
169
|
+
} | (() => Config)> | undefined) => import('unplugin').EsbuildPlugin;
|
|
170
170
|
declare const tanstackRouter: (options?: Partial<{
|
|
171
171
|
target: "react" | "solid" | "vue";
|
|
172
172
|
routeFileIgnorePrefix: string;
|
|
@@ -192,12 +192,12 @@ declare const tanstackRouter: (options?: Partial<{
|
|
|
192
192
|
enableRouteGeneration?: boolean | undefined;
|
|
193
193
|
codeSplittingOptions?: CodeSplittingOptions | undefined;
|
|
194
194
|
plugin?: {
|
|
195
|
-
hmr?: {
|
|
196
|
-
hotExpression?: string | undefined;
|
|
197
|
-
} | undefined;
|
|
198
195
|
vite?: {
|
|
199
196
|
environmentName?: string | undefined;
|
|
200
197
|
} | undefined;
|
|
198
|
+
hmr?: {
|
|
199
|
+
style?: "vite" | "webpack" | undefined;
|
|
200
|
+
} | undefined;
|
|
201
201
|
} | undefined;
|
|
202
202
|
virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
|
|
203
203
|
routeFilePrefix?: string | undefined;
|
|
@@ -213,7 +213,7 @@ declare const tanstackRouter: (options?: Partial<{
|
|
|
213
213
|
enableCodeSplitting?: boolean | undefined;
|
|
214
214
|
} | undefined;
|
|
215
215
|
plugins?: import('@tanstack/router-generator').GeneratorPlugin[] | undefined;
|
|
216
|
-
}> | undefined) => import('unplugin').EsbuildPlugin;
|
|
216
|
+
} | (() => Config)> | undefined) => import('unplugin').EsbuildPlugin;
|
|
217
217
|
export default TanStackRouterEsbuild;
|
|
218
218
|
export { configSchema, TanStackRouterGeneratorEsbuild, TanStackRouterCodeSplitterEsbuild, TanStackRouterEsbuild, tanstackRouter, };
|
|
219
219
|
export type { Config, CodeSplittingOptions };
|
package/dist/esm/rspack.d.ts
CHANGED
|
@@ -37,12 +37,12 @@ declare const TanStackRouterGeneratorRspack: (options?: Partial<{
|
|
|
37
37
|
enableRouteGeneration?: boolean | undefined;
|
|
38
38
|
codeSplittingOptions?: CodeSplittingOptions | undefined;
|
|
39
39
|
plugin?: {
|
|
40
|
-
hmr?: {
|
|
41
|
-
hotExpression?: string | undefined;
|
|
42
|
-
} | undefined;
|
|
43
40
|
vite?: {
|
|
44
41
|
environmentName?: string | undefined;
|
|
45
42
|
} | undefined;
|
|
43
|
+
hmr?: {
|
|
44
|
+
style?: "vite" | "webpack" | undefined;
|
|
45
|
+
} | undefined;
|
|
46
46
|
} | undefined;
|
|
47
47
|
virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
|
|
48
48
|
routeFilePrefix?: string | undefined;
|
package/dist/esm/rspack.js
CHANGED
|
@@ -1,11 +1,30 @@
|
|
|
1
1
|
import { configSchema } from "./core/config.js";
|
|
2
|
-
import { withHmrHotExpression } from "./core/hmr-hot-expression.js";
|
|
3
2
|
import { unpluginRouterCodeSplitterFactory } from "./core/router-code-splitter-plugin.js";
|
|
4
3
|
import { unpluginRouterGeneratorFactory } from "./core/router-generator-plugin.js";
|
|
5
4
|
import { unpluginRouterComposedFactory } from "./core/router-composed-plugin.js";
|
|
6
5
|
import { createRspackPlugin } from "unplugin";
|
|
7
6
|
//#region src/rspack.ts
|
|
8
7
|
/**
|
|
8
|
+
* Rspack uses webpack-compatible `module.hot` / `import.meta.webpackHot` HMR.
|
|
9
|
+
* Force `plugin.hmr.style = 'webpack'` so the router HMR adapter emits
|
|
10
|
+
* `module.hot`-style accept/dispose code instead of Vite's callback-receive
|
|
11
|
+
* variant, regardless of what the user passes (or doesn't pass).
|
|
12
|
+
*/
|
|
13
|
+
function withWebpackHmrStyle(options) {
|
|
14
|
+
const mergeHmrStyle = (config) => ({
|
|
15
|
+
...config,
|
|
16
|
+
plugin: {
|
|
17
|
+
...config?.plugin,
|
|
18
|
+
hmr: {
|
|
19
|
+
...config?.plugin?.hmr,
|
|
20
|
+
style: "webpack"
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
});
|
|
24
|
+
if (typeof options === "function") return () => mergeHmrStyle(options());
|
|
25
|
+
return mergeHmrStyle(options);
|
|
26
|
+
}
|
|
27
|
+
/**
|
|
9
28
|
* @example
|
|
10
29
|
* ```ts
|
|
11
30
|
* export default defineConfig({
|
|
@@ -32,7 +51,7 @@ var TanStackRouterGeneratorRspack = /* @__PURE__ */ createRspackPlugin(unpluginR
|
|
|
32
51
|
* })
|
|
33
52
|
* ```
|
|
34
53
|
*/
|
|
35
|
-
var TanStackRouterCodeSplitterRspack = /* @__PURE__ */ createRspackPlugin((options, meta) => unpluginRouterCodeSplitterFactory(
|
|
54
|
+
var TanStackRouterCodeSplitterRspack = /* @__PURE__ */ createRspackPlugin((options, meta) => unpluginRouterCodeSplitterFactory(withWebpackHmrStyle(options), meta));
|
|
36
55
|
/**
|
|
37
56
|
* @example
|
|
38
57
|
* ```ts
|
|
@@ -46,7 +65,7 @@ var TanStackRouterCodeSplitterRspack = /* @__PURE__ */ createRspackPlugin((optio
|
|
|
46
65
|
* })
|
|
47
66
|
* ```
|
|
48
67
|
*/
|
|
49
|
-
var TanStackRouterRspack = /* @__PURE__ */ createRspackPlugin((options, meta) => unpluginRouterComposedFactory(
|
|
68
|
+
var TanStackRouterRspack = /* @__PURE__ */ createRspackPlugin((options, meta) => unpluginRouterComposedFactory(withWebpackHmrStyle(options), meta));
|
|
50
69
|
var tanstackRouter = TanStackRouterRspack;
|
|
51
70
|
//#endregion
|
|
52
71
|
export { TanStackRouterCodeSplitterRspack, TanStackRouterGeneratorRspack, TanStackRouterRspack, TanStackRouterRspack as default, configSchema, tanstackRouter };
|
package/dist/esm/rspack.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"rspack.js","names":[],"sources":["../../src/rspack.ts"],"sourcesContent":["import { createRspackPlugin } from 'unplugin'\n\nimport { configSchema } from './core/config'\nimport {
|
|
1
|
+
{"version":3,"file":"rspack.js","names":[],"sources":["../../src/rspack.ts"],"sourcesContent":["import { createRspackPlugin } from 'unplugin'\n\nimport { configSchema } from './core/config'\nimport { unpluginRouterCodeSplitterFactory } from './core/router-code-splitter-plugin'\nimport { unpluginRouterGeneratorFactory } from './core/router-generator-plugin'\nimport { unpluginRouterComposedFactory } from './core/router-composed-plugin'\nimport type { CodeSplittingOptions, Config } from './core/config'\n\ntype RspackRouterPluginOptions = Partial<Config> | (() => Partial<Config>)\n\n/**\n * Rspack uses webpack-compatible `module.hot` / `import.meta.webpackHot` HMR.\n * Force `plugin.hmr.style = 'webpack'` so the router HMR adapter emits\n * `module.hot`-style accept/dispose code instead of Vite's callback-receive\n * variant, regardless of what the user passes (or doesn't pass).\n */\nfunction withWebpackHmrStyle(\n options: RspackRouterPluginOptions | undefined,\n): RspackRouterPluginOptions {\n const mergeHmrStyle = (\n config: Partial<Config> | undefined,\n ): Partial<Config> => ({\n ...config,\n plugin: {\n ...config?.plugin,\n hmr: {\n ...config?.plugin?.hmr,\n style: 'webpack',\n },\n },\n })\n\n if (typeof options === 'function') {\n return () => mergeHmrStyle(options())\n }\n\n return mergeHmrStyle(options)\n}\n\n/**\n * @example\n * ```ts\n * export default defineConfig({\n * // ...\n * tools: {\n * rspack: {\n * plugins: [TanStackRouterGeneratorRspack()],\n * },\n * },\n * })\n * ```\n */\nconst TanStackRouterGeneratorRspack = /* #__PURE__ */ createRspackPlugin(\n unpluginRouterGeneratorFactory,\n)\n\n/**\n * @example\n * ```ts\n * export default defineConfig({\n * // ...\n * tools: {\n * rspack: {\n * plugins: [TanStackRouterCodeSplitterRspack()],\n * },\n * },\n * })\n * ```\n */\nconst TanStackRouterCodeSplitterRspack = /* #__PURE__ */ createRspackPlugin(\n (options, meta) =>\n unpluginRouterCodeSplitterFactory(\n withWebpackHmrStyle(\n options as RspackRouterPluginOptions | undefined,\n ) as Partial<Config | (() => Config)>,\n meta,\n ),\n)\n\n/**\n * @example\n * ```ts\n * export default defineConfig({\n * // ...\n * tools: {\n * rspack: {\n * plugins: [tanstackRouter()],\n * },\n * },\n * })\n * ```\n */\nconst TanStackRouterRspack = /* #__PURE__ */ createRspackPlugin(\n (options, meta) =>\n unpluginRouterComposedFactory(\n withWebpackHmrStyle(\n options as RspackRouterPluginOptions | undefined,\n ) as Partial<Config | (() => Config)>,\n meta,\n ),\n)\nconst tanstackRouter = TanStackRouterRspack\nexport default TanStackRouterRspack\nexport {\n configSchema,\n TanStackRouterRspack,\n TanStackRouterGeneratorRspack,\n TanStackRouterCodeSplitterRspack,\n tanstackRouter,\n}\nexport type { Config, CodeSplittingOptions }\n"],"mappings":";;;;;;;;;;;;AAgBA,SAAS,oBACP,SAC2B;CAC3B,MAAM,iBACJ,YACqB;EACrB,GAAG;EACH,QAAQ;GACN,GAAG,QAAQ;GACX,KAAK;IACH,GAAG,QAAQ,QAAQ;IACnB,OAAO;IACR;GACF;EACF;AAED,KAAI,OAAO,YAAY,WACrB,cAAa,cAAc,SAAS,CAAC;AAGvC,QAAO,cAAc,QAAQ;;;;;;;;;;;;;;;AAgB/B,IAAM,gCAAgD,mCACpD,+BACD;;;;;;;;;;;;;;AAeD,IAAM,mCAAmD,oCACtD,SAAS,SACR,kCACE,oBACE,QACD,EACD,KACD,CACJ;;;;;;;;;;;;;;AAeD,IAAM,uBAAuC,oCAC1C,SAAS,SACR,8BACE,oBACE,QACD,EACD,KACD,CACJ;AACD,IAAM,iBAAiB"}
|
package/dist/esm/vite.d.ts
CHANGED
|
@@ -33,12 +33,12 @@ declare const tanstackRouterGenerator: (options?: Partial<{
|
|
|
33
33
|
enableRouteGeneration?: boolean | undefined;
|
|
34
34
|
codeSplittingOptions?: CodeSplittingOptions | undefined;
|
|
35
35
|
plugin?: {
|
|
36
|
-
hmr?: {
|
|
37
|
-
hotExpression?: string | undefined;
|
|
38
|
-
} | undefined;
|
|
39
36
|
vite?: {
|
|
40
37
|
environmentName?: string | undefined;
|
|
41
38
|
} | undefined;
|
|
39
|
+
hmr?: {
|
|
40
|
+
style?: "vite" | "webpack" | undefined;
|
|
41
|
+
} | undefined;
|
|
42
42
|
} | undefined;
|
|
43
43
|
virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
|
|
44
44
|
routeFilePrefix?: string | undefined;
|
|
@@ -89,12 +89,12 @@ declare const tanStackRouterCodeSplitter: (options?: Partial<{
|
|
|
89
89
|
enableRouteGeneration?: boolean | undefined;
|
|
90
90
|
codeSplittingOptions?: CodeSplittingOptions | undefined;
|
|
91
91
|
plugin?: {
|
|
92
|
-
hmr?: {
|
|
93
|
-
hotExpression?: string | undefined;
|
|
94
|
-
} | undefined;
|
|
95
92
|
vite?: {
|
|
96
93
|
environmentName?: string | undefined;
|
|
97
94
|
} | undefined;
|
|
95
|
+
hmr?: {
|
|
96
|
+
style?: "vite" | "webpack" | undefined;
|
|
97
|
+
} | undefined;
|
|
98
98
|
} | undefined;
|
|
99
99
|
virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
|
|
100
100
|
routeFilePrefix?: string | undefined;
|
|
@@ -145,12 +145,12 @@ declare const tanstackRouter: (options?: Partial<{
|
|
|
145
145
|
enableRouteGeneration?: boolean | undefined;
|
|
146
146
|
codeSplittingOptions?: CodeSplittingOptions | undefined;
|
|
147
147
|
plugin?: {
|
|
148
|
-
hmr?: {
|
|
149
|
-
hotExpression?: string | undefined;
|
|
150
|
-
} | undefined;
|
|
151
148
|
vite?: {
|
|
152
149
|
environmentName?: string | undefined;
|
|
153
150
|
} | undefined;
|
|
151
|
+
hmr?: {
|
|
152
|
+
style?: "vite" | "webpack" | undefined;
|
|
153
|
+
} | undefined;
|
|
154
154
|
} | undefined;
|
|
155
155
|
virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
|
|
156
156
|
routeFilePrefix?: string | undefined;
|
|
@@ -166,7 +166,7 @@ declare const tanstackRouter: (options?: Partial<{
|
|
|
166
166
|
enableCodeSplitting?: boolean | undefined;
|
|
167
167
|
} | undefined;
|
|
168
168
|
plugins?: import('@tanstack/router-generator').GeneratorPlugin[] | undefined;
|
|
169
|
-
}> | undefined) => import('vite').Plugin<any> | import('vite').Plugin<any>[];
|
|
169
|
+
} | (() => Config)> | undefined) => import('vite').Plugin<any> | import('vite').Plugin<any>[];
|
|
170
170
|
/**
|
|
171
171
|
* @deprecated Use `tanstackRouter` instead.
|
|
172
172
|
*/
|
|
@@ -195,12 +195,12 @@ declare const TanStackRouterVite: (options?: Partial<{
|
|
|
195
195
|
enableRouteGeneration?: boolean | undefined;
|
|
196
196
|
codeSplittingOptions?: CodeSplittingOptions | undefined;
|
|
197
197
|
plugin?: {
|
|
198
|
-
hmr?: {
|
|
199
|
-
hotExpression?: string | undefined;
|
|
200
|
-
} | undefined;
|
|
201
198
|
vite?: {
|
|
202
199
|
environmentName?: string | undefined;
|
|
203
200
|
} | undefined;
|
|
201
|
+
hmr?: {
|
|
202
|
+
style?: "vite" | "webpack" | undefined;
|
|
203
|
+
} | undefined;
|
|
204
204
|
} | undefined;
|
|
205
205
|
virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
|
|
206
206
|
routeFilePrefix?: string | undefined;
|
|
@@ -216,7 +216,7 @@ declare const TanStackRouterVite: (options?: Partial<{
|
|
|
216
216
|
enableCodeSplitting?: boolean | undefined;
|
|
217
217
|
} | undefined;
|
|
218
218
|
plugins?: import('@tanstack/router-generator').GeneratorPlugin[] | undefined;
|
|
219
|
-
}> | undefined) => import('vite').Plugin<any> | import('vite').Plugin<any>[];
|
|
219
|
+
} | (() => Config)> | undefined) => import('vite').Plugin<any> | import('vite').Plugin<any>[];
|
|
220
220
|
export default tanstackRouter;
|
|
221
221
|
export { configSchema, getConfig, tanStackRouterCodeSplitter, tanstackRouterGenerator, TanStackRouterVite, tanstackRouter, };
|
|
222
222
|
export type { Config, CodeSplittingOptions };
|
package/dist/esm/webpack.d.ts
CHANGED
|
@@ -33,12 +33,12 @@ declare const TanStackRouterGeneratorWebpack: (options?: Partial<{
|
|
|
33
33
|
enableRouteGeneration?: boolean | undefined;
|
|
34
34
|
codeSplittingOptions?: CodeSplittingOptions | undefined;
|
|
35
35
|
plugin?: {
|
|
36
|
-
hmr?: {
|
|
37
|
-
hotExpression?: string | undefined;
|
|
38
|
-
} | undefined;
|
|
39
36
|
vite?: {
|
|
40
37
|
environmentName?: string | undefined;
|
|
41
38
|
} | undefined;
|
|
39
|
+
hmr?: {
|
|
40
|
+
style?: "vite" | "webpack" | undefined;
|
|
41
|
+
} | undefined;
|
|
42
42
|
} | undefined;
|
|
43
43
|
virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
|
|
44
44
|
routeFilePrefix?: string | undefined;
|
package/dist/esm/webpack.js
CHANGED
|
@@ -1,11 +1,27 @@
|
|
|
1
1
|
import { configSchema } from "./core/config.js";
|
|
2
|
-
import { withHmrHotExpression } from "./core/hmr-hot-expression.js";
|
|
3
2
|
import { unpluginRouterCodeSplitterFactory } from "./core/router-code-splitter-plugin.js";
|
|
4
3
|
import { unpluginRouterGeneratorFactory } from "./core/router-generator-plugin.js";
|
|
5
4
|
import { unpluginRouterComposedFactory } from "./core/router-composed-plugin.js";
|
|
6
5
|
import { createWebpackPlugin } from "unplugin";
|
|
7
6
|
//#region src/webpack.ts
|
|
8
7
|
/**
|
|
8
|
+
* Webpack uses `module.hot` / `import.meta.webpackHot` HMR. Force
|
|
9
|
+
* `plugin.hmr.style = 'webpack'` so the router HMR adapter emits the correct
|
|
10
|
+
* accept/dispose shape regardless of user config.
|
|
11
|
+
*/
|
|
12
|
+
function withWebpackHmrStyle(options) {
|
|
13
|
+
return {
|
|
14
|
+
...options,
|
|
15
|
+
plugin: {
|
|
16
|
+
...options?.plugin,
|
|
17
|
+
hmr: {
|
|
18
|
+
...options?.plugin?.hmr,
|
|
19
|
+
style: "webpack"
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
};
|
|
23
|
+
}
|
|
24
|
+
/**
|
|
9
25
|
* @example
|
|
10
26
|
* ```ts
|
|
11
27
|
* export default {
|
|
@@ -24,7 +40,7 @@ var TanStackRouterGeneratorWebpack = /* @__PURE__ */ createWebpackPlugin(unplugi
|
|
|
24
40
|
* }
|
|
25
41
|
* ```
|
|
26
42
|
*/
|
|
27
|
-
var TanStackRouterCodeSplitterWebpack = /* @__PURE__ */ createWebpackPlugin((options, meta) => unpluginRouterCodeSplitterFactory(
|
|
43
|
+
var TanStackRouterCodeSplitterWebpack = /* @__PURE__ */ createWebpackPlugin((options, meta) => unpluginRouterCodeSplitterFactory(withWebpackHmrStyle(options), meta));
|
|
28
44
|
/**
|
|
29
45
|
* @example
|
|
30
46
|
* ```ts
|
|
@@ -34,7 +50,7 @@ var TanStackRouterCodeSplitterWebpack = /* @__PURE__ */ createWebpackPlugin((opt
|
|
|
34
50
|
* }
|
|
35
51
|
* ```
|
|
36
52
|
*/
|
|
37
|
-
var TanStackRouterWebpack = /* @__PURE__ */ createWebpackPlugin((options, meta) => unpluginRouterComposedFactory(
|
|
53
|
+
var TanStackRouterWebpack = /* @__PURE__ */ createWebpackPlugin((options, meta) => unpluginRouterComposedFactory(withWebpackHmrStyle(options), meta));
|
|
38
54
|
var tanstackRouter = TanStackRouterWebpack;
|
|
39
55
|
//#endregion
|
|
40
56
|
export { TanStackRouterCodeSplitterWebpack, TanStackRouterGeneratorWebpack, TanStackRouterWebpack, TanStackRouterWebpack as default, configSchema, tanstackRouter };
|
package/dist/esm/webpack.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"webpack.js","names":[],"sources":["../../src/webpack.ts"],"sourcesContent":["import { createWebpackPlugin } from 'unplugin'\n\nimport { configSchema } from './core/config'\nimport {
|
|
1
|
+
{"version":3,"file":"webpack.js","names":[],"sources":["../../src/webpack.ts"],"sourcesContent":["import { createWebpackPlugin } from 'unplugin'\n\nimport { configSchema } from './core/config'\nimport { unpluginRouterCodeSplitterFactory } from './core/router-code-splitter-plugin'\nimport { unpluginRouterGeneratorFactory } from './core/router-generator-plugin'\nimport { unpluginRouterComposedFactory } from './core/router-composed-plugin'\nimport type { CodeSplittingOptions, Config } from './core/config'\n\n/**\n * Webpack uses `module.hot` / `import.meta.webpackHot` HMR. Force\n * `plugin.hmr.style = 'webpack'` so the router HMR adapter emits the correct\n * accept/dispose shape regardless of user config.\n */\nfunction withWebpackHmrStyle(\n options: Partial<Config> | undefined,\n): Partial<Config> {\n return {\n ...options,\n plugin: {\n ...options?.plugin,\n hmr: {\n ...options?.plugin?.hmr,\n style: 'webpack',\n },\n },\n }\n}\n\n/**\n * @example\n * ```ts\n * export default {\n * // ...\n * plugins: [TanStackRouterGeneratorWebpack()],\n * }\n * ```\n */\nconst TanStackRouterGeneratorWebpack = /* #__PURE__ */ createWebpackPlugin(\n unpluginRouterGeneratorFactory,\n)\n\n/**\n * @example\n * ```ts\n * export default {\n * // ...\n * plugins: [TanStackRouterCodeSplitterWebpack()],\n * }\n * ```\n */\nconst TanStackRouterCodeSplitterWebpack = /* #__PURE__ */ createWebpackPlugin(\n (options, meta) =>\n unpluginRouterCodeSplitterFactory(\n withWebpackHmrStyle(options as Partial<Config> | undefined),\n meta,\n ),\n)\n\n/**\n * @example\n * ```ts\n * export default {\n * // ...\n * plugins: [tanstackRouter()],\n * }\n * ```\n */\nconst TanStackRouterWebpack = /* #__PURE__ */ createWebpackPlugin(\n (options, meta) =>\n unpluginRouterComposedFactory(\n withWebpackHmrStyle(options as Partial<Config> | undefined),\n meta,\n ),\n)\n\nconst tanstackRouter = TanStackRouterWebpack\nexport default TanStackRouterWebpack\nexport {\n configSchema,\n TanStackRouterWebpack,\n TanStackRouterGeneratorWebpack,\n TanStackRouterCodeSplitterWebpack,\n tanstackRouter,\n}\nexport type { Config, CodeSplittingOptions }\n"],"mappings":";;;;;;;;;;;AAaA,SAAS,oBACP,SACiB;AACjB,QAAO;EACL,GAAG;EACH,QAAQ;GACN,GAAG,SAAS;GACZ,KAAK;IACH,GAAG,SAAS,QAAQ;IACpB,OAAO;IACR;GACF;EACF;;;;;;;;;;;AAYH,IAAM,iCAAiD,oCACrD,+BACD;;;;;;;;;;AAWD,IAAM,oCAAoD,qCACvD,SAAS,SACR,kCACE,oBAAoB,QAAuC,EAC3D,KACD,CACJ;;;;;;;;;;AAWD,IAAM,wBAAwC,qCAC3C,SAAS,SACR,8BACE,oBAAoB,QAAuC,EAC3D,KACD,CACJ;AAED,IAAM,iBAAiB"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/router-plugin",
|
|
3
|
-
"version": "1.167.
|
|
3
|
+
"version": "1.167.23",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -100,8 +100,8 @@
|
|
|
100
100
|
"unplugin": "^2.1.2",
|
|
101
101
|
"zod": "^3.24.2",
|
|
102
102
|
"@tanstack/router-core": "1.168.15",
|
|
103
|
-
"@tanstack/router-generator": "1.166.
|
|
104
|
-
"@tanstack/router-utils": "1.161.
|
|
103
|
+
"@tanstack/router-generator": "1.166.33",
|
|
104
|
+
"@tanstack/router-utils": "1.161.7",
|
|
105
105
|
"@tanstack/virtual-file-routes": "1.161.7"
|
|
106
106
|
},
|
|
107
107
|
"devDependencies": {
|
|
@@ -112,11 +112,11 @@
|
|
|
112
112
|
"@types/node": ">=20"
|
|
113
113
|
},
|
|
114
114
|
"peerDependencies": {
|
|
115
|
-
"@rsbuild/core": ">=1.0.2",
|
|
115
|
+
"@rsbuild/core": ">=1.0.2 || ^2.0.0",
|
|
116
116
|
"vite": ">=5.0.0 || >=6.0.0 || >=7.0.0 || >=8.0.0",
|
|
117
117
|
"vite-plugin-solid": "^2.11.10 || ^3.0.0-0",
|
|
118
118
|
"webpack": ">=5.92.0",
|
|
119
|
-
"@tanstack/react-router": "^1.168.
|
|
119
|
+
"@tanstack/react-router": "^1.168.23"
|
|
120
120
|
},
|
|
121
121
|
"peerDependenciesMeta": {
|
|
122
122
|
"@rsbuild/core": {
|
|
@@ -8,7 +8,7 @@ import {
|
|
|
8
8
|
parseAst,
|
|
9
9
|
} from '@tanstack/router-utils'
|
|
10
10
|
import { tsrShared, tsrSplit } from '../constants'
|
|
11
|
-
import { createRouteHmrStatement } from '../
|
|
11
|
+
import { createRouteHmrStatement } from '../hmr'
|
|
12
12
|
import { getObjectPropertyKeyName } from '../utils'
|
|
13
13
|
import { createIdentifier } from './path-ids'
|
|
14
14
|
import { getFrameworkOptions } from './framework-options'
|
|
@@ -727,7 +727,9 @@ export function compileCodeSplitReferenceRoute(
|
|
|
727
727
|
programPath.pushContainer(
|
|
728
728
|
'body',
|
|
729
729
|
createRouteHmrStatement(stableRouteOptionKeys, {
|
|
730
|
-
|
|
730
|
+
hmrStyle: opts.hmrStyle ?? 'vite',
|
|
731
|
+
targetFramework: opts.targetFramework,
|
|
732
|
+
routeId: opts.hmrRouteId,
|
|
731
733
|
}),
|
|
732
734
|
)
|
|
733
735
|
modified = true
|
|
@@ -2,24 +2,23 @@ import { createReactRefreshIgnoredRouteExportsPlugin } from './react-refresh-ign
|
|
|
2
2
|
import { createReactRefreshRouteComponentsPlugin } from './react-refresh-route-components'
|
|
3
3
|
import { createReactStableHmrSplitRouteComponentsPlugin } from './react-stable-hmr-split-route-components'
|
|
4
4
|
import type { ReferenceRouteCompilerPlugin } from '../plugins'
|
|
5
|
-
import type { Config } from '../../config'
|
|
5
|
+
import type { Config, HmrStyle } from '../../config'
|
|
6
6
|
|
|
7
7
|
export function getReferenceRouteCompilerPlugins(opts: {
|
|
8
8
|
targetFramework: Config['target']
|
|
9
9
|
addHmr?: boolean
|
|
10
|
-
|
|
10
|
+
hmrStyle?: HmrStyle
|
|
11
11
|
}): Array<ReferenceRouteCompilerPlugin> | undefined {
|
|
12
12
|
switch (opts.targetFramework) {
|
|
13
13
|
case 'react': {
|
|
14
14
|
if (opts.addHmr) {
|
|
15
|
+
const hmrStyle = opts.hmrStyle ?? 'vite'
|
|
15
16
|
return [
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
17
|
+
...(hmrStyle === 'vite'
|
|
18
|
+
? [createReactRefreshIgnoredRouteExportsPlugin()]
|
|
19
|
+
: []),
|
|
19
20
|
createReactRefreshRouteComponentsPlugin(),
|
|
20
|
-
createReactStableHmrSplitRouteComponentsPlugin({
|
|
21
|
-
hotExpression: opts.hmrHotExpression,
|
|
22
|
-
}),
|
|
21
|
+
createReactStableHmrSplitRouteComponentsPlugin({ hmrStyle }),
|
|
23
22
|
]
|
|
24
23
|
}
|
|
25
24
|
return undefined
|