@tanstack/router-plugin 1.167.31 → 1.167.33
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/context.cjs +3 -0
- package/dist/cjs/context.d.cts +2 -0
- package/dist/cjs/core/code-splitter/compilers.cjs.map +1 -1
- package/dist/cjs/core/code-splitter/compilers.d.cts +1 -0
- package/dist/cjs/core/router-code-splitter-plugin.cjs +12 -3
- package/dist/cjs/core/router-code-splitter-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-code-splitter-plugin.d.cts +2 -0
- package/dist/cjs/core/router-composed-plugin.cjs +7 -6
- package/dist/cjs/core/router-composed-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-generator-plugin.cjs +7 -2
- package/dist/cjs/core/router-generator-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-generator-plugin.d.cts +2 -0
- package/dist/cjs/core/router-hmr-plugin.cjs +13 -7
- package/dist/cjs/core/router-hmr-plugin.cjs.map +1 -1
- package/dist/cjs/core/router-hmr-plugin.d.cts +2 -0
- package/dist/cjs/core/router-plugin-context.cjs +8 -0
- package/dist/cjs/core/router-plugin-context.cjs.map +1 -0
- package/dist/cjs/core/router-plugin-context.d.cts +5 -0
- package/dist/cjs/esbuild.cjs +10 -2
- package/dist/cjs/esbuild.cjs.map +1 -1
- package/dist/cjs/esbuild.d.cts +5 -95
- package/dist/cjs/index.cjs +2 -0
- package/dist/cjs/index.d.cts +2 -0
- package/dist/cjs/rspack.cjs +10 -2
- package/dist/cjs/rspack.cjs.map +1 -1
- package/dist/cjs/rspack.d.cts +5 -49
- package/dist/cjs/vite.cjs +11 -2
- package/dist/cjs/vite.cjs.map +1 -1
- package/dist/cjs/vite.d.cts +6 -96
- package/dist/cjs/webpack.cjs +10 -2
- package/dist/cjs/webpack.cjs.map +1 -1
- package/dist/cjs/webpack.d.cts +4 -49
- package/dist/esm/context.d.ts +2 -0
- package/dist/esm/context.js +2 -0
- package/dist/esm/core/code-splitter/compilers.d.ts +1 -0
- package/dist/esm/core/code-splitter/compilers.js.map +1 -1
- package/dist/esm/core/router-code-splitter-plugin.d.ts +2 -0
- package/dist/esm/core/router-code-splitter-plugin.js +12 -4
- package/dist/esm/core/router-code-splitter-plugin.js.map +1 -1
- package/dist/esm/core/router-composed-plugin.js +10 -9
- package/dist/esm/core/router-composed-plugin.js.map +1 -1
- package/dist/esm/core/router-generator-plugin.d.ts +2 -0
- package/dist/esm/core/router-generator-plugin.js +7 -3
- package/dist/esm/core/router-generator-plugin.js.map +1 -1
- package/dist/esm/core/router-hmr-plugin.d.ts +2 -0
- package/dist/esm/core/router-hmr-plugin.js +13 -7
- package/dist/esm/core/router-hmr-plugin.js.map +1 -1
- package/dist/esm/core/router-plugin-context.d.ts +5 -0
- package/dist/esm/core/router-plugin-context.js +8 -0
- package/dist/esm/core/router-plugin-context.js.map +1 -0
- package/dist/esm/esbuild.d.ts +5 -95
- package/dist/esm/esbuild.js +12 -4
- package/dist/esm/esbuild.js.map +1 -1
- package/dist/esm/index.d.ts +2 -0
- package/dist/esm/index.js +2 -1
- package/dist/esm/rspack.d.ts +5 -49
- package/dist/esm/rspack.js +12 -4
- package/dist/esm/rspack.js.map +1 -1
- package/dist/esm/vite.d.ts +6 -96
- package/dist/esm/vite.js +14 -6
- package/dist/esm/vite.js.map +1 -1
- package/dist/esm/webpack.d.ts +4 -49
- package/dist/esm/webpack.js +12 -4
- package/dist/esm/webpack.js.map +1 -1
- package/package.json +13 -7
- package/src/context.ts +2 -0
- package/src/core/code-splitter/compilers.ts +1 -0
- package/src/core/router-code-splitter-plugin.ts +15 -4
- package/src/core/router-composed-plugin.ts +16 -11
- package/src/core/router-generator-plugin.ts +13 -4
- package/src/core/router-hmr-plugin.ts +22 -7
- package/src/core/router-plugin-context.ts +11 -0
- package/src/esbuild.ts +27 -9
- package/src/index.ts +2 -0
- package/src/rspack.ts +30 -12
- package/src/vite.ts +29 -9
- package/src/webpack.ts +27 -12
- package/bin/intent.js +0 -25
- package/src/global.d.ts +0 -7
package/dist/esm/rspack.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { configSchema } from "./core/config.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { createRouterPluginContext } from "./core/router-plugin-context.js";
|
|
3
|
+
import { createRouterCodeSplitterPlugin } from "./core/router-code-splitter-plugin.js";
|
|
4
|
+
import { createRouterGeneratorPlugin } from "./core/router-generator-plugin.js";
|
|
4
5
|
import { unpluginRouterComposedFactory } from "./core/router-composed-plugin.js";
|
|
5
6
|
import { createRspackPlugin } from "unplugin";
|
|
6
7
|
//#region src/rspack.ts
|
|
8
|
+
var defaultRouterPluginContext = createRouterPluginContext();
|
|
7
9
|
/**
|
|
8
10
|
* Rspack uses webpack-compatible `module.hot` / `import.meta.webpackHot` HMR.
|
|
9
11
|
* Force `plugin.hmr.style = 'webpack'` so the router HMR adapter emits
|
|
@@ -37,7 +39,10 @@ function withWebpackHmrStyle(options) {
|
|
|
37
39
|
* })
|
|
38
40
|
* ```
|
|
39
41
|
*/
|
|
40
|
-
var TanStackRouterGeneratorRspack =
|
|
42
|
+
var TanStackRouterGeneratorRspack = (options, routerPluginContext) => {
|
|
43
|
+
const pluginContext = routerPluginContext ?? defaultRouterPluginContext;
|
|
44
|
+
return createRspackPlugin((pluginOptions) => createRouterGeneratorPlugin(pluginOptions, pluginContext))(options);
|
|
45
|
+
};
|
|
41
46
|
/**
|
|
42
47
|
* @example
|
|
43
48
|
* ```ts
|
|
@@ -51,7 +56,10 @@ var TanStackRouterGeneratorRspack = /* @__PURE__ */ createRspackPlugin(unpluginR
|
|
|
51
56
|
* })
|
|
52
57
|
* ```
|
|
53
58
|
*/
|
|
54
|
-
var TanStackRouterCodeSplitterRspack =
|
|
59
|
+
var TanStackRouterCodeSplitterRspack = (options, routerPluginContext) => {
|
|
60
|
+
const pluginContext = routerPluginContext ?? defaultRouterPluginContext;
|
|
61
|
+
return createRspackPlugin((pluginOptions) => createRouterCodeSplitterPlugin(withWebpackHmrStyle(pluginOptions), pluginContext))(options);
|
|
62
|
+
};
|
|
55
63
|
/**
|
|
56
64
|
* @example
|
|
57
65
|
* ```ts
|
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 { createRouterCodeSplitterPlugin } from './core/router-code-splitter-plugin'\nimport { createRouterGeneratorPlugin } from './core/router-generator-plugin'\nimport { unpluginRouterComposedFactory } from './core/router-composed-plugin'\nimport { createRouterPluginContext } from './core/router-plugin-context'\nimport type { CodeSplittingOptions, Config } from './core/config'\nimport type { RouterPluginContext } from './core/router-plugin-context'\n\ntype RspackRouterPluginOptions = Partial<Config> | (() => Partial<Config>)\n\nconst defaultRouterPluginContext = createRouterPluginContext()\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 = (\n options?: RspackRouterPluginOptions,\n routerPluginContext?: RouterPluginContext,\n) => {\n const pluginContext = routerPluginContext ?? defaultRouterPluginContext\n return createRspackPlugin((pluginOptions) =>\n createRouterGeneratorPlugin(\n pluginOptions as Partial<Config | (() => Config)> | undefined,\n pluginContext,\n ),\n )(options)\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 = (\n options?: RspackRouterPluginOptions,\n routerPluginContext?: RouterPluginContext,\n) => {\n const pluginContext = routerPluginContext ?? defaultRouterPluginContext\n return createRspackPlugin((pluginOptions) =>\n createRouterCodeSplitterPlugin(\n withWebpackHmrStyle(\n pluginOptions as RspackRouterPluginOptions | undefined,\n ) as Partial<Config | (() => Config)>,\n pluginContext,\n ),\n )(options)\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, RouterPluginContext }\n"],"mappings":";;;;;;;AAYA,IAAM,6BAA6B,2BAA2B;;;;;;;AAQ9D,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,iCACJ,SACA,wBACG;CACH,MAAM,gBAAgB,uBAAuB;AAC7C,QAAO,oBAAoB,kBACzB,4BACE,eACA,cACD,CACF,CAAC,QAAQ;;;;;;;;;;;;;;;AAgBZ,IAAM,oCACJ,SACA,wBACG;CACH,MAAM,gBAAgB,uBAAuB;AAC7C,QAAO,oBAAoB,kBACzB,+BACE,oBACE,cACD,EACD,cACD,CACF,CAAC,QAAQ;;;;;;;;;;;;;;;AAgBZ,IAAM,uBAAuC,oCAC1C,SAAS,SACR,8BACE,oBACE,QACD,EACD,KACD,CACJ;AACD,IAAM,iBAAiB"}
|
package/dist/esm/vite.d.ts
CHANGED
|
@@ -1,4 +1,6 @@
|
|
|
1
|
-
import { configSchema, CodeSplittingOptions, Config
|
|
1
|
+
import { configSchema, getConfig, CodeSplittingOptions, Config } from './core/config.js';
|
|
2
|
+
import { RouterPluginContext } from './core/router-plugin-context.js';
|
|
3
|
+
type RouterPluginOptions = Partial<Config | (() => Config)> | undefined;
|
|
2
4
|
/**
|
|
3
5
|
* @example
|
|
4
6
|
* ```ts
|
|
@@ -8,53 +10,7 @@ import { configSchema, CodeSplittingOptions, Config, getConfig } from './core/co
|
|
|
8
10
|
* })
|
|
9
11
|
* ```
|
|
10
12
|
*/
|
|
11
|
-
declare const tanstackRouterGenerator: (options?:
|
|
12
|
-
target: "react" | "solid" | "vue";
|
|
13
|
-
routeFileIgnorePrefix: string;
|
|
14
|
-
routesDirectory: string;
|
|
15
|
-
quoteStyle: "single" | "double";
|
|
16
|
-
semicolons: boolean;
|
|
17
|
-
disableLogging: boolean;
|
|
18
|
-
routeTreeFileHeader: string[];
|
|
19
|
-
indexToken: string | RegExp | {
|
|
20
|
-
regex: string;
|
|
21
|
-
flags?: string | undefined;
|
|
22
|
-
};
|
|
23
|
-
routeToken: string | RegExp | {
|
|
24
|
-
regex: string;
|
|
25
|
-
flags?: string | undefined;
|
|
26
|
-
};
|
|
27
|
-
generatedRouteTree: string;
|
|
28
|
-
disableTypes: boolean;
|
|
29
|
-
addExtensions: string | boolean;
|
|
30
|
-
enableRouteTreeFormatting: boolean;
|
|
31
|
-
tmpDir: string;
|
|
32
|
-
importRoutesUsingAbsolutePaths: boolean;
|
|
33
|
-
enableRouteGeneration?: boolean | undefined;
|
|
34
|
-
codeSplittingOptions?: CodeSplittingOptions | undefined;
|
|
35
|
-
plugin?: {
|
|
36
|
-
vite?: {
|
|
37
|
-
environmentName?: string | undefined;
|
|
38
|
-
} | undefined;
|
|
39
|
-
hmr?: {
|
|
40
|
-
style?: "vite" | "webpack" | undefined;
|
|
41
|
-
} | undefined;
|
|
42
|
-
} | undefined;
|
|
43
|
-
virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
|
|
44
|
-
routeFilePrefix?: string | undefined;
|
|
45
|
-
routeFileIgnorePattern?: string | undefined;
|
|
46
|
-
pathParamsAllowedCharacters?: (";" | ":" | "@" | "&" | "=" | "+" | "$" | ",")[] | undefined;
|
|
47
|
-
routeTreeFileFooter?: string[] | ((...args: unknown[]) => string[]) | undefined;
|
|
48
|
-
autoCodeSplitting?: boolean | undefined;
|
|
49
|
-
customScaffolding?: {
|
|
50
|
-
routeTemplate?: string | undefined;
|
|
51
|
-
lazyRouteTemplate?: string | undefined;
|
|
52
|
-
} | undefined;
|
|
53
|
-
experimental?: {
|
|
54
|
-
enableCodeSplitting?: boolean | undefined;
|
|
55
|
-
} | undefined;
|
|
56
|
-
plugins?: import('@tanstack/router-generator').GeneratorPlugin[] | undefined;
|
|
57
|
-
} | (() => Config)> | undefined) => import('vite').Plugin<any> | import('vite').Plugin<any>[];
|
|
13
|
+
declare const tanstackRouterGenerator: (options?: RouterPluginOptions, routerPluginContext?: RouterPluginContext) => import('vite').Plugin<any> | import('vite').Plugin<any>[];
|
|
58
14
|
/**
|
|
59
15
|
* @example
|
|
60
16
|
* ```ts
|
|
@@ -64,53 +20,7 @@ declare const tanstackRouterGenerator: (options?: Partial<{
|
|
|
64
20
|
* })
|
|
65
21
|
* ```
|
|
66
22
|
*/
|
|
67
|
-
declare const tanStackRouterCodeSplitter: (options?:
|
|
68
|
-
target: "react" | "solid" | "vue";
|
|
69
|
-
routeFileIgnorePrefix: string;
|
|
70
|
-
routesDirectory: string;
|
|
71
|
-
quoteStyle: "single" | "double";
|
|
72
|
-
semicolons: boolean;
|
|
73
|
-
disableLogging: boolean;
|
|
74
|
-
routeTreeFileHeader: string[];
|
|
75
|
-
indexToken: string | RegExp | {
|
|
76
|
-
regex: string;
|
|
77
|
-
flags?: string | undefined;
|
|
78
|
-
};
|
|
79
|
-
routeToken: string | RegExp | {
|
|
80
|
-
regex: string;
|
|
81
|
-
flags?: string | undefined;
|
|
82
|
-
};
|
|
83
|
-
generatedRouteTree: string;
|
|
84
|
-
disableTypes: boolean;
|
|
85
|
-
addExtensions: string | boolean;
|
|
86
|
-
enableRouteTreeFormatting: boolean;
|
|
87
|
-
tmpDir: string;
|
|
88
|
-
importRoutesUsingAbsolutePaths: boolean;
|
|
89
|
-
enableRouteGeneration?: boolean | undefined;
|
|
90
|
-
codeSplittingOptions?: CodeSplittingOptions | undefined;
|
|
91
|
-
plugin?: {
|
|
92
|
-
vite?: {
|
|
93
|
-
environmentName?: string | undefined;
|
|
94
|
-
} | undefined;
|
|
95
|
-
hmr?: {
|
|
96
|
-
style?: "vite" | "webpack" | undefined;
|
|
97
|
-
} | undefined;
|
|
98
|
-
} | undefined;
|
|
99
|
-
virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
|
|
100
|
-
routeFilePrefix?: string | undefined;
|
|
101
|
-
routeFileIgnorePattern?: string | undefined;
|
|
102
|
-
pathParamsAllowedCharacters?: (";" | ":" | "@" | "&" | "=" | "+" | "$" | ",")[] | undefined;
|
|
103
|
-
routeTreeFileFooter?: string[] | ((...args: unknown[]) => string[]) | undefined;
|
|
104
|
-
autoCodeSplitting?: boolean | undefined;
|
|
105
|
-
customScaffolding?: {
|
|
106
|
-
routeTemplate?: string | undefined;
|
|
107
|
-
lazyRouteTemplate?: string | undefined;
|
|
108
|
-
} | undefined;
|
|
109
|
-
experimental?: {
|
|
110
|
-
enableCodeSplitting?: boolean | undefined;
|
|
111
|
-
} | undefined;
|
|
112
|
-
plugins?: import('@tanstack/router-generator').GeneratorPlugin[] | undefined;
|
|
113
|
-
} | (() => Config)> | undefined) => import('vite').Plugin<any> | import('vite').Plugin<any>[];
|
|
23
|
+
declare const tanStackRouterCodeSplitter: (options?: RouterPluginOptions, routerPluginContext?: RouterPluginContext) => import('vite').Plugin<any> | import('vite').Plugin<any>[];
|
|
114
24
|
/**
|
|
115
25
|
* @example
|
|
116
26
|
* ```ts
|
|
@@ -219,4 +129,4 @@ declare const TanStackRouterVite: (options?: Partial<{
|
|
|
219
129
|
} | (() => Config)> | undefined) => import('vite').Plugin<any> | import('vite').Plugin<any>[];
|
|
220
130
|
export default tanstackRouter;
|
|
221
131
|
export { configSchema, getConfig, tanStackRouterCodeSplitter, tanstackRouterGenerator, TanStackRouterVite, tanstackRouter, };
|
|
222
|
-
export type { Config, CodeSplittingOptions };
|
|
132
|
+
export type { Config, CodeSplittingOptions, RouterPluginContext };
|
package/dist/esm/vite.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
|
-
import { configSchema } from "./core/config.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
1
|
+
import { configSchema, getConfig } 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";
|
|
4
5
|
import { unpluginRouterComposedFactory } from "./core/router-composed-plugin.js";
|
|
5
6
|
import { createVitePlugin } from "unplugin";
|
|
6
7
|
//#region src/vite.ts
|
|
8
|
+
var defaultRouterPluginContext = createRouterPluginContext();
|
|
7
9
|
/**
|
|
8
10
|
* @example
|
|
9
11
|
* ```ts
|
|
@@ -13,7 +15,10 @@ import { createVitePlugin } from "unplugin";
|
|
|
13
15
|
* })
|
|
14
16
|
* ```
|
|
15
17
|
*/
|
|
16
|
-
var tanstackRouterGenerator =
|
|
18
|
+
var tanstackRouterGenerator = (options, routerPluginContext) => {
|
|
19
|
+
const pluginContext = routerPluginContext ?? defaultRouterPluginContext;
|
|
20
|
+
return createVitePlugin((pluginOptions) => createRouterGeneratorPlugin(pluginOptions, pluginContext))(options);
|
|
21
|
+
};
|
|
17
22
|
/**
|
|
18
23
|
* @example
|
|
19
24
|
* ```ts
|
|
@@ -23,7 +28,10 @@ var tanstackRouterGenerator = createVitePlugin(unpluginRouterGeneratorFactory);
|
|
|
23
28
|
* })
|
|
24
29
|
* ```
|
|
25
30
|
*/
|
|
26
|
-
var tanStackRouterCodeSplitter =
|
|
31
|
+
var tanStackRouterCodeSplitter = (options, routerPluginContext) => {
|
|
32
|
+
const pluginContext = routerPluginContext ?? defaultRouterPluginContext;
|
|
33
|
+
return createVitePlugin((pluginOptions) => createRouterCodeSplitterPlugin(pluginOptions, pluginContext))(options);
|
|
34
|
+
};
|
|
27
35
|
/**
|
|
28
36
|
* @example
|
|
29
37
|
* ```ts
|
|
@@ -39,6 +47,6 @@ var tanstackRouter = createVitePlugin(unpluginRouterComposedFactory);
|
|
|
39
47
|
*/
|
|
40
48
|
var TanStackRouterVite = tanstackRouter;
|
|
41
49
|
//#endregion
|
|
42
|
-
export { TanStackRouterVite, configSchema, tanstackRouter as default, tanstackRouter, tanStackRouterCodeSplitter, tanstackRouterGenerator };
|
|
50
|
+
export { TanStackRouterVite, configSchema, tanstackRouter as default, tanstackRouter, getConfig, tanStackRouterCodeSplitter, tanstackRouterGenerator };
|
|
43
51
|
|
|
44
52
|
//# sourceMappingURL=vite.js.map
|
package/dist/esm/vite.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.js","names":[],"sources":["../../src/vite.ts"],"sourcesContent":["import { createVitePlugin } from 'unplugin'\n\nimport { configSchema } from './core/config'\nimport {
|
|
1
|
+
{"version":3,"file":"vite.js","names":[],"sources":["../../src/vite.ts"],"sourcesContent":["import { createVitePlugin } from 'unplugin'\n\nimport { configSchema, getConfig } from './core/config'\nimport { createRouterCodeSplitterPlugin } from './core/router-code-splitter-plugin'\nimport { createRouterGeneratorPlugin } from './core/router-generator-plugin'\nimport { unpluginRouterComposedFactory } from './core/router-composed-plugin'\nimport { createRouterPluginContext } from './core/router-plugin-context'\nimport type { CodeSplittingOptions, Config } from './core/config'\nimport type { RouterPluginContext } from './core/router-plugin-context'\n\ntype RouterPluginOptions = Partial<Config | (() => Config)> | undefined\n\nconst defaultRouterPluginContext = createRouterPluginContext()\n\n/**\n * @example\n * ```ts\n * export default defineConfig({\n * plugins: [tanstackRouterGenerator()],\n * // ...\n * })\n * ```\n */\nconst tanstackRouterGenerator = (\n options?: RouterPluginOptions,\n routerPluginContext?: RouterPluginContext,\n) => {\n const pluginContext = routerPluginContext ?? defaultRouterPluginContext\n return createVitePlugin((pluginOptions: RouterPluginOptions) =>\n createRouterGeneratorPlugin(pluginOptions, pluginContext),\n )(options)\n}\n\n/**\n * @example\n * ```ts\n * export default defineConfig({\n * plugins: [tanStackRouterCodeSplitter()],\n * // ...\n * })\n * ```\n */\nconst tanStackRouterCodeSplitter = (\n options?: RouterPluginOptions,\n routerPluginContext?: RouterPluginContext,\n) => {\n const pluginContext = routerPluginContext ?? defaultRouterPluginContext\n return createVitePlugin((pluginOptions: RouterPluginOptions) =>\n createRouterCodeSplitterPlugin(pluginOptions, pluginContext),\n )(options)\n}\n\n/**\n * @example\n * ```ts\n * export default defineConfig({\n * plugins: [tanstackRouter()],\n * // ...\n * })\n * ```\n */\nconst tanstackRouter = createVitePlugin(unpluginRouterComposedFactory)\n\n/**\n * @deprecated Use `tanstackRouter` instead.\n */\nconst TanStackRouterVite = tanstackRouter\n\nexport default tanstackRouter\nexport {\n configSchema,\n getConfig,\n tanStackRouterCodeSplitter,\n tanstackRouterGenerator,\n TanStackRouterVite,\n tanstackRouter,\n}\n\nexport type { Config, CodeSplittingOptions, RouterPluginContext }\n"],"mappings":";;;;;;;AAYA,IAAM,6BAA6B,2BAA2B;;;;;;;;;;AAW9D,IAAM,2BACJ,SACA,wBACG;CACH,MAAM,gBAAgB,uBAAuB;AAC7C,QAAO,kBAAkB,kBACvB,4BAA4B,eAAe,cAAc,CAC1D,CAAC,QAAQ;;;;;;;;;;;AAYZ,IAAM,8BACJ,SACA,wBACG;CACH,MAAM,gBAAgB,uBAAuB;AAC7C,QAAO,kBAAkB,kBACvB,+BAA+B,eAAe,cAAc,CAC7D,CAAC,QAAQ;;;;;;;;;;;AAYZ,IAAM,iBAAiB,iBAAiB,8BAA8B;;;;AAKtE,IAAM,qBAAqB"}
|
package/dist/esm/webpack.d.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { configSchema, CodeSplittingOptions, Config } from './core/config.js';
|
|
2
|
+
import { RouterPluginContext } from './core/router-plugin-context.js';
|
|
2
3
|
/**
|
|
3
4
|
* @example
|
|
4
5
|
* ```ts
|
|
@@ -8,53 +9,7 @@ import { configSchema, CodeSplittingOptions, Config } from './core/config.js';
|
|
|
8
9
|
* }
|
|
9
10
|
* ```
|
|
10
11
|
*/
|
|
11
|
-
declare const TanStackRouterGeneratorWebpack: (options?: Partial<
|
|
12
|
-
target: "react" | "solid" | "vue";
|
|
13
|
-
routeFileIgnorePrefix: string;
|
|
14
|
-
routesDirectory: string;
|
|
15
|
-
quoteStyle: "single" | "double";
|
|
16
|
-
semicolons: boolean;
|
|
17
|
-
disableLogging: boolean;
|
|
18
|
-
routeTreeFileHeader: string[];
|
|
19
|
-
indexToken: string | RegExp | {
|
|
20
|
-
regex: string;
|
|
21
|
-
flags?: string | undefined;
|
|
22
|
-
};
|
|
23
|
-
routeToken: string | RegExp | {
|
|
24
|
-
regex: string;
|
|
25
|
-
flags?: string | undefined;
|
|
26
|
-
};
|
|
27
|
-
generatedRouteTree: string;
|
|
28
|
-
disableTypes: boolean;
|
|
29
|
-
addExtensions: string | boolean;
|
|
30
|
-
enableRouteTreeFormatting: boolean;
|
|
31
|
-
tmpDir: string;
|
|
32
|
-
importRoutesUsingAbsolutePaths: boolean;
|
|
33
|
-
enableRouteGeneration?: boolean | undefined;
|
|
34
|
-
codeSplittingOptions?: CodeSplittingOptions | undefined;
|
|
35
|
-
plugin?: {
|
|
36
|
-
vite?: {
|
|
37
|
-
environmentName?: string | undefined;
|
|
38
|
-
} | undefined;
|
|
39
|
-
hmr?: {
|
|
40
|
-
style?: "vite" | "webpack" | undefined;
|
|
41
|
-
} | undefined;
|
|
42
|
-
} | undefined;
|
|
43
|
-
virtualRouteConfig?: string | import('@tanstack/virtual-file-routes').VirtualRootRoute | undefined;
|
|
44
|
-
routeFilePrefix?: string | undefined;
|
|
45
|
-
routeFileIgnorePattern?: string | undefined;
|
|
46
|
-
pathParamsAllowedCharacters?: (";" | ":" | "@" | "&" | "=" | "+" | "$" | ",")[] | undefined;
|
|
47
|
-
routeTreeFileFooter?: string[] | ((...args: unknown[]) => string[]) | undefined;
|
|
48
|
-
autoCodeSplitting?: boolean | undefined;
|
|
49
|
-
customScaffolding?: {
|
|
50
|
-
routeTemplate?: string | undefined;
|
|
51
|
-
lazyRouteTemplate?: string | undefined;
|
|
52
|
-
} | undefined;
|
|
53
|
-
experimental?: {
|
|
54
|
-
enableCodeSplitting?: boolean | undefined;
|
|
55
|
-
} | undefined;
|
|
56
|
-
plugins?: import('@tanstack/router-generator').GeneratorPlugin[] | undefined;
|
|
57
|
-
} | (() => Config)> | undefined) => import('unplugin').WebpackPluginInstance;
|
|
12
|
+
declare const TanStackRouterGeneratorWebpack: (options?: Partial<Config>, routerPluginContext?: RouterPluginContext) => import('unplugin').WebpackPluginInstance;
|
|
58
13
|
/**
|
|
59
14
|
* @example
|
|
60
15
|
* ```ts
|
|
@@ -64,7 +19,7 @@ declare const TanStackRouterGeneratorWebpack: (options?: Partial<{
|
|
|
64
19
|
* }
|
|
65
20
|
* ```
|
|
66
21
|
*/
|
|
67
|
-
declare const TanStackRouterCodeSplitterWebpack: (options?:
|
|
22
|
+
declare const TanStackRouterCodeSplitterWebpack: (options?: Partial<Config>, routerPluginContext?: RouterPluginContext) => import('unplugin').WebpackPluginInstance;
|
|
68
23
|
/**
|
|
69
24
|
* @example
|
|
70
25
|
* ```ts
|
|
@@ -78,4 +33,4 @@ declare const TanStackRouterWebpack: (options?: unknown) => import('unplugin').W
|
|
|
78
33
|
declare const tanstackRouter: (options?: unknown) => import('unplugin').WebpackPluginInstance;
|
|
79
34
|
export default TanStackRouterWebpack;
|
|
80
35
|
export { configSchema, TanStackRouterWebpack, TanStackRouterGeneratorWebpack, TanStackRouterCodeSplitterWebpack, tanstackRouter, };
|
|
81
|
-
export type { Config, CodeSplittingOptions };
|
|
36
|
+
export type { Config, CodeSplittingOptions, RouterPluginContext };
|
package/dist/esm/webpack.js
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import { configSchema } from "./core/config.js";
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
2
|
+
import { createRouterPluginContext } from "./core/router-plugin-context.js";
|
|
3
|
+
import { createRouterCodeSplitterPlugin } from "./core/router-code-splitter-plugin.js";
|
|
4
|
+
import { createRouterGeneratorPlugin } from "./core/router-generator-plugin.js";
|
|
4
5
|
import { unpluginRouterComposedFactory } from "./core/router-composed-plugin.js";
|
|
5
6
|
import { createWebpackPlugin } from "unplugin";
|
|
6
7
|
//#region src/webpack.ts
|
|
8
|
+
var defaultRouterPluginContext = createRouterPluginContext();
|
|
7
9
|
/**
|
|
8
10
|
* Webpack uses `module.hot` / `import.meta.webpackHot` HMR. Force
|
|
9
11
|
* `plugin.hmr.style = 'webpack'` so the router HMR adapter emits the correct
|
|
@@ -30,7 +32,10 @@ function withWebpackHmrStyle(options) {
|
|
|
30
32
|
* }
|
|
31
33
|
* ```
|
|
32
34
|
*/
|
|
33
|
-
var TanStackRouterGeneratorWebpack =
|
|
35
|
+
var TanStackRouterGeneratorWebpack = (options, routerPluginContext) => {
|
|
36
|
+
const pluginContext = routerPluginContext ?? defaultRouterPluginContext;
|
|
37
|
+
return createWebpackPlugin((pluginOptions) => createRouterGeneratorPlugin(pluginOptions, pluginContext))(options);
|
|
38
|
+
};
|
|
34
39
|
/**
|
|
35
40
|
* @example
|
|
36
41
|
* ```ts
|
|
@@ -40,7 +45,10 @@ var TanStackRouterGeneratorWebpack = /* @__PURE__ */ createWebpackPlugin(unplugi
|
|
|
40
45
|
* }
|
|
41
46
|
* ```
|
|
42
47
|
*/
|
|
43
|
-
var TanStackRouterCodeSplitterWebpack =
|
|
48
|
+
var TanStackRouterCodeSplitterWebpack = (options, routerPluginContext) => {
|
|
49
|
+
const pluginContext = routerPluginContext ?? defaultRouterPluginContext;
|
|
50
|
+
return createWebpackPlugin((pluginOptions) => createRouterCodeSplitterPlugin(withWebpackHmrStyle(pluginOptions), pluginContext))(options);
|
|
51
|
+
};
|
|
44
52
|
/**
|
|
45
53
|
* @example
|
|
46
54
|
* ```ts
|
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 { createRouterCodeSplitterPlugin } from './core/router-code-splitter-plugin'\nimport { createRouterGeneratorPlugin } from './core/router-generator-plugin'\nimport { unpluginRouterComposedFactory } from './core/router-composed-plugin'\nimport { createRouterPluginContext } from './core/router-plugin-context'\nimport type { CodeSplittingOptions, Config } from './core/config'\nimport type { RouterPluginContext } from './core/router-plugin-context'\n\nconst defaultRouterPluginContext = createRouterPluginContext()\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 = (\n options?: Partial<Config>,\n routerPluginContext?: RouterPluginContext,\n) => {\n const pluginContext = routerPluginContext ?? defaultRouterPluginContext\n return createWebpackPlugin((pluginOptions: Partial<Config> | undefined) =>\n createRouterGeneratorPlugin(pluginOptions, pluginContext),\n )(options)\n}\n\n/**\n * @example\n * ```ts\n * export default {\n * // ...\n * plugins: [TanStackRouterCodeSplitterWebpack()],\n * }\n * ```\n */\nconst TanStackRouterCodeSplitterWebpack = (\n options?: Partial<Config>,\n routerPluginContext?: RouterPluginContext,\n) => {\n const pluginContext = routerPluginContext ?? defaultRouterPluginContext\n return createWebpackPlugin((pluginOptions: Partial<Config> | undefined) =>\n createRouterCodeSplitterPlugin(\n withWebpackHmrStyle(pluginOptions),\n pluginContext,\n ),\n )(options)\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, RouterPluginContext }\n"],"mappings":";;;;;;;AAUA,IAAM,6BAA6B,2BAA2B;;;;;;AAO9D,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,kCACJ,SACA,wBACG;CACH,MAAM,gBAAgB,uBAAuB;AAC7C,QAAO,qBAAqB,kBAC1B,4BAA4B,eAAe,cAAc,CAC1D,CAAC,QAAQ;;;;;;;;;;;AAYZ,IAAM,qCACJ,SACA,wBACG;CACH,MAAM,gBAAgB,uBAAuB;AAC7C,QAAO,qBAAqB,kBAC1B,+BACE,oBAAoB,cAAc,EAClC,cACD,CACF,CAAC,QAAQ;;;;;;;;;;;AAYZ,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.33",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -46,6 +46,16 @@
|
|
|
46
46
|
"default": "./dist/cjs/vite.cjs"
|
|
47
47
|
}
|
|
48
48
|
},
|
|
49
|
+
"./context": {
|
|
50
|
+
"import": {
|
|
51
|
+
"types": "./dist/esm/context.d.ts",
|
|
52
|
+
"default": "./dist/esm/context.js"
|
|
53
|
+
},
|
|
54
|
+
"require": {
|
|
55
|
+
"types": "./dist/cjs/context.d.cts",
|
|
56
|
+
"default": "./dist/cjs/context.cjs"
|
|
57
|
+
}
|
|
58
|
+
},
|
|
49
59
|
"./rspack": {
|
|
50
60
|
"import": {
|
|
51
61
|
"types": "./dist/esm/rspack.d.ts",
|
|
@@ -100,12 +110,11 @@
|
|
|
100
110
|
"unplugin": "^3.0.0",
|
|
101
111
|
"zod": "^3.24.2",
|
|
102
112
|
"@tanstack/router-core": "1.169.1",
|
|
103
|
-
"@tanstack/router-generator": "1.166.
|
|
104
|
-
"@tanstack/router-utils": "1.161.
|
|
113
|
+
"@tanstack/router-generator": "1.166.40",
|
|
114
|
+
"@tanstack/router-utils": "1.161.8",
|
|
105
115
|
"@tanstack/virtual-file-routes": "1.161.7"
|
|
106
116
|
},
|
|
107
117
|
"devDependencies": {
|
|
108
|
-
"@tanstack/intent": "^0.0.14",
|
|
109
118
|
"@types/babel__core": "^7.20.5",
|
|
110
119
|
"@types/babel__template": "^7.4.4",
|
|
111
120
|
"@types/babel__traverse": "^7.28.0",
|
|
@@ -135,9 +144,6 @@
|
|
|
135
144
|
"optional": true
|
|
136
145
|
}
|
|
137
146
|
},
|
|
138
|
-
"bin": {
|
|
139
|
-
"intent": "./bin/intent.js"
|
|
140
|
-
},
|
|
141
147
|
"scripts": {
|
|
142
148
|
"clean": "rimraf ./dist && rimraf ./coverage",
|
|
143
149
|
"clean:snapshots": "rimraf **/*snapshot* --glob",
|
package/src/context.ts
ADDED
|
@@ -22,9 +22,11 @@ import {
|
|
|
22
22
|
} from './constants'
|
|
23
23
|
import { decodeIdentifier } from './code-splitter/path-ids'
|
|
24
24
|
import { debug, normalizePath } from './utils'
|
|
25
|
+
import { createRouterPluginContext } from './router-plugin-context'
|
|
25
26
|
import type { CodeSplitGroupings, SplitRouteIdentNodes } from './constants'
|
|
26
27
|
import type { GetRoutesByFileMapResultValue } from '@tanstack/router-generator'
|
|
27
28
|
import type { Config } from './config'
|
|
29
|
+
import type { RouterPluginContext } from './router-plugin-context'
|
|
28
30
|
import type {
|
|
29
31
|
UnpluginFactory,
|
|
30
32
|
TransformResult as UnpluginTransformResult,
|
|
@@ -76,9 +78,10 @@ const TRANSFORMATION_PLUGINS_BY_FRAMEWORK: Record<
|
|
|
76
78
|
],
|
|
77
79
|
}
|
|
78
80
|
|
|
79
|
-
export
|
|
80
|
-
Partial<Config | (() => Config)> | undefined
|
|
81
|
-
|
|
81
|
+
export function createRouterCodeSplitterPlugin(
|
|
82
|
+
options: Partial<Config | (() => Config)> | undefined = {},
|
|
83
|
+
routerPluginContext: RouterPluginContext,
|
|
84
|
+
): ReturnType<UnpluginFactory<Partial<Config | (() => Config)> | undefined>> {
|
|
82
85
|
let ROOT: string = process.cwd()
|
|
83
86
|
let userConfig: Config
|
|
84
87
|
|
|
@@ -113,6 +116,7 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
|
|
|
113
116
|
|
|
114
117
|
const fromCode = detectCodeSplitGroupingsFromRoute({
|
|
115
118
|
code,
|
|
119
|
+
filename: id,
|
|
116
120
|
})
|
|
117
121
|
|
|
118
122
|
if (fromCode.groupings !== undefined) {
|
|
@@ -147,6 +151,7 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
|
|
|
147
151
|
// Compute shared bindings before compiling the reference route
|
|
148
152
|
const sharedBindings = computeSharedBindings({
|
|
149
153
|
code,
|
|
154
|
+
filename: id,
|
|
150
155
|
codeSplitGroupings: splitGroupings,
|
|
151
156
|
})
|
|
152
157
|
if (sharedBindings.size > 0) {
|
|
@@ -259,7 +264,7 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
|
|
|
259
264
|
handler(code, id) {
|
|
260
265
|
const normalizedId = normalizePath(id)
|
|
261
266
|
const generatorFileInfo =
|
|
262
|
-
|
|
267
|
+
routerPluginContext.routesByFile.get(normalizedId)
|
|
263
268
|
if (
|
|
264
269
|
generatorFileInfo &&
|
|
265
270
|
includedCode.some((included) => code.includes(included))
|
|
@@ -402,3 +407,9 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
|
|
|
402
407
|
},
|
|
403
408
|
]
|
|
404
409
|
}
|
|
410
|
+
|
|
411
|
+
export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
|
|
412
|
+
Partial<Config | (() => Config)> | undefined
|
|
413
|
+
> = (options = {}) => {
|
|
414
|
+
return createRouterCodeSplitterPlugin(options, createRouterPluginContext())
|
|
415
|
+
}
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
import { getConfig } from '@tanstack/router-generator'
|
|
2
|
-
import {
|
|
3
|
-
import {
|
|
4
|
-
import {
|
|
2
|
+
import { createRouterGeneratorPlugin } from './router-generator-plugin'
|
|
3
|
+
import { createRouterCodeSplitterPlugin } from './router-code-splitter-plugin'
|
|
4
|
+
import { createRouterHmrPlugin } from './router-hmr-plugin'
|
|
5
|
+
import { createRouterPluginContext } from './router-plugin-context'
|
|
5
6
|
import type { Config } from './config'
|
|
6
7
|
import type {
|
|
7
8
|
RspackCompiler,
|
|
@@ -29,25 +30,27 @@ function applyRspackInlineCssDefaultDefinePlugin(compiler: RspackCompiler) {
|
|
|
29
30
|
|
|
30
31
|
export const unpluginRouterComposedFactory: UnpluginFactory<
|
|
31
32
|
Partial<Config | (() => Config)> | undefined
|
|
32
|
-
> = (options = {},
|
|
33
|
+
> = (options = {}, _meta) => {
|
|
33
34
|
const ROOT: string = process.cwd()
|
|
34
35
|
const userConfig = getConfig(
|
|
35
36
|
(typeof options === 'function' ? options() : options) as Partial<Config>,
|
|
36
37
|
ROOT,
|
|
37
38
|
)
|
|
39
|
+
const routerPluginContext = createRouterPluginContext()
|
|
38
40
|
|
|
39
|
-
const getPlugin = (
|
|
40
|
-
pluginFactory: UnpluginFactory<Partial<Config | (() => Config)>>,
|
|
41
|
-
) => {
|
|
42
|
-
const plugin = pluginFactory(options, meta)
|
|
41
|
+
const getPlugin = (plugin: ReturnType<UnpluginFactory<any>>) => {
|
|
43
42
|
if (!Array.isArray(plugin)) {
|
|
44
43
|
return [plugin]
|
|
45
44
|
}
|
|
46
45
|
return plugin
|
|
47
46
|
}
|
|
48
47
|
|
|
49
|
-
const routerGenerator = getPlugin(
|
|
50
|
-
|
|
48
|
+
const routerGenerator = getPlugin(
|
|
49
|
+
createRouterGeneratorPlugin(options, routerPluginContext),
|
|
50
|
+
)
|
|
51
|
+
const routerCodeSplitter = getPlugin(
|
|
52
|
+
createRouterCodeSplitterPlugin(options, routerPluginContext),
|
|
53
|
+
)
|
|
51
54
|
|
|
52
55
|
const result = [
|
|
53
56
|
{
|
|
@@ -85,7 +88,9 @@ export const unpluginRouterComposedFactory: UnpluginFactory<
|
|
|
85
88
|
const isProduction = process.env.NODE_ENV === 'production'
|
|
86
89
|
|
|
87
90
|
if (!isProduction && !userConfig.autoCodeSplitting) {
|
|
88
|
-
const routerHmr = getPlugin(
|
|
91
|
+
const routerHmr = getPlugin(
|
|
92
|
+
createRouterHmrPlugin(options, routerPluginContext),
|
|
93
|
+
)
|
|
89
94
|
result.push(...routerHmr)
|
|
90
95
|
}
|
|
91
96
|
return result
|
|
@@ -1,17 +1,20 @@
|
|
|
1
1
|
import { isAbsolute, join, normalize } from 'node:path'
|
|
2
2
|
import { Generator, resolveConfigPath } from '@tanstack/router-generator'
|
|
3
3
|
import { getConfig } from './config'
|
|
4
|
+
import { createRouterPluginContext } from './router-plugin-context'
|
|
4
5
|
|
|
5
6
|
import type { GeneratorEvent } from '@tanstack/router-generator'
|
|
6
7
|
import type { FSWatcher } from 'chokidar'
|
|
7
8
|
import type { UnpluginFactory } from 'unplugin'
|
|
8
9
|
import type { Config } from './config'
|
|
10
|
+
import type { RouterPluginContext } from './router-plugin-context'
|
|
9
11
|
|
|
10
12
|
const PLUGIN_NAME = 'unplugin:router-generator'
|
|
11
13
|
|
|
12
|
-
export
|
|
13
|
-
Partial<Config | (() => Config)> | undefined
|
|
14
|
-
|
|
14
|
+
export function createRouterGeneratorPlugin(
|
|
15
|
+
options: Partial<Config | (() => Config)> | undefined = {},
|
|
16
|
+
routerPluginContext: RouterPluginContext,
|
|
17
|
+
): ReturnType<UnpluginFactory<Partial<Config | (() => Config)> | undefined>> {
|
|
15
18
|
let ROOT: string = process.cwd()
|
|
16
19
|
let userConfig: Config
|
|
17
20
|
let generator: Generator
|
|
@@ -58,7 +61,7 @@ export const unpluginRouterGeneratorFactory: UnpluginFactory<
|
|
|
58
61
|
|
|
59
62
|
try {
|
|
60
63
|
await generator.run(generatorEvent)
|
|
61
|
-
|
|
64
|
+
routerPluginContext.routesByFile = generator.getRoutesByFileMap()
|
|
62
65
|
} catch (e) {
|
|
63
66
|
console.error(e)
|
|
64
67
|
}
|
|
@@ -146,3 +149,9 @@ export const unpluginRouterGeneratorFactory: UnpluginFactory<
|
|
|
146
149
|
},
|
|
147
150
|
}
|
|
148
151
|
}
|
|
152
|
+
|
|
153
|
+
export const unpluginRouterGeneratorFactory: UnpluginFactory<
|
|
154
|
+
Partial<Config | (() => Config)> | undefined
|
|
155
|
+
> = (options = {}) => {
|
|
156
|
+
return createRouterGeneratorPlugin(options, createRouterPluginContext())
|
|
157
|
+
}
|