@tanstack/router-plugin 1.43.5 → 1.43.9

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.
@@ -1 +1 @@
1
- {"version":3,"file":"composed.js","sources":["../../src/composed.ts"],"sourcesContent":["import { unpluginRouterGeneratorFactory } from './router-generator'\nimport { unpluginRouterCodeSplitterFactory } from './code-splitter'\n\nimport type { Config } from './config'\nimport type { UnpluginFactory } from 'unplugin'\n\nexport const unpluginRouterComposedFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}, meta) => {\n const routerGenerator = unpluginRouterGeneratorFactory(options, meta)\n\n const routerGeneratorOptions = Array.isArray(routerGenerator)\n ? routerGenerator\n : [routerGenerator]\n\n const routerCodeSplitter = unpluginRouterCodeSplitterFactory(options, meta)\n let routerCodeSplitterOptions = Array.isArray(routerCodeSplitter)\n ? routerCodeSplitter\n : [routerCodeSplitter]\n\n // Rspack doesn't support the `resolveId` and `transform` hooks provided by unplugin\n // so we need to disable the code splitter for it\n // If you're using Rspack, and know how to implement the code splitting, please let us know\n // We'd love to support it, but we're not sure how to do it yet\n if (meta.framework === 'rspack') {\n routerCodeSplitterOptions = []\n }\n\n return [...routerGeneratorOptions, ...routerCodeSplitterOptions]\n}\n"],"names":[],"mappings":";;AAMO,MAAM,gCAET,CAAC,UAAU,IAAI,SAAS;AACpB,QAAA,kBAAkB,+BAA+B,OAAa;AAEpE,QAAM,yBAAyB,MAAM,QAAQ,eAAe,IACxD,kBACA,CAAC,eAAe;AAEd,QAAA,qBAAqB,kCAAkC,SAAS,IAAI;AAC1E,MAAI,4BAA4B,MAAM,QAAQ,kBAAkB,IAC5D,qBACA,CAAC,kBAAkB;AAMnB,MAAA,KAAK,cAAc,UAAU;AAC/B,gCAA4B,CAAA;AAAA,EAC9B;AAEA,SAAO,CAAC,GAAG,wBAAwB,GAAG,yBAAyB;AACjE;"}
1
+ {"version":3,"file":"composed.js","sources":["../../src/composed.ts"],"sourcesContent":["import { unpluginRouterGeneratorFactory } from './router-generator'\nimport { unpluginRouterCodeSplitterFactory } from './code-splitter'\n\nimport type { Config } from './config'\nimport type { UnpluginFactory } from 'unplugin'\n\nexport const unpluginRouterComposedFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}, meta) => {\n const routerGenerator = unpluginRouterGeneratorFactory(options, meta)\n\n const routerGeneratorOptions = Array.isArray(routerGenerator)\n ? routerGenerator\n : [routerGenerator]\n\n const routerCodeSplitter = unpluginRouterCodeSplitterFactory(options, meta)\n const routerCodeSplitterOptions = Array.isArray(routerCodeSplitter)\n ? routerCodeSplitter\n : [routerCodeSplitter]\n\n return [...routerGeneratorOptions, ...routerCodeSplitterOptions]\n}\n"],"names":[],"mappings":";;AAMO,MAAM,gCAET,CAAC,UAAU,IAAI,SAAS;AACpB,QAAA,kBAAkB,+BAA+B,OAAa;AAEpE,QAAM,yBAAyB,MAAM,QAAQ,eAAe,IACxD,kBACA,CAAC,eAAe;AAEd,QAAA,qBAAqB,kCAAkC,SAAS,IAAI;AAC1E,QAAM,4BAA4B,MAAM,QAAQ,kBAAkB,IAC9D,qBACA,CAAC,kBAAkB;AAEvB,SAAO,CAAC,GAAG,wBAAwB,GAAG,yBAAyB;AACjE;"}
@@ -1,4 +1,4 @@
1
- import { normalize, join, resolve, isAbsolute } from "node:path";
1
+ import { isAbsolute, join, normalize, resolve } from "node:path";
2
2
  import { generator } from "@tanstack/router-generator";
3
3
  import { getConfig } from "./config.js";
4
4
  import { CONFIG_FILE_NAME } from "./constants.js";
@@ -11,6 +11,9 @@ const PLUGIN_NAME = "unplugin:router-generator";
11
11
  const unpluginRouterGeneratorFactory = (options = {}) => {
12
12
  let ROOT = process.cwd();
13
13
  let userConfig = options;
14
+ const getRoutesDirectoryPath = () => {
15
+ return isAbsolute(userConfig.routesDirectory) ? userConfig.routesDirectory : join(ROOT, userConfig.routesDirectory);
16
+ };
14
17
  const generate = async () => {
15
18
  if (checkLock()) {
16
19
  return;
@@ -34,7 +37,7 @@ const unpluginRouterGeneratorFactory = (options = {}) => {
34
37
  if (event === "update" && filePath === resolve(userConfig.generatedRouteTree)) {
35
38
  return;
36
39
  }
37
- const routesDirectoryPath = isAbsolute(userConfig.routesDirectory) ? userConfig.routesDirectory : join(ROOT, userConfig.routesDirectory);
40
+ const routesDirectoryPath = getRoutesDirectoryPath();
38
41
  if (filePath.startsWith(routesDirectoryPath)) {
39
42
  await generate();
40
43
  }
@@ -60,10 +63,35 @@ const unpluginRouterGeneratorFactory = (options = {}) => {
60
63
  },
61
64
  async rspack(compiler) {
62
65
  userConfig = await getConfig(options, ROOT);
63
- await run(generate);
64
- compiler.hooks.watchRun.tap(PLUGIN_NAME, async () => {
66
+ if (compiler.options.mode === "production") {
65
67
  await run(generate);
66
- });
68
+ } else {
69
+ const routesDirectoryPath = getRoutesDirectoryPath();
70
+ const chokidar = await import("chokidar");
71
+ chokidar.watch(routesDirectoryPath).on("add", async () => {
72
+ await run(generate);
73
+ });
74
+ }
75
+ },
76
+ async webpack(compiler) {
77
+ userConfig = await getConfig(options, ROOT);
78
+ if (compiler.options.mode === "production") {
79
+ await run(generate);
80
+ } else {
81
+ const routesDirectoryPath = getRoutesDirectoryPath();
82
+ const chokidar = await import("chokidar");
83
+ chokidar.watch(routesDirectoryPath).on("add", async () => {
84
+ await run(generate);
85
+ });
86
+ }
87
+ if (compiler.options.mode === "production") {
88
+ compiler.hooks.done.tap(PLUGIN_NAME, (stats) => {
89
+ console.log("✅ " + PLUGIN_NAME + ": route-tree generation done");
90
+ setTimeout(() => {
91
+ process.exit(0);
92
+ });
93
+ });
94
+ }
67
95
  }
68
96
  };
69
97
  };
@@ -1 +1 @@
1
- {"version":3,"file":"router-generator.js","sources":["../../src/router-generator.ts"],"sourcesContent":["import { isAbsolute, join, normalize, resolve } from 'node:path'\nimport { generator } from '@tanstack/router-generator'\n\nimport { getConfig } from './config'\nimport { CONFIG_FILE_NAME } from './constants'\nimport type { UnpluginFactory } from 'unplugin'\nimport type { Config } from './config'\n\nlet lock = false\nconst checkLock = () => lock\nconst setLock = (bool: boolean) => {\n lock = bool\n}\n\nconst PLUGIN_NAME = 'unplugin:router-generator'\n\nexport const unpluginRouterGeneratorFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}) => {\n let ROOT: string = process.cwd()\n let userConfig = options as Config\n\n const generate = async () => {\n if (checkLock()) {\n return\n }\n\n setLock(true)\n\n try {\n await generator(userConfig)\n } catch (err) {\n console.error(err)\n console.info()\n } finally {\n setLock(false)\n }\n }\n\n const handleFile = async (\n file: string,\n event: 'create' | 'update' | 'delete',\n ) => {\n const filePath = normalize(file)\n\n if (filePath === join(ROOT, CONFIG_FILE_NAME)) {\n userConfig = await getConfig(options, ROOT)\n return\n }\n\n if (\n event === 'update' &&\n filePath === resolve(userConfig.generatedRouteTree)\n ) {\n // skip generating routes if the generated route tree is updated\n return\n }\n\n const routesDirectoryPath = isAbsolute(userConfig.routesDirectory)\n ? userConfig.routesDirectory\n : join(ROOT, userConfig.routesDirectory)\n\n if (filePath.startsWith(routesDirectoryPath)) {\n await generate()\n }\n }\n\n const run: (cb: () => Promise<void> | void) => Promise<void> = async (cb) => {\n if (userConfig.enableRouteGeneration ?? true) {\n await cb()\n }\n }\n\n return {\n name: 'router-generator-plugin',\n async watchChange(id, { event }) {\n await run(async () => {\n await handleFile(id, event)\n })\n },\n vite: {\n async configResolved(config) {\n ROOT = config.root\n userConfig = await getConfig(options, ROOT)\n\n await run(generate)\n },\n },\n async rspack(compiler) {\n userConfig = await getConfig(options, ROOT)\n\n await run(generate)\n\n compiler.hooks.watchRun.tap(PLUGIN_NAME, async () => {\n await run(generate)\n })\n },\n }\n}\n"],"names":[],"mappings":";;;;AAQA,IAAI,OAAO;AACX,MAAM,YAAY,MAAM;AACxB,MAAM,UAAU,CAAC,SAAkB;AAC1B,SAAA;AACT;AAEA,MAAM,cAAc;AAEb,MAAM,iCAET,CAAC,UAAU,OAAO;AAChB,MAAA,OAAe,QAA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,MAAA,CACnB;AAAA,IACH;AAAA,EAAA;AAEJ;"}
1
+ {"version":3,"file":"router-generator.js","sources":["../../src/router-generator.ts"],"sourcesContent":["import { isAbsolute, join, normalize, resolve } from 'node:path'\nimport { generator } from '@tanstack/router-generator'\n\nimport { getConfig } from './config'\nimport { CONFIG_FILE_NAME } from './constants'\nimport type { UnpluginFactory } from 'unplugin'\nimport type { Config } from './config'\n\nlet lock = false\nconst checkLock = () => lock\nconst setLock = (bool: boolean) => {\n lock = bool\n}\n\nconst PLUGIN_NAME = 'unplugin:router-generator'\n\nexport const unpluginRouterGeneratorFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}) => {\n let ROOT: string = process.cwd()\n let userConfig = options as Config\n\n const getRoutesDirectoryPath = () => {\n return isAbsolute(userConfig.routesDirectory)\n ? userConfig.routesDirectory\n : join(ROOT, userConfig.routesDirectory)\n }\n\n const generate = async () => {\n if (checkLock()) {\n return\n }\n\n setLock(true)\n\n try {\n await generator(userConfig)\n } catch (err) {\n console.error(err)\n console.info()\n } finally {\n setLock(false)\n }\n }\n\n const handleFile = async (\n file: string,\n event: 'create' | 'update' | 'delete',\n ) => {\n const filePath = normalize(file)\n\n if (filePath === join(ROOT, CONFIG_FILE_NAME)) {\n userConfig = await getConfig(options, ROOT)\n return\n }\n\n if (\n event === 'update' &&\n filePath === resolve(userConfig.generatedRouteTree)\n ) {\n // skip generating routes if the generated route tree is updated\n return\n }\n\n const routesDirectoryPath = getRoutesDirectoryPath()\n if (filePath.startsWith(routesDirectoryPath)) {\n await generate()\n }\n }\n\n const run: (cb: () => Promise<void> | void) => Promise<void> = async (cb) => {\n if (userConfig.enableRouteGeneration ?? true) {\n await cb()\n }\n }\n\n return {\n name: 'router-generator-plugin',\n async watchChange(id, { event }) {\n await run(async () => {\n await handleFile(id, event)\n })\n },\n vite: {\n async configResolved(config) {\n ROOT = config.root\n userConfig = await getConfig(options, ROOT)\n\n await run(generate)\n },\n },\n async rspack(compiler) {\n userConfig = await getConfig(options, ROOT)\n\n // rspack watcher doesn't register newly created files\n if (compiler.options.mode === 'production') {\n await run(generate)\n } else {\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n chokidar.watch(routesDirectoryPath).on('add', async () => {\n await run(generate)\n })\n }\n },\n async webpack(compiler) {\n userConfig = await getConfig(options, ROOT)\n\n // webpack watcher doesn't register newly created files\n if (compiler.options.mode === 'production') {\n await run(generate)\n } else {\n const routesDirectoryPath = getRoutesDirectoryPath()\n const chokidar = await import('chokidar')\n chokidar.watch(routesDirectoryPath).on('add', async () => {\n await run(generate)\n })\n }\n\n if (compiler.options.mode === 'production') {\n compiler.hooks.done.tap(PLUGIN_NAME, (stats) => {\n console.log('✅ ' + PLUGIN_NAME + ': route-tree generation done')\n setTimeout(() => {\n process.exit(0)\n })\n })\n }\n },\n }\n}\n"],"names":[],"mappings":";;;;AAQA,IAAI,OAAO;AACX,MAAM,YAAY,MAAM;AACxB,MAAM,UAAU,CAAC,SAAkB;AAC1B,SAAA;AACT;AAEA,MAAM,cAAc;AAEb,MAAM,iCAET,CAAC,UAAU,OAAO;AAChB,MAAA,OAAe,QAAQ;AAC3B,MAAI,aAAa;AAEjB,QAAM,yBAAyB,MAAM;AAC5B,WAAA,WAAW,WAAW,eAAe,IACxC,WAAW,kBACX,KAAK,MAAM,WAAW,eAAe;AAAA,EAAA;AAG3C,QAAM,WAAW,YAAY;AAC3B,QAAI,aAAa;AACf;AAAA,IACF;AAEA,YAAQ,IAAI;AAER,QAAA;AACF,YAAM,UAAU,UAAU;AAAA,aACnB,KAAK;AACZ,cAAQ,MAAM,GAAG;AACjB,cAAQ,KAAK;AAAA,IAAA,UACb;AACA,cAAQ,KAAK;AAAA,IACf;AAAA,EAAA;AAGI,QAAA,aAAa,OACjB,MACA,UACG;AACG,UAAA,WAAW,UAAU,IAAI;AAE/B,QAAI,aAAa,KAAK,MAAM,gBAAgB,GAAG;AAChC,mBAAA,MAAM,UAAU,SAAS,IAAI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MACH;AAEI,UAAA,SAAS,QAAQ,SAAS,cAAc;AAC1C,iBAAS,MAAM,KAAK,IAAI,aAAa,CAAC,UAAU;AACtC,kBAAA,IAAI,OAAO,cAAc,8BAA8B;AAC/D,qBAAW,MAAM;AACf,oBAAQ,KAAK,CAAC;AAAA,UAAA,CACf;AAAA,QAAA,CACF;AAAA,MACH;AAAA,IACF;AAAA,EAAA;AAEJ;"}
@@ -32,28 +32,19 @@ declare const TanStackRouterGeneratorRspack: (options?: Partial<{
32
32
  routeFileIgnorePattern?: string | undefined;
33
33
  }> | undefined) => _rspack_core_dist_config_zod.RspackPluginInstance;
34
34
  /**
35
- * @experimental Do not use this plugin yet
36
- *
37
- * Unplugin's Rspack integration doesn't support the `resolveId` and `transform` hooks.
38
- * The code-splitter won't work with Rspack and will probably break your dev and build.
39
- *
40
- * If you're familiar with Rspack and know how to overcome our `resolveId` and `transform`
41
- * limitations, please let us know.
42
- * We'd love to support it, but we're not sure how to do it yet 😅.
43
- *
44
35
  * @example
45
36
  * ```ts
46
37
  * export default defineConfig({
47
38
  * // ...
48
39
  * tools: {
49
40
  * rspack: {
50
- * plugins: [unstable_TanStackRouterCodeSplitterRspack()],
41
+ * plugins: [TanStackRouterCodeSplitterRspack()],
51
42
  * },
52
43
  * },
53
44
  * })
54
45
  * ```
55
46
  */
56
- declare const unstable_TanStackRouterCodeSplitterRspack: (options?: Partial<{
47
+ declare const TanStackRouterCodeSplitterRspack: (options?: Partial<{
57
48
  routeFileIgnorePrefix: string;
58
49
  routesDirectory: string;
59
50
  generatedRouteTree: string;
@@ -103,5 +94,5 @@ declare const TanStackRouterRspack: (options?: Partial<{
103
94
  routeFileIgnorePattern?: string | undefined;
104
95
  }> | undefined) => _rspack_core_dist_config_zod.RspackPluginInstance;
105
96
  export default TanStackRouterRspack;
106
- export { configSchema, TanStackRouterRspack, TanStackRouterGeneratorRspack, unstable_TanStackRouterCodeSplitterRspack, };
97
+ export { configSchema, TanStackRouterRspack, TanStackRouterGeneratorRspack, TanStackRouterCodeSplitterRspack, };
107
98
  export type { Config };
@@ -6,15 +6,17 @@ import { unpluginRouterComposedFactory } from "./composed.js";
6
6
  const TanStackRouterGeneratorRspack = /* @__PURE__ */ createRspackPlugin(
7
7
  unpluginRouterGeneratorFactory
8
8
  );
9
- const unstable_TanStackRouterCodeSplitterRspack = /* @__PURE__ */ createRspackPlugin(unpluginRouterCodeSplitterFactory);
9
+ const TanStackRouterCodeSplitterRspack = /* @__PURE__ */ createRspackPlugin(
10
+ unpluginRouterCodeSplitterFactory
11
+ );
10
12
  const TanStackRouterRspack = /* @__PURE__ */ createRspackPlugin(
11
13
  unpluginRouterComposedFactory
12
14
  );
13
15
  export {
16
+ TanStackRouterCodeSplitterRspack,
14
17
  TanStackRouterGeneratorRspack,
15
18
  TanStackRouterRspack,
16
19
  configSchema,
17
- TanStackRouterRspack as default,
18
- unstable_TanStackRouterCodeSplitterRspack
20
+ TanStackRouterRspack as default
19
21
  };
20
22
  //# sourceMappingURL=rspack.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"rspack.js","sources":["../../src/rspack.ts"],"sourcesContent":["import { createRspackPlugin } from 'unplugin'\nimport { unpluginRouterCodeSplitterFactory } from './code-splitter'\nimport { configSchema } from './config'\nimport { unpluginRouterGeneratorFactory } from './router-generator'\nimport { unpluginRouterComposedFactory } from './composed'\nimport type { Config } from './config'\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 * @experimental Do not use this plugin yet\n *\n * Unplugin's Rspack integration doesn't support the `resolveId` and `transform` hooks.\n * The code-splitter won't work with Rspack and will probably break your dev and build.\n *\n * If you're familiar with Rspack and know how to overcome our `resolveId` and `transform`\n * limitations, please let us know.\n * We'd love to support it, but we're not sure how to do it yet 😅.\n *\n * @example\n * ```ts\n * export default defineConfig({\n * // ...\n * tools: {\n * rspack: {\n * plugins: [unstable_TanStackRouterCodeSplitterRspack()],\n * },\n * },\n * })\n * ```\n */\nconst unstable_TanStackRouterCodeSplitterRspack =\n /* #__PURE__ */ createRspackPlugin(unpluginRouterCodeSplitterFactory)\n\n/**\n * @example\n * ```ts\n * export default defineConfig({\n * // ...\n * tools: {\n * rspack: {\n * plugins: [TanStackRouterRspack()],\n * },\n * },\n * })\n * ```\n */\nconst TanStackRouterRspack = /* #__PURE__ */ createRspackPlugin(\n unpluginRouterComposedFactory,\n)\n\nexport default TanStackRouterRspack\nexport {\n configSchema,\n TanStackRouterRspack,\n TanStackRouterGeneratorRspack,\n unstable_TanStackRouterCodeSplitterRspack,\n}\nexport type { Config }\n"],"names":[],"mappings":";;;;;AAoBA,MAAM,gCAAgD;AAAA,EACpD;AACF;AAwBM,MAAA,+EAC+B,iCAAiC;AAetE,MAAM,uBAAuC;AAAA,EAC3C;AACF;"}
1
+ {"version":3,"file":"rspack.js","sources":["../../src/rspack.ts"],"sourcesContent":["import { createRspackPlugin } from 'unplugin'\nimport { unpluginRouterCodeSplitterFactory } from './code-splitter'\nimport { configSchema } from './config'\nimport { unpluginRouterGeneratorFactory } from './router-generator'\nimport { unpluginRouterComposedFactory } from './composed'\nimport type { Config } from './config'\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 unpluginRouterCodeSplitterFactory,\n)\n\n/**\n * @example\n * ```ts\n * export default defineConfig({\n * // ...\n * tools: {\n * rspack: {\n * plugins: [TanStackRouterRspack()],\n * },\n * },\n * })\n * ```\n */\nconst TanStackRouterRspack = /* #__PURE__ */ createRspackPlugin(\n unpluginRouterComposedFactory,\n)\n\nexport default TanStackRouterRspack\nexport {\n configSchema,\n TanStackRouterRspack,\n TanStackRouterGeneratorRspack,\n TanStackRouterCodeSplitterRspack,\n}\nexport type { Config }\n"],"names":[],"mappings":";;;;;AAoBA,MAAM,gCAAgD;AAAA,EACpD;AACF;AAeA,MAAM,mCAAmD;AAAA,EACvD;AACF;AAeA,MAAM,uBAAuC;AAAA,EAC3C;AACF;"}
@@ -0,0 +1,86 @@
1
+ import { configSchema, Config } from './config.js';
2
+
3
+ /**
4
+ * @example
5
+ * ```ts
6
+ * export default {
7
+ * // ...
8
+ * plugins: [TanStackRouterGeneratorWebpack()],
9
+ * }
10
+ * ```
11
+ */
12
+ declare const TanStackRouterGeneratorWebpack: (options?: Partial<{
13
+ routeFileIgnorePrefix: string;
14
+ routesDirectory: string;
15
+ generatedRouteTree: string;
16
+ quoteStyle: "single" | "double";
17
+ semicolons: boolean;
18
+ disableTypes: boolean;
19
+ addExtensions: boolean;
20
+ disableLogging: boolean;
21
+ routeTreeFileHeader: string[];
22
+ routeTreeFileFooter: string[];
23
+ enableRouteGeneration?: boolean | undefined;
24
+ experimental?: {
25
+ enableCodeSplitting?: boolean | undefined;
26
+ } | undefined;
27
+ routeFilePrefix?: string | undefined;
28
+ routeFileIgnorePattern?: string | undefined;
29
+ }> | undefined) => import('unplugin').WebpackPluginInstance;
30
+ /**
31
+ * @example
32
+ * ```ts
33
+ * export default {
34
+ * // ...
35
+ * plugins: [TanStackRouterCodeSplitterWebpack()],
36
+ * }
37
+ * ```
38
+ */
39
+ declare const TanStackRouterCodeSplitterWebpack: (options?: Partial<{
40
+ routeFileIgnorePrefix: string;
41
+ routesDirectory: string;
42
+ generatedRouteTree: string;
43
+ quoteStyle: "single" | "double";
44
+ semicolons: boolean;
45
+ disableTypes: boolean;
46
+ addExtensions: boolean;
47
+ disableLogging: boolean;
48
+ routeTreeFileHeader: string[];
49
+ routeTreeFileFooter: string[];
50
+ enableRouteGeneration?: boolean | undefined;
51
+ experimental?: {
52
+ enableCodeSplitting?: boolean | undefined;
53
+ } | undefined;
54
+ routeFilePrefix?: string | undefined;
55
+ routeFileIgnorePattern?: string | undefined;
56
+ }> | undefined) => import('unplugin').WebpackPluginInstance;
57
+ /**
58
+ * @example
59
+ * ```ts
60
+ * export default {
61
+ * // ...
62
+ * plugins: [TanStackRouterWebpack()],
63
+ * }
64
+ * ```
65
+ */
66
+ declare const TanStackRouterWebpack: (options?: Partial<{
67
+ routeFileIgnorePrefix: string;
68
+ routesDirectory: string;
69
+ generatedRouteTree: string;
70
+ quoteStyle: "single" | "double";
71
+ semicolons: boolean;
72
+ disableTypes: boolean;
73
+ addExtensions: boolean;
74
+ disableLogging: boolean;
75
+ routeTreeFileHeader: string[];
76
+ routeTreeFileFooter: string[];
77
+ enableRouteGeneration?: boolean | undefined;
78
+ experimental?: {
79
+ enableCodeSplitting?: boolean | undefined;
80
+ } | undefined;
81
+ routeFilePrefix?: string | undefined;
82
+ routeFileIgnorePattern?: string | undefined;
83
+ }> | undefined) => import('unplugin').WebpackPluginInstance;
84
+ export default TanStackRouterWebpack;
85
+ export { configSchema, TanStackRouterWebpack, TanStackRouterGeneratorWebpack, TanStackRouterCodeSplitterWebpack, };
86
+ export type { Config };
@@ -0,0 +1,22 @@
1
+ import { createWebpackPlugin } from "unplugin";
2
+ import { unpluginRouterCodeSplitterFactory } from "./code-splitter.js";
3
+ import { configSchema } from "./config.js";
4
+ import { unpluginRouterGeneratorFactory } from "./router-generator.js";
5
+ import { unpluginRouterComposedFactory } from "./composed.js";
6
+ const TanStackRouterGeneratorWebpack = /* @__PURE__ */ createWebpackPlugin(
7
+ unpluginRouterGeneratorFactory
8
+ );
9
+ const TanStackRouterCodeSplitterWebpack = /* @__PURE__ */ createWebpackPlugin(
10
+ unpluginRouterCodeSplitterFactory
11
+ );
12
+ const TanStackRouterWebpack = /* @__PURE__ */ createWebpackPlugin(
13
+ unpluginRouterComposedFactory
14
+ );
15
+ export {
16
+ TanStackRouterCodeSplitterWebpack,
17
+ TanStackRouterGeneratorWebpack,
18
+ TanStackRouterWebpack,
19
+ configSchema,
20
+ TanStackRouterWebpack as default
21
+ };
22
+ //# sourceMappingURL=webpack.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"webpack.js","sources":["../../src/webpack.ts"],"sourcesContent":["import { createWebpackPlugin } from 'unplugin'\nimport { unpluginRouterCodeSplitterFactory } from './code-splitter'\nimport { configSchema } from './config'\nimport { unpluginRouterGeneratorFactory } from './router-generator'\nimport { unpluginRouterComposedFactory } from './composed'\nimport type { Config } from './config'\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 unpluginRouterCodeSplitterFactory,\n)\n\n/**\n * @example\n * ```ts\n * export default {\n * // ...\n * plugins: [TanStackRouterWebpack()],\n * }\n * ```\n */\nconst TanStackRouterWebpack = /* #__PURE__ */ createWebpackPlugin(\n unpluginRouterComposedFactory,\n)\n\nexport default TanStackRouterWebpack\nexport {\n configSchema,\n TanStackRouterWebpack,\n TanStackRouterGeneratorWebpack,\n TanStackRouterCodeSplitterWebpack,\n}\nexport type { Config }\n"],"names":[],"mappings":";;;;;AAgBA,MAAM,iCAAiD;AAAA,EACrD;AACF;AAWA,MAAM,oCAAoD;AAAA,EACxD;AACF;AAWA,MAAM,wBAAwC;AAAA,EAC5C;AACF;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/router-plugin",
3
- "version": "1.43.5",
3
+ "version": "1.43.9",
4
4
  "description": "",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -46,6 +46,16 @@
46
46
  "default": "./dist/cjs/rspack.cjs"
47
47
  }
48
48
  },
49
+ "./webpack": {
50
+ "import": {
51
+ "types": "./dist/esm/webpack.d.ts",
52
+ "default": "./dist/esm/webpack.js"
53
+ },
54
+ "require": {
55
+ "types": "./dist/cjs/webpack.d.cts",
56
+ "default": "./dist/cjs/webpack.cjs"
57
+ }
58
+ },
49
59
  "./package.json": "./package.json"
50
60
  },
51
61
  "sideEffects": false,
@@ -67,7 +77,8 @@
67
77
  ],
68
78
  "peerDependencies": {
69
79
  "@rsbuild/core": ">=0.7.9",
70
- "vite": ">=5.0.13"
80
+ "vite": ">=5.0.13",
81
+ "webpack": ">=5.92.0"
71
82
  },
72
83
  "peerDependenciesMeta": {
73
84
  "vite": {
@@ -75,6 +86,9 @@
75
86
  },
76
87
  "@rsbuild/core": {
77
88
  "optional": true
89
+ },
90
+ "webpack": {
91
+ "optional": true
78
92
  }
79
93
  },
80
94
  "dependencies": {
@@ -91,7 +105,8 @@
91
105
  "@types/babel__template": "^7.4.4",
92
106
  "@types/babel__traverse": "^7.20.6",
93
107
  "babel-dead-code-elimination": "^1.0.6",
94
- "unplugin": "^1.10.2",
108
+ "chokidar": "^3.5.3",
109
+ "unplugin": "^1.11.0",
95
110
  "zod": "^3.22.4",
96
111
  "@tanstack/router-generator": "^1.43.1"
97
112
  },
@@ -52,6 +52,7 @@ plugins: [
52
52
  }
53
53
 
54
54
  const PLUGIN_NAME = 'unplugin:router-code-splitter'
55
+ const JoinedSplitPrefix = splitPrefix + ':'
55
56
 
56
57
  export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
57
58
  Partial<Config> | undefined
@@ -77,11 +78,6 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
77
78
  if (debug) console.info('')
78
79
  if (debug) console.info('')
79
80
  if (debug) console.info('')
80
- if (debug) console.info('')
81
- if (debug) console.info('')
82
- if (debug) console.info('')
83
- if (debug) console.info('')
84
- if (debug) console.info('')
85
81
 
86
82
  return compiledVirtualRoute
87
83
  }
@@ -102,13 +98,6 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
102
98
  if (debug) console.info('')
103
99
  if (debug) console.info('')
104
100
  if (debug) console.info('')
105
- if (debug) console.info('')
106
- if (debug) console.info('')
107
- if (debug) console.info('')
108
- if (debug) console.info('')
109
- if (debug) console.info('')
110
- if (debug) console.info('')
111
- if (debug) console.info('')
112
101
 
113
102
  return compiledReferenceRoute
114
103
  }
@@ -159,6 +148,26 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
159
148
  return null
160
149
  },
161
150
 
151
+ transformInclude(transformId) {
152
+ if (!userConfig.experimental?.enableCodeSplitting) {
153
+ return undefined
154
+ }
155
+
156
+ let id = transformId
157
+
158
+ if (id.startsWith(JoinedSplitPrefix)) {
159
+ id = id.replace(JoinedSplitPrefix, '')
160
+ }
161
+
162
+ if (
163
+ fileIsInRoutesDirectory(id, userConfig.routesDirectory) ||
164
+ id.includes(splitPrefix)
165
+ ) {
166
+ return true
167
+ }
168
+ return false
169
+ },
170
+
162
171
  vite: {
163
172
  async configResolved(config) {
164
173
  ROOT = config.root
@@ -167,7 +176,55 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
167
176
  },
168
177
 
169
178
  async rspack(compiler) {
179
+ ROOT = process.cwd()
180
+
181
+ compiler.hooks.beforeCompile.tap(PLUGIN_NAME, (self) => {
182
+ self.normalModuleFactory.hooks.beforeResolve.tap(
183
+ PLUGIN_NAME,
184
+ (resolveData) => {
185
+ if (resolveData.request.includes(JoinedSplitPrefix)) {
186
+ resolveData.request = resolveData.request.replace(
187
+ JoinedSplitPrefix,
188
+ '',
189
+ )
190
+ }
191
+ },
192
+ )
193
+ })
194
+
170
195
  userConfig = await getConfig(options, ROOT)
171
196
  },
197
+
198
+ async webpack(compiler) {
199
+ ROOT = process.cwd()
200
+
201
+ compiler.hooks.beforeCompile.tap(PLUGIN_NAME, (self) => {
202
+ self.normalModuleFactory.hooks.beforeResolve.tap(
203
+ PLUGIN_NAME,
204
+ (resolveData) => {
205
+ if (resolveData.request.includes(JoinedSplitPrefix)) {
206
+ resolveData.request = resolveData.request.replace(
207
+ JoinedSplitPrefix,
208
+ '',
209
+ )
210
+ }
211
+ },
212
+ )
213
+ })
214
+
215
+ userConfig = await getConfig(options, ROOT)
216
+
217
+ if (
218
+ userConfig.experimental?.enableCodeSplitting &&
219
+ compiler.options.mode === 'production'
220
+ ) {
221
+ compiler.hooks.done.tap(PLUGIN_NAME, (stats) => {
222
+ console.log('✅ ' + PLUGIN_NAME + ': code-splitting done!')
223
+ setTimeout(() => {
224
+ process.exit(0)
225
+ })
226
+ })
227
+ }
228
+ },
172
229
  }
173
230
  }
package/src/composed.ts CHANGED
@@ -14,17 +14,9 @@ export const unpluginRouterComposedFactory: UnpluginFactory<
14
14
  : [routerGenerator]
15
15
 
16
16
  const routerCodeSplitter = unpluginRouterCodeSplitterFactory(options, meta)
17
- let routerCodeSplitterOptions = Array.isArray(routerCodeSplitter)
17
+ const routerCodeSplitterOptions = Array.isArray(routerCodeSplitter)
18
18
  ? routerCodeSplitter
19
19
  : [routerCodeSplitter]
20
20
 
21
- // Rspack doesn't support the `resolveId` and `transform` hooks provided by unplugin
22
- // so we need to disable the code splitter for it
23
- // If you're using Rspack, and know how to implement the code splitting, please let us know
24
- // We'd love to support it, but we're not sure how to do it yet
25
- if (meta.framework === 'rspack') {
26
- routerCodeSplitterOptions = []
27
- }
28
-
29
21
  return [...routerGeneratorOptions, ...routerCodeSplitterOptions]
30
22
  }
@@ -20,6 +20,12 @@ export const unpluginRouterGeneratorFactory: UnpluginFactory<
20
20
  let ROOT: string = process.cwd()
21
21
  let userConfig = options as Config
22
22
 
23
+ const getRoutesDirectoryPath = () => {
24
+ return isAbsolute(userConfig.routesDirectory)
25
+ ? userConfig.routesDirectory
26
+ : join(ROOT, userConfig.routesDirectory)
27
+ }
28
+
23
29
  const generate = async () => {
24
30
  if (checkLock()) {
25
31
  return
@@ -56,10 +62,7 @@ export const unpluginRouterGeneratorFactory: UnpluginFactory<
56
62
  return
57
63
  }
58
64
 
59
- const routesDirectoryPath = isAbsolute(userConfig.routesDirectory)
60
- ? userConfig.routesDirectory
61
- : join(ROOT, userConfig.routesDirectory)
62
-
65
+ const routesDirectoryPath = getRoutesDirectoryPath()
63
66
  if (filePath.startsWith(routesDirectoryPath)) {
64
67
  await generate()
65
68
  }
@@ -89,11 +92,39 @@ export const unpluginRouterGeneratorFactory: UnpluginFactory<
89
92
  async rspack(compiler) {
90
93
  userConfig = await getConfig(options, ROOT)
91
94
 
92
- await run(generate)
95
+ // rspack watcher doesn't register newly created files
96
+ if (compiler.options.mode === 'production') {
97
+ await run(generate)
98
+ } else {
99
+ const routesDirectoryPath = getRoutesDirectoryPath()
100
+ const chokidar = await import('chokidar')
101
+ chokidar.watch(routesDirectoryPath).on('add', async () => {
102
+ await run(generate)
103
+ })
104
+ }
105
+ },
106
+ async webpack(compiler) {
107
+ userConfig = await getConfig(options, ROOT)
93
108
 
94
- compiler.hooks.watchRun.tap(PLUGIN_NAME, async () => {
109
+ // webpack watcher doesn't register newly created files
110
+ if (compiler.options.mode === 'production') {
95
111
  await run(generate)
96
- })
112
+ } else {
113
+ const routesDirectoryPath = getRoutesDirectoryPath()
114
+ const chokidar = await import('chokidar')
115
+ chokidar.watch(routesDirectoryPath).on('add', async () => {
116
+ await run(generate)
117
+ })
118
+ }
119
+
120
+ if (compiler.options.mode === 'production') {
121
+ compiler.hooks.done.tap(PLUGIN_NAME, (stats) => {
122
+ console.log('✅ ' + PLUGIN_NAME + ': route-tree generation done')
123
+ setTimeout(() => {
124
+ process.exit(0)
125
+ })
126
+ })
127
+ }
97
128
  },
98
129
  }
99
130
  }
package/src/rspack.ts CHANGED
@@ -23,29 +23,21 @@ const TanStackRouterGeneratorRspack = /* #__PURE__ */ createRspackPlugin(
23
23
  )
24
24
 
25
25
  /**
26
- * @experimental Do not use this plugin yet
27
- *
28
- * Unplugin's Rspack integration doesn't support the `resolveId` and `transform` hooks.
29
- * The code-splitter won't work with Rspack and will probably break your dev and build.
30
- *
31
- * If you're familiar with Rspack and know how to overcome our `resolveId` and `transform`
32
- * limitations, please let us know.
33
- * We'd love to support it, but we're not sure how to do it yet 😅.
34
- *
35
26
  * @example
36
27
  * ```ts
37
28
  * export default defineConfig({
38
29
  * // ...
39
30
  * tools: {
40
31
  * rspack: {
41
- * plugins: [unstable_TanStackRouterCodeSplitterRspack()],
32
+ * plugins: [TanStackRouterCodeSplitterRspack()],
42
33
  * },
43
34
  * },
44
35
  * })
45
36
  * ```
46
37
  */
47
- const unstable_TanStackRouterCodeSplitterRspack =
48
- /* #__PURE__ */ createRspackPlugin(unpluginRouterCodeSplitterFactory)
38
+ const TanStackRouterCodeSplitterRspack = /* #__PURE__ */ createRspackPlugin(
39
+ unpluginRouterCodeSplitterFactory,
40
+ )
49
41
 
50
42
  /**
51
43
  * @example
@@ -69,6 +61,6 @@ export {
69
61
  configSchema,
70
62
  TanStackRouterRspack,
71
63
  TanStackRouterGeneratorRspack,
72
- unstable_TanStackRouterCodeSplitterRspack,
64
+ TanStackRouterCodeSplitterRspack,
73
65
  }
74
66
  export type { Config }
package/src/webpack.ts ADDED
@@ -0,0 +1,54 @@
1
+ import { createWebpackPlugin } from 'unplugin'
2
+ import { unpluginRouterCodeSplitterFactory } from './code-splitter'
3
+ import { configSchema } from './config'
4
+ import { unpluginRouterGeneratorFactory } from './router-generator'
5
+ import { unpluginRouterComposedFactory } from './composed'
6
+ import type { Config } from './config'
7
+
8
+ /**
9
+ * @example
10
+ * ```ts
11
+ * export default {
12
+ * // ...
13
+ * plugins: [TanStackRouterGeneratorWebpack()],
14
+ * }
15
+ * ```
16
+ */
17
+ const TanStackRouterGeneratorWebpack = /* #__PURE__ */ createWebpackPlugin(
18
+ unpluginRouterGeneratorFactory,
19
+ )
20
+
21
+ /**
22
+ * @example
23
+ * ```ts
24
+ * export default {
25
+ * // ...
26
+ * plugins: [TanStackRouterCodeSplitterWebpack()],
27
+ * }
28
+ * ```
29
+ */
30
+ const TanStackRouterCodeSplitterWebpack = /* #__PURE__ */ createWebpackPlugin(
31
+ unpluginRouterCodeSplitterFactory,
32
+ )
33
+
34
+ /**
35
+ * @example
36
+ * ```ts
37
+ * export default {
38
+ * // ...
39
+ * plugins: [TanStackRouterWebpack()],
40
+ * }
41
+ * ```
42
+ */
43
+ const TanStackRouterWebpack = /* #__PURE__ */ createWebpackPlugin(
44
+ unpluginRouterComposedFactory,
45
+ )
46
+
47
+ export default TanStackRouterWebpack
48
+ export {
49
+ configSchema,
50
+ TanStackRouterWebpack,
51
+ TanStackRouterGeneratorWebpack,
52
+ TanStackRouterCodeSplitterWebpack,
53
+ }
54
+ export type { Config }