@octanejs/tanstack-start 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/LICENSE +22 -0
- package/README.md +52 -0
- package/THIRD_PARTY_NOTICES.md +11 -0
- package/package.json +149 -0
- package/src/client-only.d.ts +1 -0
- package/src/client-only.js +0 -0
- package/src/client-rpc.d.ts +1 -0
- package/src/client-rpc.js +1 -0
- package/src/client.d.ts +3 -0
- package/src/client.js +2 -0
- package/src/default-entry/client.js +12 -0
- package/src/default-entry/server.js +13 -0
- package/src/default-entry/start.js +1 -0
- package/src/default-entry-paths.d.ts +5 -0
- package/src/default-entry-paths.js +11 -0
- package/src/index.d.ts +11 -0
- package/src/index.js +22 -0
- package/src/internal/README.md +15 -0
- package/src/internal/router-generator/config.d.ts +255 -0
- package/src/internal/router-generator/config.js +134 -0
- package/src/internal/router-generator/filesystem/physical/getRouteNodes.d.ts +53 -0
- package/src/internal/router-generator/filesystem/physical/getRouteNodes.js +335 -0
- package/src/internal/router-generator/filesystem/physical/rootPathId.d.ts +1 -0
- package/src/internal/router-generator/filesystem/physical/rootPathId.js +4 -0
- package/src/internal/router-generator/filesystem/virtual/config.d.ts +3 -0
- package/src/internal/router-generator/filesystem/virtual/config.js +36 -0
- package/src/internal/router-generator/filesystem/virtual/getRouteNodes.d.ts +31 -0
- package/src/internal/router-generator/filesystem/virtual/getRouteNodes.js +272 -0
- package/src/internal/router-generator/filesystem/virtual/loadConfigFile.d.ts +1 -0
- package/src/internal/router-generator/filesystem/virtual/loadConfigFile.js +10 -0
- package/src/internal/router-generator/generator.d.ts +119 -0
- package/src/internal/router-generator/generator.js +1080 -0
- package/src/internal/router-generator/index.d.ts +40 -0
- package/src/internal/router-generator/index.js +49 -0
- package/src/internal/router-generator/logger.d.ts +8 -0
- package/src/internal/router-generator/logger.js +30 -0
- package/src/internal/router-generator/plugin/types.d.ts +37 -0
- package/src/internal/router-generator/template.d.ts +38 -0
- package/src/internal/router-generator/template.js +220 -0
- package/src/internal/router-generator/transform/transform.d.ts +8 -0
- package/src/internal/router-generator/transform/transform.js +385 -0
- package/src/internal/router-generator/transform/types.d.ts +34 -0
- package/src/internal/router-generator/types.d.ts +73 -0
- package/src/internal/router-generator/utils.d.ts +270 -0
- package/src/internal/router-generator/utils.js +864 -0
- package/src/internal/router-generator/validate-route-params.d.ts +13 -0
- package/src/internal/router-generator/validate-route-params.js +75 -0
- package/src/internal/router-plugin/context.d.ts +2 -0
- package/src/internal/router-plugin/context.js +2 -0
- package/src/internal/router-plugin/core/code-splitter/compilers.d.ts +69 -0
- package/src/internal/router-plugin/core/code-splitter/compilers.js +1042 -0
- package/src/internal/router-plugin/core/code-splitter/framework-options.d.ts +11 -0
- package/src/internal/router-plugin/core/code-splitter/framework-options.js +41 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/framework-plugins.d.ts +12 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/framework-plugins.js +35 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/octane-hmr-split-route-components.d.ts +5 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/octane-hmr-split-route-components.js +106 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/octane-split-route-components.d.ts +8 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/octane-split-route-components.js +85 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/react-refresh-ignored-route-exports.d.ts +2 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/react-refresh-ignored-route-exports.js +55 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/react-refresh-route-components.d.ts +2 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/react-refresh-route-components.js +50 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/react-stable-hmr-split-route-components.d.ts +5 -0
- package/src/internal/router-plugin/core/code-splitter/plugins/react-stable-hmr-split-route-components.js +54 -0
- package/src/internal/router-plugin/core/code-splitter/plugins.d.ts +62 -0
- package/src/internal/router-plugin/core/code-splitter/types.d.ts +9 -0
- package/src/internal/router-plugin/core/config.d.ts +294 -0
- package/src/internal/router-plugin/core/config.js +56 -0
- package/src/internal/router-plugin/core/constants.d.ts +12 -0
- package/src/internal/router-plugin/core/constants.js +13 -0
- package/src/internal/router-plugin/core/framework-plugin-order.d.ts +8 -0
- package/src/internal/router-plugin/core/framework-plugin-order.js +78 -0
- package/src/internal/router-plugin/core/hmr/handle-route-update.d.ts +1 -0
- package/src/internal/router-plugin/core/hmr/handle-route-update.js +126 -0
- package/src/internal/router-plugin/core/hmr/index.d.ts +5 -0
- package/src/internal/router-plugin/core/hmr/select-adapter.d.ts +17 -0
- package/src/internal/router-plugin/core/hmr/select-adapter.js +24 -0
- package/src/internal/router-plugin/core/hmr/vite-adapter.d.ts +18 -0
- package/src/internal/router-plugin/core/hmr/vite-adapter.js +73 -0
- package/src/internal/router-plugin/core/hmr/webpack-adapter.d.ts +22 -0
- package/src/internal/router-plugin/core/hmr/webpack-adapter.js +78 -0
- package/src/internal/router-plugin/core/router-code-splitter-plugin.d.ts +10 -0
- package/src/internal/router-plugin/core/router-code-splitter-plugin.js +244 -0
- package/src/internal/router-plugin/core/router-composed-plugin.d.ts +5 -0
- package/src/internal/router-plugin/core/router-composed-plugin.js +62 -0
- package/src/internal/router-plugin/core/router-generator-plugin.d.ts +10 -0
- package/src/internal/router-plugin/core/router-generator-plugin.js +125 -0
- package/src/internal/router-plugin/core/router-hmr-plugin.d.ts +13 -0
- package/src/internal/router-plugin/core/router-hmr-plugin.js +101 -0
- package/src/internal/router-plugin/core/router-plugin-context.d.ts +5 -0
- package/src/internal/router-plugin/core/router-plugin-context.js +6 -0
- package/src/internal/router-plugin/core/utils.d.ts +17 -0
- package/src/internal/router-plugin/core/utils.js +47 -0
- package/src/internal/router-plugin/esbuild.d.ts +197 -0
- package/src/internal/router-plugin/esbuild.js +58 -0
- package/src/internal/router-plugin/index.d.ts +19 -0
- package/src/internal/router-plugin/index.js +17 -0
- package/src/internal/router-plugin/rspack.d.ts +61 -0
- package/src/internal/router-plugin/rspack.js +92 -0
- package/src/internal/router-plugin/vite.d.ts +201 -0
- package/src/internal/router-plugin/vite.js +62 -0
- package/src/internal/router-plugin/webpack.d.ts +50 -0
- package/src/internal/router-plugin/webpack.js +77 -0
- package/src/internal/start-plugin-core/build-sitemap.d.ts +34 -0
- package/src/internal/start-plugin-core/build-sitemap.js +125 -0
- package/src/internal/start-plugin-core/config-context.d.ts +30 -0
- package/src/internal/start-plugin-core/config-context.js +89 -0
- package/src/internal/start-plugin-core/constants.d.ts +20 -0
- package/src/internal/start-plugin-core/constants.js +24 -0
- package/src/internal/start-plugin-core/debug.d.ts +1 -0
- package/src/internal/start-plugin-core/hydrate-when-transform.d.ts +5 -0
- package/src/internal/start-plugin-core/hydrate-when-transform.js +661 -0
- package/src/internal/start-plugin-core/hydration-constants.d.ts +1 -0
- package/src/internal/start-plugin-core/hydration-constants.js +4 -0
- package/src/internal/start-plugin-core/import-protection/adapterUtils.d.ts +40 -0
- package/src/internal/start-plugin-core/import-protection/adapterUtils.js +42 -0
- package/src/internal/start-plugin-core/import-protection/analysis.d.ts +63 -0
- package/src/internal/start-plugin-core/import-protection/analysis.js +533 -0
- package/src/internal/start-plugin-core/import-protection/constants.d.ts +11 -0
- package/src/internal/start-plugin-core/import-protection/constants.js +39 -0
- package/src/internal/start-plugin-core/import-protection/defaults.d.ts +19 -0
- package/src/internal/start-plugin-core/import-protection/defaults.js +34 -0
- package/src/internal/start-plugin-core/import-protection/extensionlessAbsoluteIdResolver.d.ts +22 -0
- package/src/internal/start-plugin-core/import-protection/extensionlessAbsoluteIdResolver.js +94 -0
- package/src/internal/start-plugin-core/import-protection/matchers.d.ts +18 -0
- package/src/internal/start-plugin-core/import-protection/matchers.js +39 -0
- package/src/internal/start-plugin-core/import-protection/rewrite.d.ts +29 -0
- package/src/internal/start-plugin-core/import-protection/rewrite.js +184 -0
- package/src/internal/start-plugin-core/import-protection/sourceLocation.d.ts +170 -0
- package/src/internal/start-plugin-core/import-protection/sourceLocation.js +376 -0
- package/src/internal/start-plugin-core/import-protection/trace.d.ts +89 -0
- package/src/internal/start-plugin-core/import-protection/trace.js +186 -0
- package/src/internal/start-plugin-core/import-protection/utils.d.ts +78 -0
- package/src/internal/start-plugin-core/import-protection/utils.js +171 -0
- package/src/internal/start-plugin-core/import-protection/virtualModules.d.ts +38 -0
- package/src/internal/start-plugin-core/import-protection/virtualModules.js +241 -0
- package/src/internal/start-plugin-core/index.d.ts +8 -0
- package/src/internal/start-plugin-core/index.js +2 -0
- package/src/internal/start-plugin-core/planning.d.ts +44 -0
- package/src/internal/start-plugin-core/planning.js +98 -0
- package/src/internal/start-plugin-core/post-build.d.ts +12 -0
- package/src/internal/start-plugin-core/post-build.js +40 -0
- package/src/internal/start-plugin-core/prerender.d.ts +17 -0
- package/src/internal/start-plugin-core/prerender.js +172 -0
- package/src/internal/start-plugin-core/queue.d.ts +37 -0
- package/src/internal/start-plugin-core/queue.js +118 -0
- package/src/internal/start-plugin-core/resolve-entries.d.ts +10 -0
- package/src/internal/start-plugin-core/resolve-entries.js +32 -0
- package/src/internal/start-plugin-core/schema.d.ts +1799 -0
- package/src/internal/start-plugin-core/schema.js +252 -0
- package/src/internal/start-plugin-core/serialization-adapters-module.d.ts +18 -0
- package/src/internal/start-plugin-core/serialization-adapters-module.js +37 -0
- package/src/internal/start-plugin-core/start-compiler/compiler.d.ts +181 -0
- package/src/internal/start-plugin-core/start-compiler/compiler.js +1078 -0
- package/src/internal/start-plugin-core/start-compiler/config.d.ts +20 -0
- package/src/internal/start-plugin-core/start-compiler/config.js +84 -0
- package/src/internal/start-plugin-core/start-compiler/handleClientOnlyJSX.d.ts +24 -0
- package/src/internal/start-plugin-core/start-compiler/handleClientOnlyJSX.js +25 -0
- package/src/internal/start-plugin-core/start-compiler/handleCreateIsomorphicFn.d.ts +11 -0
- package/src/internal/start-plugin-core/start-compiler/handleCreateIsomorphicFn.js +24 -0
- package/src/internal/start-plugin-core/start-compiler/handleCreateMiddleware.d.ts +11 -0
- package/src/internal/start-plugin-core/start-compiler/handleCreateMiddleware.js +35 -0
- package/src/internal/start-plugin-core/start-compiler/handleCreateServerFn.d.ts +22 -0
- package/src/internal/start-plugin-core/start-compiler/handleCreateServerFn.js +292 -0
- package/src/internal/start-plugin-core/start-compiler/handleEnvOnly.d.ts +14 -0
- package/src/internal/start-plugin-core/start-compiler/handleEnvOnly.js +41 -0
- package/src/internal/start-plugin-core/start-compiler/host.d.ts +44 -0
- package/src/internal/start-plugin-core/start-compiler/host.js +75 -0
- package/src/internal/start-plugin-core/start-compiler/server-fn-resolver-module.d.ts +10 -0
- package/src/internal/start-plugin-core/start-compiler/server-fn-resolver-module.js +87 -0
- package/src/internal/start-plugin-core/start-compiler/types.d.ts +119 -0
- package/src/internal/start-plugin-core/start-compiler/utils.d.ts +27 -0
- package/src/internal/start-plugin-core/start-compiler/utils.js +36 -0
- package/src/internal/start-plugin-core/start-manifest-plugin/inlineCss.d.ts +16 -0
- package/src/internal/start-plugin-core/start-manifest-plugin/inlineCss.js +131 -0
- package/src/internal/start-plugin-core/start-manifest-plugin/manifestBuilder.d.ts +64 -0
- package/src/internal/start-plugin-core/start-manifest-plugin/manifestBuilder.js +441 -0
- package/src/internal/start-plugin-core/start-router-plugin/constants.d.ts +1 -0
- package/src/internal/start-plugin-core/start-router-plugin/constants.js +4 -0
- package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/compose-generator-plugins.d.ts +6 -0
- package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/compose-generator-plugins.js +6 -0
- package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/prerender-routes-plugin.d.ts +6 -0
- package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/prerender-routes-plugin.js +27 -0
- package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/routes-manifest-plugin.d.ts +6 -0
- package/src/internal/start-plugin-core/start-router-plugin/generator-plugins/routes-manifest-plugin.js +34 -0
- package/src/internal/start-plugin-core/start-router-plugin/pruneServerOnlySubtrees.d.ts +11 -0
- package/src/internal/start-plugin-core/start-router-plugin/pruneServerOnlySubtrees.js +42 -0
- package/src/internal/start-plugin-core/start-router-plugin/route-tree-footer.d.ts +6 -0
- package/src/internal/start-plugin-core/start-router-plugin/route-tree-footer.js +59 -0
- package/src/internal/start-plugin-core/types.d.ts +135 -0
- package/src/internal/start-plugin-core/types.js +4 -0
- package/src/internal/start-plugin-core/utils.d.ts +13 -0
- package/src/internal/start-plugin-core/utils.js +42 -0
- package/src/internal/start-plugin-core/vite/createVirtualModule.d.ts +15 -0
- package/src/internal/start-plugin-core/vite/createVirtualModule.js +27 -0
- package/src/internal/start-plugin-core/vite/dev-server-plugin/dev-styles.d.ts +26 -0
- package/src/internal/start-plugin-core/vite/dev-server-plugin/dev-styles.js +165 -0
- package/src/internal/start-plugin-core/vite/dev-server-plugin/plugin.d.ts +11 -0
- package/src/internal/start-plugin-core/vite/dev-server-plugin/plugin.js +170 -0
- package/src/internal/start-plugin-core/vite/import-protection-plugin/plugin.d.ts +4 -0
- package/src/internal/start-plugin-core/vite/import-protection-plugin/plugin.js +1553 -0
- package/src/internal/start-plugin-core/vite/import-protection-plugin/types.d.ts +103 -0
- package/src/internal/start-plugin-core/vite/import-protection-plugin/virtualModules.d.ts +40 -0
- package/src/internal/start-plugin-core/vite/import-protection-plugin/virtualModules.js +68 -0
- package/src/internal/start-plugin-core/vite/index.d.ts +13 -0
- package/src/internal/start-plugin-core/vite/index.js +4 -0
- package/src/internal/start-plugin-core/vite/load-env-plugin/plugin.d.ts +2 -0
- package/src/internal/start-plugin-core/vite/load-env-plugin/plugin.js +13 -0
- package/src/internal/start-plugin-core/vite/output-directory.d.ts +7 -0
- package/src/internal/start-plugin-core/vite/output-directory.js +18 -0
- package/src/internal/start-plugin-core/vite/planning.d.ts +112 -0
- package/src/internal/start-plugin-core/vite/planning.js +152 -0
- package/src/internal/start-plugin-core/vite/plugin.d.ts +7 -0
- package/src/internal/start-plugin-core/vite/plugin.js +208 -0
- package/src/internal/start-plugin-core/vite/plugins.d.ts +17 -0
- package/src/internal/start-plugin-core/vite/plugins.js +72 -0
- package/src/internal/start-plugin-core/vite/post-server-build.d.ts +9 -0
- package/src/internal/start-plugin-core/vite/post-server-build.js +22 -0
- package/src/internal/start-plugin-core/vite/prerender.d.ts +9 -0
- package/src/internal/start-plugin-core/vite/prerender.js +52 -0
- package/src/internal/start-plugin-core/vite/preview-server-plugin/plugin.d.ts +2 -0
- package/src/internal/start-plugin-core/vite/preview-server-plugin/plugin.js +54 -0
- package/src/internal/start-plugin-core/vite/schema.d.ts +2423 -0
- package/src/internal/start-plugin-core/vite/schema.js +17 -0
- package/src/internal/start-plugin-core/vite/serialization-adapters-plugin.d.ts +5 -0
- package/src/internal/start-plugin-core/vite/serialization-adapters-plugin.js +63 -0
- package/src/internal/start-plugin-core/vite/start-compiler-plugin/hot-update.d.ts +5 -0
- package/src/internal/start-plugin-core/vite/start-compiler-plugin/hot-update.js +14 -0
- package/src/internal/start-plugin-core/vite/start-compiler-plugin/module-specifier.d.ts +5 -0
- package/src/internal/start-plugin-core/vite/start-compiler-plugin/module-specifier.js +25 -0
- package/src/internal/start-plugin-core/vite/start-compiler-plugin/plugin.d.ts +29 -0
- package/src/internal/start-plugin-core/vite/start-compiler-plugin/plugin.js +380 -0
- package/src/internal/start-plugin-core/vite/start-manifest-plugin/normalized-client-build.d.ts +11 -0
- package/src/internal/start-plugin-core/vite/start-manifest-plugin/normalized-client-build.js +114 -0
- package/src/internal/start-plugin-core/vite/start-manifest-plugin/plugin.d.ts +3 -0
- package/src/internal/start-plugin-core/vite/start-manifest-plugin/plugin.js +103 -0
- package/src/internal/start-plugin-core/vite/start-router-plugin/plugin.d.ts +9 -0
- package/src/internal/start-plugin-core/vite/start-router-plugin/plugin.js +143 -0
- package/src/internal/start-plugin-core/vite/types.d.ts +17 -0
- package/src/package-names.js +10 -0
- package/src/plugin-vite.d.ts +23 -0
- package/src/plugin-vite.js +62 -0
- package/src/runtime/client/StartClient.d.ts +11 -0
- package/src/runtime/client/StartClient.js +16 -0
- package/src/runtime/client/hydrateStart.d.ts +4 -0
- package/src/runtime/client/hydrateStart.js +30 -0
- package/src/runtime/server/StartServer.d.ts +10 -0
- package/src/runtime/server/StartServer.js +6 -0
- package/src/runtime/server/defaultRenderHandler.d.ts +3 -0
- package/src/runtime/server/defaultRenderHandler.js +11 -0
- package/src/runtime/server/defaultStreamHandler.d.ts +3 -0
- package/src/runtime/server/defaultStreamHandler.js +13 -0
- package/src/server-entry.d.ts +11 -0
- package/src/server-entry.js +13 -0
- package/src/server-only.d.ts +1 -0
- package/src/server-only.js +0 -0
- package/src/server-rpc.d.ts +1 -0
- package/src/server-rpc.js +1 -0
- package/src/server.d.ts +6 -0
- package/src/server.js +4 -0
- package/src/ssr-rpc.d.ts +1 -0
- package/src/ssr-rpc.js +1 -0
- package/src/use-server-fn.d.ts +3 -0
- package/src/use-server-fn.js +18 -0
- package/src/validate-options.js +7 -0
|
@@ -0,0 +1,101 @@
|
|
|
1
|
+
import { getConfig } from './config.js';
|
|
2
|
+
import { createRouteHmrStatement } from './hmr/select-adapter.js';
|
|
3
|
+
import { debug, normalizePath, routeFactoryCallCodeFilter } from './utils.js';
|
|
4
|
+
import { compileCodeSplitReferenceRoute } from './code-splitter/compilers.js';
|
|
5
|
+
import { getReferenceRouteCompilerPlugins } from './code-splitter/plugins/framework-plugins.js';
|
|
6
|
+
import { validateFrameworkPluginOrder } from './framework-plugin-order.js';
|
|
7
|
+
import { generateFromAst, logDiff, parseAst } from '@tanstack/router-utils';
|
|
8
|
+
//#region src/core/router-hmr-plugin.ts
|
|
9
|
+
/**
|
|
10
|
+
* This plugin adds HMR support for file routes.
|
|
11
|
+
* It is only added to the composed plugin in dev when autoCodeSplitting is disabled, since the code splitting plugin
|
|
12
|
+
* handles HMR for code-split routes itself.
|
|
13
|
+
*/
|
|
14
|
+
function createRouterHmrPlugin(options = {}, routerPluginContext) {
|
|
15
|
+
let ROOT = process.cwd();
|
|
16
|
+
const resolveUserConfig = () => {
|
|
17
|
+
return getConfig(typeof options === 'function' ? options() : options, ROOT);
|
|
18
|
+
};
|
|
19
|
+
let userConfig = resolveUserConfig();
|
|
20
|
+
return {
|
|
21
|
+
name: 'tanstack-router:hmr',
|
|
22
|
+
enforce: 'pre',
|
|
23
|
+
transform: {
|
|
24
|
+
filter: {
|
|
25
|
+
id: [/\.(m|c)?(j|t)sx?$/, /\.tsrx(?:$|\?)/],
|
|
26
|
+
code: { include: routeFactoryCallCodeFilter },
|
|
27
|
+
},
|
|
28
|
+
handler(code, id) {
|
|
29
|
+
const normalizedId = normalizePath(id);
|
|
30
|
+
const routeEntry = routerPluginContext.routesByFile.get(normalizedId);
|
|
31
|
+
if (!routeEntry) return null;
|
|
32
|
+
if (debug) console.info('Adding HMR handling to route ', normalizedId);
|
|
33
|
+
const hmrStyle = userConfig.plugin?.hmr?.style ?? 'vite';
|
|
34
|
+
if (userConfig.target === 'react') {
|
|
35
|
+
const compilerPlugins = getReferenceRouteCompilerPlugins({
|
|
36
|
+
targetFramework: 'react',
|
|
37
|
+
addHmr: true,
|
|
38
|
+
hmrStyle,
|
|
39
|
+
});
|
|
40
|
+
const compiled = compileCodeSplitReferenceRoute({
|
|
41
|
+
code,
|
|
42
|
+
filename: normalizedId,
|
|
43
|
+
id: normalizedId,
|
|
44
|
+
addHmr: true,
|
|
45
|
+
hmrStyle,
|
|
46
|
+
hmrRouteId: routeEntry.routeId,
|
|
47
|
+
codeSplitGroupings: [],
|
|
48
|
+
targetFramework: 'react',
|
|
49
|
+
compilerPlugins,
|
|
50
|
+
});
|
|
51
|
+
if (compiled) {
|
|
52
|
+
if (debug) {
|
|
53
|
+
logDiff(code, compiled.code);
|
|
54
|
+
console.log('Output:\n', compiled.code + '\n\n');
|
|
55
|
+
}
|
|
56
|
+
return compiled;
|
|
57
|
+
}
|
|
58
|
+
}
|
|
59
|
+
const ast = parseAst({
|
|
60
|
+
code,
|
|
61
|
+
filename: normalizedId,
|
|
62
|
+
});
|
|
63
|
+
ast.program.body.push(
|
|
64
|
+
...createRouteHmrStatement([], {
|
|
65
|
+
hmrStyle,
|
|
66
|
+
targetFramework: userConfig.target,
|
|
67
|
+
routeId: routeEntry.routeId,
|
|
68
|
+
}),
|
|
69
|
+
);
|
|
70
|
+
const result = generateFromAst(ast, {
|
|
71
|
+
sourceMaps: true,
|
|
72
|
+
filename: normalizedId,
|
|
73
|
+
sourceFileName: normalizedId,
|
|
74
|
+
});
|
|
75
|
+
if (debug) {
|
|
76
|
+
logDiff(code, result.code);
|
|
77
|
+
console.log('Output:\n', result.code + '\n\n');
|
|
78
|
+
}
|
|
79
|
+
return result;
|
|
80
|
+
},
|
|
81
|
+
},
|
|
82
|
+
vite: {
|
|
83
|
+
configResolved(config) {
|
|
84
|
+
ROOT = config.root;
|
|
85
|
+
userConfig = resolveUserConfig();
|
|
86
|
+
validateFrameworkPluginOrder({
|
|
87
|
+
framework: userConfig.target,
|
|
88
|
+
plugins: config.plugins,
|
|
89
|
+
routerPluginName: 'tanstack-router:hmr',
|
|
90
|
+
});
|
|
91
|
+
},
|
|
92
|
+
applyToEnvironment(environment) {
|
|
93
|
+
if (userConfig.plugin?.vite?.environmentName)
|
|
94
|
+
return userConfig.plugin.vite.environmentName === environment.name;
|
|
95
|
+
return true;
|
|
96
|
+
},
|
|
97
|
+
},
|
|
98
|
+
};
|
|
99
|
+
}
|
|
100
|
+
//#endregion
|
|
101
|
+
export { createRouterHmrPlugin };
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { default as babel } from '@babel/core';
|
|
2
|
+
import * as t from '@babel/types';
|
|
3
|
+
export declare const debug: boolean | '' | undefined;
|
|
4
|
+
/**
|
|
5
|
+
* Normalizes a file path by converting Windows backslashes to forward slashes.
|
|
6
|
+
* This ensures consistent path handling across different bundlers and operating systems.
|
|
7
|
+
*
|
|
8
|
+
* The route generator stores paths with forward slashes, but rspack/webpack on Windows
|
|
9
|
+
* pass native paths with backslashes to transform handlers.
|
|
10
|
+
*/
|
|
11
|
+
export declare function normalizePath(path: string): string;
|
|
12
|
+
export declare const routeFactoryCallCodeFilter: RegExp[];
|
|
13
|
+
export declare function getObjectPropertyKeyName(prop: t.ObjectProperty): string | undefined;
|
|
14
|
+
export declare function getUniqueProgramIdentifier(
|
|
15
|
+
programPath: babel.NodePath<t.Program>,
|
|
16
|
+
baseName: string,
|
|
17
|
+
): t.Identifier;
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
import * as t from '@babel/types';
|
|
2
|
+
//#region src/core/utils.ts
|
|
3
|
+
var debug =
|
|
4
|
+
process.env.TSR_VITE_DEBUG && ['true', 'router-plugin'].includes(process.env.TSR_VITE_DEBUG);
|
|
5
|
+
/**
|
|
6
|
+
* Normalizes a file path by converting Windows backslashes to forward slashes.
|
|
7
|
+
* This ensures consistent path handling across different bundlers and operating systems.
|
|
8
|
+
*
|
|
9
|
+
* The route generator stores paths with forward slashes, but rspack/webpack on Windows
|
|
10
|
+
* pass native paths with backslashes to transform handlers.
|
|
11
|
+
*/
|
|
12
|
+
function normalizePath(path) {
|
|
13
|
+
return path.replace(/\\/g, '/');
|
|
14
|
+
}
|
|
15
|
+
var routeFactoryCallCodeFilter = [
|
|
16
|
+
/\bcreateFileRoute\s*\(/,
|
|
17
|
+
/\bcreateRootRoute\s*\(/,
|
|
18
|
+
/\bcreateRootRouteWithContext\s*(?:<|\()/,
|
|
19
|
+
];
|
|
20
|
+
function getObjectPropertyKeyName(prop) {
|
|
21
|
+
if (prop.computed) return;
|
|
22
|
+
if (t.isIdentifier(prop.key)) return prop.key.name;
|
|
23
|
+
if (t.isStringLiteral(prop.key)) return prop.key.value;
|
|
24
|
+
}
|
|
25
|
+
function getUniqueProgramIdentifier(programPath, baseName) {
|
|
26
|
+
let name = baseName;
|
|
27
|
+
let suffix = 2;
|
|
28
|
+
const programScope = programPath.scope.getProgramParent();
|
|
29
|
+
while (
|
|
30
|
+
programScope.hasBinding(name) ||
|
|
31
|
+
programScope.hasGlobal(name) ||
|
|
32
|
+
programScope.hasReference(name)
|
|
33
|
+
) {
|
|
34
|
+
name = `${baseName}${suffix}`;
|
|
35
|
+
suffix++;
|
|
36
|
+
}
|
|
37
|
+
programScope.references[name] = true;
|
|
38
|
+
return t.identifier(name);
|
|
39
|
+
}
|
|
40
|
+
//#endregion
|
|
41
|
+
export {
|
|
42
|
+
debug,
|
|
43
|
+
getObjectPropertyKeyName,
|
|
44
|
+
getUniqueProgramIdentifier,
|
|
45
|
+
normalizePath,
|
|
46
|
+
routeFactoryCallCodeFilter,
|
|
47
|
+
};
|
|
@@ -0,0 +1,197 @@
|
|
|
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;
|
|
4
|
+
/**
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* export default {
|
|
8
|
+
* plugins: [TanStackRouterGeneratorEsbuild()],
|
|
9
|
+
* // ...
|
|
10
|
+
* }
|
|
11
|
+
* ```
|
|
12
|
+
*/
|
|
13
|
+
declare const TanStackRouterGeneratorEsbuild: (
|
|
14
|
+
options?: RouterPluginOptions,
|
|
15
|
+
routerPluginContext?: RouterPluginContext,
|
|
16
|
+
) => import('unplugin').EsbuildPlugin;
|
|
17
|
+
/**
|
|
18
|
+
* @example
|
|
19
|
+
* ```ts
|
|
20
|
+
* export default {
|
|
21
|
+
* plugins: [TanStackRouterCodeSplitterEsbuild()],
|
|
22
|
+
* // ...
|
|
23
|
+
* }
|
|
24
|
+
* ```
|
|
25
|
+
*/
|
|
26
|
+
declare const TanStackRouterCodeSplitterEsbuild: (
|
|
27
|
+
options?: RouterPluginOptions,
|
|
28
|
+
routerPluginContext?: RouterPluginContext,
|
|
29
|
+
) => import('unplugin').EsbuildPlugin;
|
|
30
|
+
/**
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* export default {
|
|
34
|
+
* plugins: [tanstackRouter()],
|
|
35
|
+
* // ...
|
|
36
|
+
* }
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
39
|
+
declare const TanStackRouterEsbuild: (
|
|
40
|
+
options?:
|
|
41
|
+
| Partial<
|
|
42
|
+
| {
|
|
43
|
+
target: 'vue' | 'react' | 'solid' | 'octane';
|
|
44
|
+
routeFileIgnorePrefix: string;
|
|
45
|
+
routesDirectory: string;
|
|
46
|
+
quoteStyle: 'single' | 'double';
|
|
47
|
+
semicolons: boolean;
|
|
48
|
+
disableLogging: boolean;
|
|
49
|
+
routeTreeFileHeader: string[];
|
|
50
|
+
indexToken:
|
|
51
|
+
| string
|
|
52
|
+
| RegExp
|
|
53
|
+
| {
|
|
54
|
+
regex: string;
|
|
55
|
+
flags?: string | undefined;
|
|
56
|
+
};
|
|
57
|
+
routeToken:
|
|
58
|
+
| string
|
|
59
|
+
| RegExp
|
|
60
|
+
| {
|
|
61
|
+
regex: string;
|
|
62
|
+
flags?: string | undefined;
|
|
63
|
+
};
|
|
64
|
+
generatedRouteTree: string;
|
|
65
|
+
disableTypes: boolean;
|
|
66
|
+
addExtensions: string | boolean;
|
|
67
|
+
enableRouteTreeFormatting: boolean;
|
|
68
|
+
tmpDir: string;
|
|
69
|
+
importRoutesUsingAbsolutePaths: boolean;
|
|
70
|
+
virtualRouteConfig?:
|
|
71
|
+
| string
|
|
72
|
+
| import('@tanstack/virtual-file-routes').VirtualRootRoute
|
|
73
|
+
| undefined;
|
|
74
|
+
routeFilePrefix?: string | undefined;
|
|
75
|
+
routeFileIgnorePattern?: string | undefined;
|
|
76
|
+
pathParamsAllowedCharacters?:
|
|
77
|
+
| (':' | '$' | ';' | '@' | '&' | '=' | '+' | ',')[]
|
|
78
|
+
| undefined;
|
|
79
|
+
routeTreeFileFooter?: string[] | (() => Array<string>) | undefined;
|
|
80
|
+
autoCodeSplitting?: boolean | undefined;
|
|
81
|
+
customScaffolding?:
|
|
82
|
+
| {
|
|
83
|
+
routeTemplate?: string | undefined;
|
|
84
|
+
lazyRouteTemplate?: string | undefined;
|
|
85
|
+
}
|
|
86
|
+
| undefined;
|
|
87
|
+
experimental?:
|
|
88
|
+
| {
|
|
89
|
+
enableCodeSplitting?: boolean | undefined;
|
|
90
|
+
}
|
|
91
|
+
| undefined;
|
|
92
|
+
plugins?: import('#tanstack-start/router-generator').GeneratorPlugin[] | undefined;
|
|
93
|
+
enableRouteGeneration?: boolean | undefined;
|
|
94
|
+
codeSplittingOptions?: CodeSplittingOptions | undefined;
|
|
95
|
+
plugin?:
|
|
96
|
+
| {
|
|
97
|
+
hmr?:
|
|
98
|
+
| {
|
|
99
|
+
style?: 'vite' | 'webpack' | undefined;
|
|
100
|
+
}
|
|
101
|
+
| undefined;
|
|
102
|
+
vite?:
|
|
103
|
+
| {
|
|
104
|
+
environmentName?: string | undefined;
|
|
105
|
+
}
|
|
106
|
+
| undefined;
|
|
107
|
+
}
|
|
108
|
+
| undefined;
|
|
109
|
+
}
|
|
110
|
+
| (() => Config)
|
|
111
|
+
>
|
|
112
|
+
| undefined,
|
|
113
|
+
) => import('unplugin').EsbuildPlugin;
|
|
114
|
+
declare const tanstackRouter: (
|
|
115
|
+
options?:
|
|
116
|
+
| Partial<
|
|
117
|
+
| {
|
|
118
|
+
target: 'vue' | 'react' | 'solid' | 'octane';
|
|
119
|
+
routeFileIgnorePrefix: string;
|
|
120
|
+
routesDirectory: string;
|
|
121
|
+
quoteStyle: 'single' | 'double';
|
|
122
|
+
semicolons: boolean;
|
|
123
|
+
disableLogging: boolean;
|
|
124
|
+
routeTreeFileHeader: string[];
|
|
125
|
+
indexToken:
|
|
126
|
+
| string
|
|
127
|
+
| RegExp
|
|
128
|
+
| {
|
|
129
|
+
regex: string;
|
|
130
|
+
flags?: string | undefined;
|
|
131
|
+
};
|
|
132
|
+
routeToken:
|
|
133
|
+
| string
|
|
134
|
+
| RegExp
|
|
135
|
+
| {
|
|
136
|
+
regex: string;
|
|
137
|
+
flags?: string | undefined;
|
|
138
|
+
};
|
|
139
|
+
generatedRouteTree: string;
|
|
140
|
+
disableTypes: boolean;
|
|
141
|
+
addExtensions: string | boolean;
|
|
142
|
+
enableRouteTreeFormatting: boolean;
|
|
143
|
+
tmpDir: string;
|
|
144
|
+
importRoutesUsingAbsolutePaths: boolean;
|
|
145
|
+
virtualRouteConfig?:
|
|
146
|
+
| string
|
|
147
|
+
| import('@tanstack/virtual-file-routes').VirtualRootRoute
|
|
148
|
+
| undefined;
|
|
149
|
+
routeFilePrefix?: string | undefined;
|
|
150
|
+
routeFileIgnorePattern?: string | undefined;
|
|
151
|
+
pathParamsAllowedCharacters?:
|
|
152
|
+
| (':' | '$' | ';' | '@' | '&' | '=' | '+' | ',')[]
|
|
153
|
+
| undefined;
|
|
154
|
+
routeTreeFileFooter?: string[] | (() => Array<string>) | undefined;
|
|
155
|
+
autoCodeSplitting?: boolean | undefined;
|
|
156
|
+
customScaffolding?:
|
|
157
|
+
| {
|
|
158
|
+
routeTemplate?: string | undefined;
|
|
159
|
+
lazyRouteTemplate?: string | undefined;
|
|
160
|
+
}
|
|
161
|
+
| undefined;
|
|
162
|
+
experimental?:
|
|
163
|
+
| {
|
|
164
|
+
enableCodeSplitting?: boolean | undefined;
|
|
165
|
+
}
|
|
166
|
+
| undefined;
|
|
167
|
+
plugins?: import('#tanstack-start/router-generator').GeneratorPlugin[] | undefined;
|
|
168
|
+
enableRouteGeneration?: boolean | undefined;
|
|
169
|
+
codeSplittingOptions?: CodeSplittingOptions | undefined;
|
|
170
|
+
plugin?:
|
|
171
|
+
| {
|
|
172
|
+
hmr?:
|
|
173
|
+
| {
|
|
174
|
+
style?: 'vite' | 'webpack' | undefined;
|
|
175
|
+
}
|
|
176
|
+
| undefined;
|
|
177
|
+
vite?:
|
|
178
|
+
| {
|
|
179
|
+
environmentName?: string | undefined;
|
|
180
|
+
}
|
|
181
|
+
| undefined;
|
|
182
|
+
}
|
|
183
|
+
| undefined;
|
|
184
|
+
}
|
|
185
|
+
| (() => Config)
|
|
186
|
+
>
|
|
187
|
+
| undefined,
|
|
188
|
+
) => import('unplugin').EsbuildPlugin;
|
|
189
|
+
export default TanStackRouterEsbuild;
|
|
190
|
+
export {
|
|
191
|
+
configSchema,
|
|
192
|
+
TanStackRouterGeneratorEsbuild,
|
|
193
|
+
TanStackRouterCodeSplitterEsbuild,
|
|
194
|
+
TanStackRouterEsbuild,
|
|
195
|
+
tanstackRouter,
|
|
196
|
+
};
|
|
197
|
+
export type { Config, CodeSplittingOptions, RouterPluginContext };
|
|
@@ -0,0 +1,58 @@
|
|
|
1
|
+
import { configSchema } from './core/config.js';
|
|
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';
|
|
5
|
+
import { unpluginRouterComposedFactory } from './core/router-composed-plugin.js';
|
|
6
|
+
import { createEsbuildPlugin } from 'unplugin';
|
|
7
|
+
//#region src/esbuild.ts
|
|
8
|
+
var defaultRouterPluginContext = createRouterPluginContext();
|
|
9
|
+
/**
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* export default {
|
|
13
|
+
* plugins: [TanStackRouterGeneratorEsbuild()],
|
|
14
|
+
* // ...
|
|
15
|
+
* }
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
18
|
+
var TanStackRouterGeneratorEsbuild = (options, routerPluginContext) => {
|
|
19
|
+
const pluginContext = routerPluginContext ?? defaultRouterPluginContext;
|
|
20
|
+
return createEsbuildPlugin((pluginOptions) =>
|
|
21
|
+
createRouterGeneratorPlugin(pluginOptions, pluginContext),
|
|
22
|
+
)(options);
|
|
23
|
+
};
|
|
24
|
+
/**
|
|
25
|
+
* @example
|
|
26
|
+
* ```ts
|
|
27
|
+
* export default {
|
|
28
|
+
* plugins: [TanStackRouterCodeSplitterEsbuild()],
|
|
29
|
+
* // ...
|
|
30
|
+
* }
|
|
31
|
+
* ```
|
|
32
|
+
*/
|
|
33
|
+
var TanStackRouterCodeSplitterEsbuild = (options, routerPluginContext) => {
|
|
34
|
+
const pluginContext = routerPluginContext ?? defaultRouterPluginContext;
|
|
35
|
+
return createEsbuildPlugin((pluginOptions) =>
|
|
36
|
+
createRouterCodeSplitterPlugin(pluginOptions, pluginContext),
|
|
37
|
+
)(options);
|
|
38
|
+
};
|
|
39
|
+
/**
|
|
40
|
+
* @example
|
|
41
|
+
* ```ts
|
|
42
|
+
* export default {
|
|
43
|
+
* plugins: [tanstackRouter()],
|
|
44
|
+
* // ...
|
|
45
|
+
* }
|
|
46
|
+
* ```
|
|
47
|
+
*/
|
|
48
|
+
var TanStackRouterEsbuild = createEsbuildPlugin(unpluginRouterComposedFactory);
|
|
49
|
+
var tanstackRouter = TanStackRouterEsbuild;
|
|
50
|
+
//#endregion
|
|
51
|
+
export {
|
|
52
|
+
TanStackRouterCodeSplitterEsbuild,
|
|
53
|
+
TanStackRouterEsbuild,
|
|
54
|
+
TanStackRouterEsbuild as default,
|
|
55
|
+
TanStackRouterGeneratorEsbuild,
|
|
56
|
+
configSchema,
|
|
57
|
+
tanstackRouter,
|
|
58
|
+
};
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export { configSchema, getConfig } from './core/config.js';
|
|
2
|
+
export { unpluginRouterCodeSplitterFactory } from './core/router-code-splitter-plugin.js';
|
|
3
|
+
export { unpluginRouterGeneratorFactory } from './core/router-generator-plugin.js';
|
|
4
|
+
export { createRouterPluginContext } from './core/router-plugin-context.js';
|
|
5
|
+
export type {
|
|
6
|
+
Config,
|
|
7
|
+
ConfigInput,
|
|
8
|
+
ConfigOutput,
|
|
9
|
+
CodeSplittingOptions,
|
|
10
|
+
DeletableNodes,
|
|
11
|
+
HmrOptions,
|
|
12
|
+
} from './core/config.js';
|
|
13
|
+
export type { RouterPluginContext } from './core/router-plugin-context.js';
|
|
14
|
+
export { getObjectPropertyKeyName } from './core/utils.js';
|
|
15
|
+
export type {
|
|
16
|
+
ReferenceRouteCompilerPlugin,
|
|
17
|
+
ReferenceRouteCompilerPluginContext,
|
|
18
|
+
} from './core/code-splitter/plugins.js';
|
|
19
|
+
export { tsrSplit, splitRouteIdentNodes, defaultCodeSplitGroupings } from './core/constants.js';
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { configSchema, getConfig } from './core/config.js';
|
|
2
|
+
import { defaultCodeSplitGroupings, splitRouteIdentNodes, tsrSplit } from './core/constants.js';
|
|
3
|
+
import { getObjectPropertyKeyName } from './core/utils.js';
|
|
4
|
+
import { createRouterPluginContext } from './core/router-plugin-context.js';
|
|
5
|
+
import { unpluginRouterCodeSplitterFactory } from './core/router-code-splitter-plugin.js';
|
|
6
|
+
import { unpluginRouterGeneratorFactory } from './core/router-generator-plugin.js';
|
|
7
|
+
export {
|
|
8
|
+
configSchema,
|
|
9
|
+
createRouterPluginContext,
|
|
10
|
+
defaultCodeSplitGroupings,
|
|
11
|
+
getConfig,
|
|
12
|
+
getObjectPropertyKeyName,
|
|
13
|
+
splitRouteIdentNodes,
|
|
14
|
+
tsrSplit,
|
|
15
|
+
unpluginRouterCodeSplitterFactory,
|
|
16
|
+
unpluginRouterGeneratorFactory,
|
|
17
|
+
};
|
|
@@ -0,0 +1,61 @@
|
|
|
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>);
|
|
4
|
+
/**
|
|
5
|
+
* @example
|
|
6
|
+
* ```ts
|
|
7
|
+
* export default defineConfig({
|
|
8
|
+
* // ...
|
|
9
|
+
* tools: {
|
|
10
|
+
* rspack: {
|
|
11
|
+
* plugins: [TanStackRouterGeneratorRspack()],
|
|
12
|
+
* },
|
|
13
|
+
* },
|
|
14
|
+
* })
|
|
15
|
+
* ```
|
|
16
|
+
*/
|
|
17
|
+
declare const TanStackRouterGeneratorRspack: (
|
|
18
|
+
options?: RspackRouterPluginOptions,
|
|
19
|
+
routerPluginContext?: RouterPluginContext,
|
|
20
|
+
) => import('unplugin').RspackPluginInstance;
|
|
21
|
+
/**
|
|
22
|
+
* @example
|
|
23
|
+
* ```ts
|
|
24
|
+
* export default defineConfig({
|
|
25
|
+
* // ...
|
|
26
|
+
* tools: {
|
|
27
|
+
* rspack: {
|
|
28
|
+
* plugins: [TanStackRouterCodeSplitterRspack()],
|
|
29
|
+
* },
|
|
30
|
+
* },
|
|
31
|
+
* })
|
|
32
|
+
* ```
|
|
33
|
+
*/
|
|
34
|
+
declare const TanStackRouterCodeSplitterRspack: (
|
|
35
|
+
options?: RspackRouterPluginOptions,
|
|
36
|
+
routerPluginContext?: RouterPluginContext,
|
|
37
|
+
) => import('unplugin').RspackPluginInstance;
|
|
38
|
+
/**
|
|
39
|
+
* @example
|
|
40
|
+
* ```ts
|
|
41
|
+
* export default defineConfig({
|
|
42
|
+
* // ...
|
|
43
|
+
* tools: {
|
|
44
|
+
* rspack: {
|
|
45
|
+
* plugins: [tanstackRouter()],
|
|
46
|
+
* },
|
|
47
|
+
* },
|
|
48
|
+
* })
|
|
49
|
+
* ```
|
|
50
|
+
*/
|
|
51
|
+
declare const TanStackRouterRspack: (options?: unknown) => import('unplugin').RspackPluginInstance;
|
|
52
|
+
declare const tanstackRouter: (options?: unknown) => import('unplugin').RspackPluginInstance;
|
|
53
|
+
export default TanStackRouterRspack;
|
|
54
|
+
export {
|
|
55
|
+
configSchema,
|
|
56
|
+
TanStackRouterRspack,
|
|
57
|
+
TanStackRouterGeneratorRspack,
|
|
58
|
+
TanStackRouterCodeSplitterRspack,
|
|
59
|
+
tanstackRouter,
|
|
60
|
+
};
|
|
61
|
+
export type { Config, CodeSplittingOptions, RouterPluginContext };
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
import { configSchema } from './core/config.js';
|
|
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';
|
|
5
|
+
import { unpluginRouterComposedFactory } from './core/router-composed-plugin.js';
|
|
6
|
+
import { createRspackPlugin } from 'unplugin';
|
|
7
|
+
//#region src/rspack.ts
|
|
8
|
+
var defaultRouterPluginContext = createRouterPluginContext();
|
|
9
|
+
/**
|
|
10
|
+
* Rspack uses webpack-compatible `module.hot` / `import.meta.webpackHot` HMR.
|
|
11
|
+
* Force `plugin.hmr.style = 'webpack'` so the router HMR adapter emits
|
|
12
|
+
* `module.hot`-style accept/dispose code instead of Vite's callback-receive
|
|
13
|
+
* variant, regardless of what the user passes (or doesn't pass).
|
|
14
|
+
*/
|
|
15
|
+
function withWebpackHmrStyle(options) {
|
|
16
|
+
const mergeHmrStyle = (config) => ({
|
|
17
|
+
...config,
|
|
18
|
+
plugin: {
|
|
19
|
+
...config?.plugin,
|
|
20
|
+
hmr: {
|
|
21
|
+
...config?.plugin?.hmr,
|
|
22
|
+
style: 'webpack',
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
});
|
|
26
|
+
if (typeof options === 'function') return () => mergeHmrStyle(options());
|
|
27
|
+
return mergeHmrStyle(options);
|
|
28
|
+
}
|
|
29
|
+
/**
|
|
30
|
+
* @example
|
|
31
|
+
* ```ts
|
|
32
|
+
* export default defineConfig({
|
|
33
|
+
* // ...
|
|
34
|
+
* tools: {
|
|
35
|
+
* rspack: {
|
|
36
|
+
* plugins: [TanStackRouterGeneratorRspack()],
|
|
37
|
+
* },
|
|
38
|
+
* },
|
|
39
|
+
* })
|
|
40
|
+
* ```
|
|
41
|
+
*/
|
|
42
|
+
var TanStackRouterGeneratorRspack = (options, routerPluginContext) => {
|
|
43
|
+
const pluginContext = routerPluginContext ?? defaultRouterPluginContext;
|
|
44
|
+
return createRspackPlugin((pluginOptions) =>
|
|
45
|
+
createRouterGeneratorPlugin(pluginOptions, pluginContext),
|
|
46
|
+
)(options);
|
|
47
|
+
};
|
|
48
|
+
/**
|
|
49
|
+
* @example
|
|
50
|
+
* ```ts
|
|
51
|
+
* export default defineConfig({
|
|
52
|
+
* // ...
|
|
53
|
+
* tools: {
|
|
54
|
+
* rspack: {
|
|
55
|
+
* plugins: [TanStackRouterCodeSplitterRspack()],
|
|
56
|
+
* },
|
|
57
|
+
* },
|
|
58
|
+
* })
|
|
59
|
+
* ```
|
|
60
|
+
*/
|
|
61
|
+
var TanStackRouterCodeSplitterRspack = (options, routerPluginContext) => {
|
|
62
|
+
const pluginContext = routerPluginContext ?? defaultRouterPluginContext;
|
|
63
|
+
return createRspackPlugin((pluginOptions) =>
|
|
64
|
+
createRouterCodeSplitterPlugin(withWebpackHmrStyle(pluginOptions), pluginContext),
|
|
65
|
+
)(options);
|
|
66
|
+
};
|
|
67
|
+
/**
|
|
68
|
+
* @example
|
|
69
|
+
* ```ts
|
|
70
|
+
* export default defineConfig({
|
|
71
|
+
* // ...
|
|
72
|
+
* tools: {
|
|
73
|
+
* rspack: {
|
|
74
|
+
* plugins: [tanstackRouter()],
|
|
75
|
+
* },
|
|
76
|
+
* },
|
|
77
|
+
* })
|
|
78
|
+
* ```
|
|
79
|
+
*/
|
|
80
|
+
var TanStackRouterRspack = /* @__PURE__ */ createRspackPlugin((options, meta) =>
|
|
81
|
+
unpluginRouterComposedFactory(withWebpackHmrStyle(options), meta),
|
|
82
|
+
);
|
|
83
|
+
var tanstackRouter = TanStackRouterRspack;
|
|
84
|
+
//#endregion
|
|
85
|
+
export {
|
|
86
|
+
TanStackRouterCodeSplitterRspack,
|
|
87
|
+
TanStackRouterGeneratorRspack,
|
|
88
|
+
TanStackRouterRspack,
|
|
89
|
+
TanStackRouterRspack as default,
|
|
90
|
+
configSchema,
|
|
91
|
+
tanstackRouter,
|
|
92
|
+
};
|