@tanstack/router-plugin 1.39.5 → 1.39.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.
- package/dist/cjs/code-splitter.cjs +3 -0
- package/dist/cjs/code-splitter.cjs.map +1 -1
- package/dist/cjs/composed.cjs +16 -0
- package/dist/cjs/composed.cjs.map +1 -0
- package/dist/cjs/composed.d.cts +4 -0
- package/dist/cjs/router-generator.cjs +8 -0
- package/dist/cjs/router-generator.cjs.map +1 -1
- package/dist/cjs/router-generator.d.cts +1 -1
- package/dist/cjs/rspack.cjs +20 -0
- package/dist/cjs/rspack.cjs.map +1 -0
- package/dist/cjs/rspack.d.cts +107 -0
- package/dist/cjs/vite.cjs +2 -6
- package/dist/cjs/vite.cjs.map +1 -1
- package/dist/cjs/vite.d.cts +47 -4
- package/dist/esm/code-splitter.js +3 -0
- package/dist/esm/code-splitter.js.map +1 -1
- package/dist/esm/composed.d.ts +4 -0
- package/dist/esm/composed.js +16 -0
- package/dist/esm/composed.js.map +1 -0
- package/dist/esm/router-generator.d.ts +1 -1
- package/dist/esm/router-generator.js +8 -0
- package/dist/esm/router-generator.js.map +1 -1
- package/dist/esm/rspack.d.ts +107 -0
- package/dist/esm/rspack.js +20 -0
- package/dist/esm/rspack.js.map +1 -0
- package/dist/esm/vite.d.ts +47 -4
- package/dist/esm/vite.js +2 -6
- package/dist/esm/vite.js.map +1 -1
- package/package.json +16 -2
- package/src/code-splitter.ts +9 -0
- package/src/composed.ts +30 -0
- package/src/router-generator.ts +12 -1
- package/src/rspack.ts +74 -0
- package/src/vite.ts +30 -7
|
@@ -155,6 +155,9 @@ const unpluginRouterCodeSplitterFactory = (options = {}, { framework }) => {
|
|
|
155
155
|
ROOT = config$1.root;
|
|
156
156
|
userConfig = await config.getConfig(options, ROOT);
|
|
157
157
|
}
|
|
158
|
+
},
|
|
159
|
+
async rspack(compiler) {
|
|
160
|
+
userConfig = await config.getConfig(options, ROOT);
|
|
158
161
|
}
|
|
159
162
|
};
|
|
160
163
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-splitter.cjs","sources":["../../src/code-splitter.ts"],"sourcesContent":["import { isAbsolute, join } from 'node:path'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\n\nimport { compileAst } from './ast'\nimport { compileFile, splitFile } from './compilers'\nimport { getConfig } from './config'\nimport { splitPrefix } from './constants'\n\nimport type { Config } from './config'\nimport type { UnpluginContextMeta, UnpluginFactory } from 'unplugin'\n\nfunction capitalizeFirst(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1)\n}\n\nfunction fileIsInRoutesDirectory(filePath: string, routesDirectory: string) {\n const routesDirectoryPath = isAbsolute(routesDirectory)\n ? routesDirectory\n : join(process.cwd(), routesDirectory)\n\n return filePath.startsWith(routesDirectoryPath)\n}\n\ntype BannedBeforeExternalPlugin = {\n identifier: string\n pkg: string\n usage: string\n frameworks: Array<UnpluginContextMeta['framework']>\n}\n\nconst bannedBeforeExternalPlugins: Array<BannedBeforeExternalPlugin> = [\n {\n identifier: '@react-refresh',\n pkg: '@vitejs/plugin-react',\n usage: 'viteReact()',\n frameworks: ['vite'],\n },\n]\n\nclass FoundPluginInBeforeCode extends Error {\n constructor(externalPlugin: BannedBeforeExternalPlugin, framework: string) {\n super(`We detected that the '${externalPlugin.pkg}' was passed before '@tanstack/router-plugin'. Please make sure that '@tanstack/router-plugin' is passed before '${externalPlugin.pkg}' and try again: \ne.g.\nplugins: [\n TanStackRouter${capitalizeFirst(framework)}(), // Place this before ${externalPlugin.usage}\n ${externalPlugin.usage},\n]\n`)\n }\n}\n\nexport const unpluginRouterCodeSplitterFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}, { framework }) => {\n const debug = Boolean(process.env.TSR_VITE_DEBUG)\n\n let ROOT: string = process.cwd()\n let userConfig = options as Config\n\n const handleSplittingFile = async (code: string, id: string) => {\n const compiledAst = compileAst({\n root: ROOT,\n })\n\n if (debug) console.info('Splitting route: ', id)\n\n const compiled = await splitFile({\n code,\n compileAst: compiledAst,\n filename: id,\n })\n\n if (debug) console.info('')\n if (debug) console.info('Split Output')\n if (debug) console.info('')\n if (debug) console.info(compiled.code)\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n\n return compiled\n }\n\n const handleCompilingFile = async (code: string, id: string) => {\n const compiledAst = compileAst({\n root: ROOT,\n })\n\n if (debug) console.info('Handling createRoute: ', id)\n\n const compiled = await compileFile({\n code,\n compileAst: compiledAst,\n filename: id,\n })\n\n if (debug) console.info('')\n if (debug) console.info('Compiled Output')\n if (debug) console.info('')\n if (debug) console.info(compiled.code)\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n\n return compiled\n }\n\n return {\n name: 'router-code-splitter-plugin',\n enforce: 'pre',\n resolveId(source) {\n if (!userConfig.experimental?.enableCodeSplitting) {\n return null\n }\n\n if (source.startsWith(splitPrefix + ':')) {\n return source.replace(splitPrefix + ':', '')\n }\n return null\n },\n async transform(code, id) {\n if (!userConfig.experimental?.enableCodeSplitting) {\n return null\n }\n\n const url = pathToFileURL(id)\n url.searchParams.delete('v')\n id = fileURLToPath(url).replace(/\\\\/g, '/')\n\n if (id.includes(splitPrefix)) {\n return await handleSplittingFile(code, id)\n } else if (\n fileIsInRoutesDirectory(id, userConfig.routesDirectory) &&\n (code.includes('createRoute(') || code.includes('createFileRoute('))\n ) {\n for (const externalPlugin of bannedBeforeExternalPlugins) {\n if (!externalPlugin.frameworks.includes(framework)) {\n continue\n }\n\n if (code.includes(externalPlugin.identifier)) {\n throw new FoundPluginInBeforeCode(externalPlugin, framework)\n }\n }\n\n return await handleCompilingFile(code, id)\n }\n\n return null\n },\n vite: {\n async configResolved(config) {\n ROOT = config.root\n userConfig = await getConfig(options, ROOT)\n },\n },\n }\n}\n"],"names":["isAbsolute","join","compileAst","splitFile","compileFile","splitPrefix","pathToFileURL","fileURLToPath","config","getConfig"],"mappings":";;;;;;;;AAWA,SAAS,gBAAgB,KAAqB;AACrC,SAAA,IAAI,OAAO,CAAC,EAAE,gBAAgB,IAAI,MAAM,CAAC;AAClD;AAEA,SAAS,wBAAwB,UAAkB,iBAAyB;AACpE,QAAA,sBAAsBA,qBAAW,eAAe,IAClD,kBACAC,UAAK,KAAA,QAAQ,OAAO,eAAe;AAEhC,SAAA,SAAS,WAAW,mBAAmB;AAChD;AASA,MAAM,8BAAiE;AAAA,EACrE;AAAA,IACE,YAAY;AAAA,IACZ,KAAK;AAAA,IACL,OAAO;AAAA,IACP,YAAY,CAAC,MAAM;AAAA,EACrB;AACF;AAEA,MAAM,gCAAgC,MAAM;AAAA,EAC1C,YAAY,gBAA4C,WAAmB;AACzE,UAAM,yBAAyB,eAAe,GAAG,oHAAoH,eAAe,GAAG;AAAA;AAAA;AAAA,kBAGzK,gBAAgB,SAAS,CAAC,4BAA4B,eAAe,KAAK;AAAA,IACxF,eAAe,KAAK;AAAA;AAAA,CAEvB;AAAA,EACC;AACF;
|
|
1
|
+
{"version":3,"file":"code-splitter.cjs","sources":["../../src/code-splitter.ts"],"sourcesContent":["import { isAbsolute, join } from 'node:path'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\n\nimport { compileAst } from './ast'\nimport { compileFile, splitFile } from './compilers'\nimport { getConfig } from './config'\nimport { splitPrefix } from './constants'\n\nimport type { Config } from './config'\nimport type { UnpluginContextMeta, UnpluginFactory } from 'unplugin'\n\nfunction capitalizeFirst(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1)\n}\n\nfunction fileIsInRoutesDirectory(filePath: string, routesDirectory: string) {\n const routesDirectoryPath = isAbsolute(routesDirectory)\n ? routesDirectory\n : join(process.cwd(), routesDirectory)\n\n return filePath.startsWith(routesDirectoryPath)\n}\n\ntype BannedBeforeExternalPlugin = {\n identifier: string\n pkg: string\n usage: string\n frameworks: Array<UnpluginContextMeta['framework']>\n}\n\nconst bannedBeforeExternalPlugins: Array<BannedBeforeExternalPlugin> = [\n {\n identifier: '@react-refresh',\n pkg: '@vitejs/plugin-react',\n usage: 'viteReact()',\n frameworks: ['vite'],\n },\n]\n\nclass FoundPluginInBeforeCode extends Error {\n constructor(externalPlugin: BannedBeforeExternalPlugin, framework: string) {\n super(`We detected that the '${externalPlugin.pkg}' was passed before '@tanstack/router-plugin'. Please make sure that '@tanstack/router-plugin' is passed before '${externalPlugin.pkg}' and try again: \ne.g.\nplugins: [\n TanStackRouter${capitalizeFirst(framework)}(), // Place this before ${externalPlugin.usage}\n ${externalPlugin.usage},\n]\n`)\n }\n}\n\nconst PLUGIN_NAME = 'unplugin:router-code-splitter'\n\nexport const unpluginRouterCodeSplitterFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}, { framework }) => {\n const debug = Boolean(process.env.TSR_VITE_DEBUG)\n\n let ROOT: string = process.cwd()\n let userConfig = options as Config\n\n const handleSplittingFile = async (code: string, id: string) => {\n const compiledAst = compileAst({\n root: ROOT,\n })\n\n if (debug) console.info('Splitting route: ', id)\n\n const compiled = await splitFile({\n code,\n compileAst: compiledAst,\n filename: id,\n })\n\n if (debug) console.info('')\n if (debug) console.info('Split Output')\n if (debug) console.info('')\n if (debug) console.info(compiled.code)\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n\n return compiled\n }\n\n const handleCompilingFile = async (code: string, id: string) => {\n const compiledAst = compileAst({\n root: ROOT,\n })\n\n if (debug) console.info('Handling createRoute: ', id)\n\n const compiled = await compileFile({\n code,\n compileAst: compiledAst,\n filename: id,\n })\n\n if (debug) console.info('')\n if (debug) console.info('Compiled Output')\n if (debug) console.info('')\n if (debug) console.info(compiled.code)\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n\n return compiled\n }\n\n return {\n name: 'router-code-splitter-plugin',\n enforce: 'pre',\n\n resolveId(source) {\n if (!userConfig.experimental?.enableCodeSplitting) {\n return null\n }\n\n if (source.startsWith(splitPrefix + ':')) {\n return source.replace(splitPrefix + ':', '')\n }\n return null\n },\n\n async transform(code, id) {\n if (!userConfig.experimental?.enableCodeSplitting) {\n return null\n }\n\n const url = pathToFileURL(id)\n url.searchParams.delete('v')\n id = fileURLToPath(url).replace(/\\\\/g, '/')\n\n if (id.includes(splitPrefix)) {\n return await handleSplittingFile(code, id)\n } else if (\n fileIsInRoutesDirectory(id, userConfig.routesDirectory) &&\n (code.includes('createRoute(') || code.includes('createFileRoute('))\n ) {\n for (const externalPlugin of bannedBeforeExternalPlugins) {\n if (!externalPlugin.frameworks.includes(framework)) {\n continue\n }\n\n if (code.includes(externalPlugin.identifier)) {\n throw new FoundPluginInBeforeCode(externalPlugin, framework)\n }\n }\n\n return await handleCompilingFile(code, id)\n }\n\n return null\n },\n\n vite: {\n async configResolved(config) {\n ROOT = config.root\n userConfig = await getConfig(options, ROOT)\n },\n },\n\n async rspack(compiler) {\n userConfig = await getConfig(options, ROOT)\n },\n }\n}\n"],"names":["isAbsolute","join","compileAst","splitFile","compileFile","splitPrefix","pathToFileURL","fileURLToPath","config","getConfig"],"mappings":";;;;;;;;AAWA,SAAS,gBAAgB,KAAqB;AACrC,SAAA,IAAI,OAAO,CAAC,EAAE,gBAAgB,IAAI,MAAM,CAAC;AAClD;AAEA,SAAS,wBAAwB,UAAkB,iBAAyB;AACpE,QAAA,sBAAsBA,qBAAW,eAAe,IAClD,kBACAC,UAAK,KAAA,QAAQ,OAAO,eAAe;AAEhC,SAAA,SAAS,WAAW,mBAAmB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c,EAAE;AACxB,UAAA,aAAa,OAAO,GAAG;AAC3B,WAAKC,SAAc,cAAA,GAAG,EAAE,QAAQ,OAAO,GAAG;AAEtC,UAAA,GAAG,SAASF,UAAAA,WAAW,GAAG;AACrB,eAAA,MAAM,oBAAoB,MAAM,EAAE;AAAA,MAEzC,WAAA,wBAAwB,IAAI,WAAW,eAAe,MACrD,KAAK,SAAS,cAAc,KAAK,KAAK,SAAS,kBAAkB,IAClE;AACA,mBAAW,kBAAkB,6BAA6B;AACxD,cAAI,CAAC,eAAe,WAAW,SAAS,SAAS,GAAG;AAClD;AAAA,UACF;AAEA,cAAI,KAAK,SAAS,eAAe,UAAU,GAAG;AACtC,kBAAA,IAAI,wBAAwB,gBAAgB,SAAS;AAAA,UAC7D;AAAA,QACF;AAEO,eAAA,MAAM,oBAAoB,MAAM,EAAE;AAAA,MAC3C;AAEO,aAAA;AAAA,IACT;AAAA,IAEA,MAAM;AAAA,MACJ,MAAM,eAAeG,UAAQ;AAC3B,eAAOA,SAAO;AACD,qBAAA,MAAMC,OAAAA,UAAU,SAAS,IAAI;AAAA,MAC5C;AAAA,IACF;AAAA,IAEA,MAAM,OAAO,UAAU;AACR,mBAAA,MAAMA,OAAAA,UAAU,SAAS,IAAI;AAAA,IAC5C;AAAA,EAAA;AAEJ;;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
|
+
const routerGenerator = require("./router-generator.cjs");
|
|
4
|
+
const codeSplitter = require("./code-splitter.cjs");
|
|
5
|
+
const unpluginRouterComposedFactory = (options = {}, meta) => {
|
|
6
|
+
const routerGenerator$1 = routerGenerator.unpluginRouterGeneratorFactory(options);
|
|
7
|
+
const routerGeneratorOptions = Array.isArray(routerGenerator$1) ? routerGenerator$1 : [routerGenerator$1];
|
|
8
|
+
const routerCodeSplitter = codeSplitter.unpluginRouterCodeSplitterFactory(options, meta);
|
|
9
|
+
let routerCodeSplitterOptions = Array.isArray(routerCodeSplitter) ? routerCodeSplitter : [routerCodeSplitter];
|
|
10
|
+
if (meta.framework === "rspack") {
|
|
11
|
+
routerCodeSplitterOptions = [];
|
|
12
|
+
}
|
|
13
|
+
return [...routerGeneratorOptions, ...routerCodeSplitterOptions];
|
|
14
|
+
};
|
|
15
|
+
exports.unpluginRouterComposedFactory = unpluginRouterComposedFactory;
|
|
16
|
+
//# sourceMappingURL=composed.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"composed.cjs","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":["routerGenerator","unpluginRouterGeneratorFactory","unpluginRouterCodeSplitterFactory"],"mappings":";;;;AAMO,MAAM,gCAET,CAAC,UAAU,IAAI,SAAS;AACpB,QAAAA,oBAAkBC,+CAA+B,OAAa;AAEpE,QAAM,yBAAyB,MAAM,QAAQD,iBAAe,IACxDA,oBACA,CAACA,iBAAe;AAEd,QAAA,qBAAqBE,aAAAA,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;;"}
|
|
@@ -9,6 +9,7 @@ const checkLock = () => lock;
|
|
|
9
9
|
const setLock = (bool) => {
|
|
10
10
|
lock = bool;
|
|
11
11
|
};
|
|
12
|
+
const PLUGIN_NAME = "unplugin:router-generator";
|
|
12
13
|
const unpluginRouterGeneratorFactory = (options = {}) => {
|
|
13
14
|
let ROOT = process.cwd();
|
|
14
15
|
let userConfig = options;
|
|
@@ -58,6 +59,13 @@ const unpluginRouterGeneratorFactory = (options = {}) => {
|
|
|
58
59
|
userConfig = await config.getConfig(options, ROOT);
|
|
59
60
|
await run(generate);
|
|
60
61
|
}
|
|
62
|
+
},
|
|
63
|
+
async rspack(compiler) {
|
|
64
|
+
userConfig = await config.getConfig(options, ROOT);
|
|
65
|
+
await run(generate);
|
|
66
|
+
compiler.hooks.watchRun.tap(PLUGIN_NAME, async () => {
|
|
67
|
+
await run(generate);
|
|
68
|
+
});
|
|
61
69
|
}
|
|
62
70
|
};
|
|
63
71
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"router-generator.cjs","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 {
|
|
1
|
+
{"version":3,"file":"router-generator.cjs","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":["generator","normalize","join","CONFIG_FILE_NAME","getConfig","resolve","isAbsolute","config"],"mappings":";;;;;;AAQA,IAAI,OAAO;AACX,MAAM,YAAY,MAAM;AACxB,MAAM,UAAU,CAAC,SAAkB;AAC1B,SAAA;AACT;AAEA,MAAM,cAAc;AAEb,MAAM,iCAET,CAAC,UAAU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AAI;AAE1C,YAAM,IAAI,QAAQ;AAElB,eAAS,MAAM,SAAS,IAAI,aAAa,YAAY;AACnD,cAAM,IAAI,QAAQ;AAAA,MAAA,CACnB;AAAA,IACH;AAAA,EAAA;AAEJ;;"}
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperties(exports, { __esModule: { value: true }, [Symbol.toStringTag]: { value: "Module" } });
|
|
3
|
+
const unplugin = require("unplugin");
|
|
4
|
+
const codeSplitter = require("./code-splitter.cjs");
|
|
5
|
+
const config = require("./config.cjs");
|
|
6
|
+
const routerGenerator = require("./router-generator.cjs");
|
|
7
|
+
const composed = require("./composed.cjs");
|
|
8
|
+
const TanStackRouterGeneratorRspack = /* @__PURE__ */ unplugin.createRspackPlugin(
|
|
9
|
+
routerGenerator.unpluginRouterGeneratorFactory
|
|
10
|
+
);
|
|
11
|
+
const unstable_TanStackRouterCodeSplitterRspack = /* @__PURE__ */ unplugin.createRspackPlugin(codeSplitter.unpluginRouterCodeSplitterFactory);
|
|
12
|
+
const TanStackRouterRspack = /* @__PURE__ */ unplugin.createRspackPlugin(
|
|
13
|
+
composed.unpluginRouterComposedFactory
|
|
14
|
+
);
|
|
15
|
+
exports.configSchema = config.configSchema;
|
|
16
|
+
exports.TanStackRouterGeneratorRspack = TanStackRouterGeneratorRspack;
|
|
17
|
+
exports.TanStackRouterRspack = TanStackRouterRspack;
|
|
18
|
+
exports.default = TanStackRouterRspack;
|
|
19
|
+
exports.unstable_TanStackRouterCodeSplitterRspack = unstable_TanStackRouterCodeSplitterRspack;
|
|
20
|
+
//# sourceMappingURL=rspack.cjs.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"rspack.cjs","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":["createRspackPlugin","unpluginRouterGeneratorFactory","unpluginRouterCodeSplitterFactory","unpluginRouterComposedFactory"],"mappings":";;;;;;;AAoBA,MAAM,gCAAgDA,yBAAA;AAAA,EACpDC,gBAAA;AACF;AAwBM,MAAA,wFAC+BC,8CAAiC;AAetE,MAAM,uBAAuCF,yBAAA;AAAA,EAC3CG,SAAA;AACF;;;;;;"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { configSchema, Config } from './config.cjs';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* export default defineConfig({
|
|
7
|
+
* // ...
|
|
8
|
+
* tools: {
|
|
9
|
+
* rspack: {
|
|
10
|
+
* plugins: [TanStackRouterGeneratorRspack()],
|
|
11
|
+
* },
|
|
12
|
+
* },
|
|
13
|
+
* })
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
declare const TanStackRouterGeneratorRspack: (options?: Partial<{
|
|
17
|
+
routeFileIgnorePrefix: string;
|
|
18
|
+
routesDirectory: string;
|
|
19
|
+
generatedRouteTree: string;
|
|
20
|
+
quoteStyle: "single" | "double";
|
|
21
|
+
semicolons: boolean;
|
|
22
|
+
disableTypes: boolean;
|
|
23
|
+
addExtensions: boolean;
|
|
24
|
+
disableLogging: boolean;
|
|
25
|
+
routeTreeFileHeader: string[];
|
|
26
|
+
routeTreeFileFooter: string[];
|
|
27
|
+
enableRouteGeneration?: boolean | undefined;
|
|
28
|
+
experimental?: {
|
|
29
|
+
enableCodeSplitting?: boolean | undefined;
|
|
30
|
+
} | undefined;
|
|
31
|
+
routeFilePrefix?: string | undefined;
|
|
32
|
+
routeFileIgnorePattern?: string | undefined;
|
|
33
|
+
}> | undefined) => _rspack_core_dist_config_zod.RspackPluginInstance;
|
|
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
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* export default defineConfig({
|
|
47
|
+
* // ...
|
|
48
|
+
* tools: {
|
|
49
|
+
* rspack: {
|
|
50
|
+
* plugins: [unstable_TanStackRouterCodeSplitterRspack()],
|
|
51
|
+
* },
|
|
52
|
+
* },
|
|
53
|
+
* })
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
declare const unstable_TanStackRouterCodeSplitterRspack: (options?: Partial<{
|
|
57
|
+
routeFileIgnorePrefix: string;
|
|
58
|
+
routesDirectory: string;
|
|
59
|
+
generatedRouteTree: string;
|
|
60
|
+
quoteStyle: "single" | "double";
|
|
61
|
+
semicolons: boolean;
|
|
62
|
+
disableTypes: boolean;
|
|
63
|
+
addExtensions: boolean;
|
|
64
|
+
disableLogging: boolean;
|
|
65
|
+
routeTreeFileHeader: string[];
|
|
66
|
+
routeTreeFileFooter: string[];
|
|
67
|
+
enableRouteGeneration?: boolean | undefined;
|
|
68
|
+
experimental?: {
|
|
69
|
+
enableCodeSplitting?: boolean | undefined;
|
|
70
|
+
} | undefined;
|
|
71
|
+
routeFilePrefix?: string | undefined;
|
|
72
|
+
routeFileIgnorePattern?: string | undefined;
|
|
73
|
+
}> | undefined) => _rspack_core_dist_config_zod.RspackPluginInstance;
|
|
74
|
+
/**
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* export default defineConfig({
|
|
78
|
+
* // ...
|
|
79
|
+
* tools: {
|
|
80
|
+
* rspack: {
|
|
81
|
+
* plugins: [TanStackRouterRspack()],
|
|
82
|
+
* },
|
|
83
|
+
* },
|
|
84
|
+
* })
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
declare const TanStackRouterRspack: (options?: Partial<{
|
|
88
|
+
routeFileIgnorePrefix: string;
|
|
89
|
+
routesDirectory: string;
|
|
90
|
+
generatedRouteTree: string;
|
|
91
|
+
quoteStyle: "single" | "double";
|
|
92
|
+
semicolons: boolean;
|
|
93
|
+
disableTypes: boolean;
|
|
94
|
+
addExtensions: boolean;
|
|
95
|
+
disableLogging: boolean;
|
|
96
|
+
routeTreeFileHeader: string[];
|
|
97
|
+
routeTreeFileFooter: string[];
|
|
98
|
+
enableRouteGeneration?: boolean | undefined;
|
|
99
|
+
experimental?: {
|
|
100
|
+
enableCodeSplitting?: boolean | undefined;
|
|
101
|
+
} | undefined;
|
|
102
|
+
routeFilePrefix?: string | undefined;
|
|
103
|
+
routeFileIgnorePattern?: string | undefined;
|
|
104
|
+
}> | undefined) => _rspack_core_dist_config_zod.RspackPluginInstance;
|
|
105
|
+
export default TanStackRouterRspack;
|
|
106
|
+
export { configSchema, TanStackRouterRspack, TanStackRouterGeneratorRspack, unstable_TanStackRouterCodeSplitterRspack, };
|
|
107
|
+
export type { Config };
|
package/dist/cjs/vite.cjs
CHANGED
|
@@ -4,18 +4,14 @@ const unplugin = require("unplugin");
|
|
|
4
4
|
const codeSplitter = require("./code-splitter.cjs");
|
|
5
5
|
const config = require("./config.cjs");
|
|
6
6
|
const routerGenerator = require("./router-generator.cjs");
|
|
7
|
+
const composed = require("./composed.cjs");
|
|
7
8
|
const TanStackRouterGeneratorVite = unplugin.createVitePlugin(
|
|
8
9
|
routerGenerator.unpluginRouterGeneratorFactory
|
|
9
10
|
);
|
|
10
11
|
const TanStackRouterCodeSplitterVite = unplugin.createVitePlugin(
|
|
11
12
|
codeSplitter.unpluginRouterCodeSplitterFactory
|
|
12
13
|
);
|
|
13
|
-
|
|
14
|
-
return [
|
|
15
|
-
TanStackRouterGeneratorVite(inlineConfig),
|
|
16
|
-
TanStackRouterCodeSplitterVite(inlineConfig)
|
|
17
|
-
];
|
|
18
|
-
}
|
|
14
|
+
const TanStackRouterVite = unplugin.createVitePlugin(composed.unpluginRouterComposedFactory);
|
|
19
15
|
exports.configSchema = config.configSchema;
|
|
20
16
|
exports.TanStackRouterCodeSplitterVite = TanStackRouterCodeSplitterVite;
|
|
21
17
|
exports.TanStackRouterGeneratorVite = TanStackRouterGeneratorVite;
|
package/dist/cjs/vite.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.cjs","sources":["../../src/vite.ts"],"sourcesContent":["import { createVitePlugin } from 'unplugin'\nimport { unpluginRouterCodeSplitterFactory } from './code-splitter'\nimport { configSchema } from './config'\nimport { unpluginRouterGeneratorFactory } from './router-generator'\
|
|
1
|
+
{"version":3,"file":"vite.cjs","sources":["../../src/vite.ts"],"sourcesContent":["import { createVitePlugin } from 'unplugin'\nimport { unpluginRouterCodeSplitterFactory } from './code-splitter'\nimport { configSchema } from './config'\nimport { unpluginRouterGeneratorFactory } from './router-generator'\nimport { unpluginRouterComposedFactory } from './composed'\n\nimport type { Config } from './config'\n\n/**\n * @example\n * ```ts\n * export default defineConfig({\n * plugins: [TanStackRouterGeneratorVite()],\n * // ...\n * })\n * ```\n */\nconst TanStackRouterGeneratorVite = createVitePlugin(\n unpluginRouterGeneratorFactory,\n)\n\n/**\n * @example\n * ```ts\n * export default defineConfig({\n * plugins: [TanStackRouterCodeSplitterVite()],\n * // ...\n * })\n * ```\n */\nconst TanStackRouterCodeSplitterVite = createVitePlugin(\n unpluginRouterCodeSplitterFactory,\n)\n\n/**\n * @example\n * ```ts\n * export default defineConfig({\n * plugins: [TanStackRouterVite()],\n * // ...\n * })\n * ```\n */\nconst TanStackRouterVite = createVitePlugin(unpluginRouterComposedFactory)\n\nexport default TanStackRouterVite\nexport {\n configSchema,\n TanStackRouterGeneratorVite,\n TanStackRouterCodeSplitterVite,\n TanStackRouterVite,\n}\nexport type { Config }\n"],"names":["createVitePlugin","unpluginRouterGeneratorFactory","unpluginRouterCodeSplitterFactory","unpluginRouterComposedFactory"],"mappings":";;;;;;;AAiBA,MAAM,8BAA8BA,SAAA;AAAA,EAClCC,gBAAA;AACF;AAWA,MAAM,iCAAiCD,SAAA;AAAA,EACrCE,aAAA;AACF;AAWM,MAAA,qBAAqBF,0BAAiBG,SAA6B,6BAAA;;;;;;"}
|
package/dist/cjs/vite.d.cts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { configSchema, Config } from './config.cjs';
|
|
2
|
-
import { VitePlugin } from 'unplugin';
|
|
3
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* export default defineConfig({
|
|
7
|
+
* plugins: [TanStackRouterGeneratorVite()],
|
|
8
|
+
* // ...
|
|
9
|
+
* })
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
4
12
|
declare const TanStackRouterGeneratorVite: (options?: Partial<{
|
|
5
13
|
routeFileIgnorePrefix: string;
|
|
6
14
|
routesDirectory: string;
|
|
@@ -18,7 +26,16 @@ declare const TanStackRouterGeneratorVite: (options?: Partial<{
|
|
|
18
26
|
} | undefined;
|
|
19
27
|
routeFilePrefix?: string | undefined;
|
|
20
28
|
routeFileIgnorePattern?: string | undefined;
|
|
21
|
-
}> | undefined) =>
|
|
29
|
+
}> | undefined) => import('vite').Plugin<any> | import('vite').Plugin<any>[];
|
|
30
|
+
/**
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* export default defineConfig({
|
|
34
|
+
* plugins: [TanStackRouterCodeSplitterVite()],
|
|
35
|
+
* // ...
|
|
36
|
+
* })
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
22
39
|
declare const TanStackRouterCodeSplitterVite: (options?: Partial<{
|
|
23
40
|
routeFileIgnorePrefix: string;
|
|
24
41
|
routesDirectory: string;
|
|
@@ -36,8 +53,34 @@ declare const TanStackRouterCodeSplitterVite: (options?: Partial<{
|
|
|
36
53
|
} | undefined;
|
|
37
54
|
routeFilePrefix?: string | undefined;
|
|
38
55
|
routeFileIgnorePattern?: string | undefined;
|
|
39
|
-
}> | undefined) =>
|
|
40
|
-
|
|
56
|
+
}> | undefined) => import('vite').Plugin<any> | import('vite').Plugin<any>[];
|
|
57
|
+
/**
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* export default defineConfig({
|
|
61
|
+
* plugins: [TanStackRouterVite()],
|
|
62
|
+
* // ...
|
|
63
|
+
* })
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
declare const TanStackRouterVite: (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('vite').Plugin<any> | import('vite').Plugin<any>[];
|
|
41
84
|
export default TanStackRouterVite;
|
|
42
85
|
export { configSchema, TanStackRouterGeneratorVite, TanStackRouterCodeSplitterVite, TanStackRouterVite, };
|
|
43
86
|
export type { Config };
|
|
@@ -153,6 +153,9 @@ const unpluginRouterCodeSplitterFactory = (options = {}, { framework }) => {
|
|
|
153
153
|
ROOT = config.root;
|
|
154
154
|
userConfig = await getConfig(options, ROOT);
|
|
155
155
|
}
|
|
156
|
+
},
|
|
157
|
+
async rspack(compiler) {
|
|
158
|
+
userConfig = await getConfig(options, ROOT);
|
|
156
159
|
}
|
|
157
160
|
};
|
|
158
161
|
};
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"code-splitter.js","sources":["../../src/code-splitter.ts"],"sourcesContent":["import { isAbsolute, join } from 'node:path'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\n\nimport { compileAst } from './ast'\nimport { compileFile, splitFile } from './compilers'\nimport { getConfig } from './config'\nimport { splitPrefix } from './constants'\n\nimport type { Config } from './config'\nimport type { UnpluginContextMeta, UnpluginFactory } from 'unplugin'\n\nfunction capitalizeFirst(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1)\n}\n\nfunction fileIsInRoutesDirectory(filePath: string, routesDirectory: string) {\n const routesDirectoryPath = isAbsolute(routesDirectory)\n ? routesDirectory\n : join(process.cwd(), routesDirectory)\n\n return filePath.startsWith(routesDirectoryPath)\n}\n\ntype BannedBeforeExternalPlugin = {\n identifier: string\n pkg: string\n usage: string\n frameworks: Array<UnpluginContextMeta['framework']>\n}\n\nconst bannedBeforeExternalPlugins: Array<BannedBeforeExternalPlugin> = [\n {\n identifier: '@react-refresh',\n pkg: '@vitejs/plugin-react',\n usage: 'viteReact()',\n frameworks: ['vite'],\n },\n]\n\nclass FoundPluginInBeforeCode extends Error {\n constructor(externalPlugin: BannedBeforeExternalPlugin, framework: string) {\n super(`We detected that the '${externalPlugin.pkg}' was passed before '@tanstack/router-plugin'. Please make sure that '@tanstack/router-plugin' is passed before '${externalPlugin.pkg}' and try again: \ne.g.\nplugins: [\n TanStackRouter${capitalizeFirst(framework)}(), // Place this before ${externalPlugin.usage}\n ${externalPlugin.usage},\n]\n`)\n }\n}\n\nexport const unpluginRouterCodeSplitterFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}, { framework }) => {\n const debug = Boolean(process.env.TSR_VITE_DEBUG)\n\n let ROOT: string = process.cwd()\n let userConfig = options as Config\n\n const handleSplittingFile = async (code: string, id: string) => {\n const compiledAst = compileAst({\n root: ROOT,\n })\n\n if (debug) console.info('Splitting route: ', id)\n\n const compiled = await splitFile({\n code,\n compileAst: compiledAst,\n filename: id,\n })\n\n if (debug) console.info('')\n if (debug) console.info('Split Output')\n if (debug) console.info('')\n if (debug) console.info(compiled.code)\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n\n return compiled\n }\n\n const handleCompilingFile = async (code: string, id: string) => {\n const compiledAst = compileAst({\n root: ROOT,\n })\n\n if (debug) console.info('Handling createRoute: ', id)\n\n const compiled = await compileFile({\n code,\n compileAst: compiledAst,\n filename: id,\n })\n\n if (debug) console.info('')\n if (debug) console.info('Compiled Output')\n if (debug) console.info('')\n if (debug) console.info(compiled.code)\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n\n return compiled\n }\n\n return {\n name: 'router-code-splitter-plugin',\n enforce: 'pre',\n resolveId(source) {\n if (!userConfig.experimental?.enableCodeSplitting) {\n return null\n }\n\n if (source.startsWith(splitPrefix + ':')) {\n return source.replace(splitPrefix + ':', '')\n }\n return null\n },\n async transform(code, id) {\n if (!userConfig.experimental?.enableCodeSplitting) {\n return null\n }\n\n const url = pathToFileURL(id)\n url.searchParams.delete('v')\n id = fileURLToPath(url).replace(/\\\\/g, '/')\n\n if (id.includes(splitPrefix)) {\n return await handleSplittingFile(code, id)\n } else if (\n fileIsInRoutesDirectory(id, userConfig.routesDirectory) &&\n (code.includes('createRoute(') || code.includes('createFileRoute('))\n ) {\n for (const externalPlugin of bannedBeforeExternalPlugins) {\n if (!externalPlugin.frameworks.includes(framework)) {\n continue\n }\n\n if (code.includes(externalPlugin.identifier)) {\n throw new FoundPluginInBeforeCode(externalPlugin, framework)\n }\n }\n\n return await handleCompilingFile(code, id)\n }\n\n return null\n },\n vite: {\n async configResolved(config) {\n ROOT = config.root\n userConfig = await getConfig(options, ROOT)\n },\n },\n }\n}\n"],"names":[],"mappings":";;;;;;AAWA,SAAS,gBAAgB,KAAqB;AACrC,SAAA,IAAI,OAAO,CAAC,EAAE,gBAAgB,IAAI,MAAM,CAAC;AAClD;AAEA,SAAS,wBAAwB,UAAkB,iBAAyB;AACpE,QAAA,sBAAsB,WAAW,eAAe,IAClD,kBACA,KAAK,QAAQ,OAAO,eAAe;AAEhC,SAAA,SAAS,WAAW,mBAAmB;AAChD;AASA,MAAM,8BAAiE;AAAA,EACrE;AAAA,IACE,YAAY;AAAA,IACZ,KAAK;AAAA,IACL,OAAO;AAAA,IACP,YAAY,CAAC,MAAM;AAAA,EACrB;AACF;AAEA,MAAM,gCAAgC,MAAM;AAAA,EAC1C,YAAY,gBAA4C,WAAmB;AACzE,UAAM,yBAAyB,eAAe,GAAG,oHAAoH,eAAe,GAAG;AAAA;AAAA;AAAA,kBAGzK,gBAAgB,SAAS,CAAC,4BAA4B,eAAe,KAAK;AAAA,IACxF,eAAe,KAAK;AAAA;AAAA,CAEvB;AAAA,EACC;AACF;
|
|
1
|
+
{"version":3,"file":"code-splitter.js","sources":["../../src/code-splitter.ts"],"sourcesContent":["import { isAbsolute, join } from 'node:path'\nimport { fileURLToPath, pathToFileURL } from 'node:url'\n\nimport { compileAst } from './ast'\nimport { compileFile, splitFile } from './compilers'\nimport { getConfig } from './config'\nimport { splitPrefix } from './constants'\n\nimport type { Config } from './config'\nimport type { UnpluginContextMeta, UnpluginFactory } from 'unplugin'\n\nfunction capitalizeFirst(str: string): string {\n return str.charAt(0).toUpperCase() + str.slice(1)\n}\n\nfunction fileIsInRoutesDirectory(filePath: string, routesDirectory: string) {\n const routesDirectoryPath = isAbsolute(routesDirectory)\n ? routesDirectory\n : join(process.cwd(), routesDirectory)\n\n return filePath.startsWith(routesDirectoryPath)\n}\n\ntype BannedBeforeExternalPlugin = {\n identifier: string\n pkg: string\n usage: string\n frameworks: Array<UnpluginContextMeta['framework']>\n}\n\nconst bannedBeforeExternalPlugins: Array<BannedBeforeExternalPlugin> = [\n {\n identifier: '@react-refresh',\n pkg: '@vitejs/plugin-react',\n usage: 'viteReact()',\n frameworks: ['vite'],\n },\n]\n\nclass FoundPluginInBeforeCode extends Error {\n constructor(externalPlugin: BannedBeforeExternalPlugin, framework: string) {\n super(`We detected that the '${externalPlugin.pkg}' was passed before '@tanstack/router-plugin'. Please make sure that '@tanstack/router-plugin' is passed before '${externalPlugin.pkg}' and try again: \ne.g.\nplugins: [\n TanStackRouter${capitalizeFirst(framework)}(), // Place this before ${externalPlugin.usage}\n ${externalPlugin.usage},\n]\n`)\n }\n}\n\nconst PLUGIN_NAME = 'unplugin:router-code-splitter'\n\nexport const unpluginRouterCodeSplitterFactory: UnpluginFactory<\n Partial<Config> | undefined\n> = (options = {}, { framework }) => {\n const debug = Boolean(process.env.TSR_VITE_DEBUG)\n\n let ROOT: string = process.cwd()\n let userConfig = options as Config\n\n const handleSplittingFile = async (code: string, id: string) => {\n const compiledAst = compileAst({\n root: ROOT,\n })\n\n if (debug) console.info('Splitting route: ', id)\n\n const compiled = await splitFile({\n code,\n compileAst: compiledAst,\n filename: id,\n })\n\n if (debug) console.info('')\n if (debug) console.info('Split Output')\n if (debug) console.info('')\n if (debug) console.info(compiled.code)\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n\n return compiled\n }\n\n const handleCompilingFile = async (code: string, id: string) => {\n const compiledAst = compileAst({\n root: ROOT,\n })\n\n if (debug) console.info('Handling createRoute: ', id)\n\n const compiled = await compileFile({\n code,\n compileAst: compiledAst,\n filename: id,\n })\n\n if (debug) console.info('')\n if (debug) console.info('Compiled Output')\n if (debug) console.info('')\n if (debug) console.info(compiled.code)\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n if (debug) console.info('')\n\n return compiled\n }\n\n return {\n name: 'router-code-splitter-plugin',\n enforce: 'pre',\n\n resolveId(source) {\n if (!userConfig.experimental?.enableCodeSplitting) {\n return null\n }\n\n if (source.startsWith(splitPrefix + ':')) {\n return source.replace(splitPrefix + ':', '')\n }\n return null\n },\n\n async transform(code, id) {\n if (!userConfig.experimental?.enableCodeSplitting) {\n return null\n }\n\n const url = pathToFileURL(id)\n url.searchParams.delete('v')\n id = fileURLToPath(url).replace(/\\\\/g, '/')\n\n if (id.includes(splitPrefix)) {\n return await handleSplittingFile(code, id)\n } else if (\n fileIsInRoutesDirectory(id, userConfig.routesDirectory) &&\n (code.includes('createRoute(') || code.includes('createFileRoute('))\n ) {\n for (const externalPlugin of bannedBeforeExternalPlugins) {\n if (!externalPlugin.frameworks.includes(framework)) {\n continue\n }\n\n if (code.includes(externalPlugin.identifier)) {\n throw new FoundPluginInBeforeCode(externalPlugin, framework)\n }\n }\n\n return await handleCompilingFile(code, id)\n }\n\n return null\n },\n\n vite: {\n async configResolved(config) {\n ROOT = config.root\n userConfig = await getConfig(options, ROOT)\n },\n },\n\n async rspack(compiler) {\n userConfig = await getConfig(options, ROOT)\n },\n }\n}\n"],"names":[],"mappings":";;;;;;AAWA,SAAS,gBAAgB,KAAqB;AACrC,SAAA,IAAI,OAAO,CAAC,EAAE,gBAAgB,IAAI,MAAM,CAAC;AAClD;AAEA,SAAS,wBAAwB,UAAkB,iBAAyB;AACpE,QAAA,sBAAsB,WAAW,eAAe,IAClD,kBACA,KAAK,QAAQ,OAAO,eAAe;AAEhC,SAAA,SAAS,WAAW,mBAAmB;AAChD;AASA,MAAM,8BAAiE;AAAA,EACrE;AAAA,IACE,YAAY;AAAA,IACZ,KAAK;AAAA,IACL,OAAO;AAAA,IACP,YAAY,CAAC,MAAM;AAAA,EACrB;AACF;AAEA,MAAM,gCAAgC,MAAM;AAAA,EAC1C,YAAY,gBAA4C,WAAmB;AACzE,UAAM,yBAAyB,eAAe,GAAG,oHAAoH,eAAe,GAAG;AAAA;AAAA;AAAA,kBAGzK,gBAAgB,SAAS,CAAC,4BAA4B,eAAe,KAAK;AAAA,IACxF,eAAe,KAAK;AAAA;AAAA,CAEvB;AAAA,EACC;AACF;AAIO,MAAM,oCAET,CAAC,UAAU,IAAI,EAAE,gBAAgB;AACnC,QAAM,QAAQ,QAAQ,QAAQ,IAAI,cAAc;AAE5C,MAAA,OAAe,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AAA;AAAA,IACT;AAAA,IAEA,MAAM;AAAA,MACJ,MAAM,eAAe,QAAQ;AAC3B,eAAO,OAAO;AACD,qBAAA,MAAM,UAAU,SAAS,IAAI;AAAA,MAC5C;AAAA,IACF;AAAA,IAEA,MAAM,OAAO,UAAU;AACR,mBAAA,MAAM,UAAU,SAAS,IAAI;AAAA,IAC5C;AAAA,EAAA;AAEJ;"}
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import { unpluginRouterGeneratorFactory } from "./router-generator.js";
|
|
2
|
+
import { unpluginRouterCodeSplitterFactory } from "./code-splitter.js";
|
|
3
|
+
const unpluginRouterComposedFactory = (options = {}, meta) => {
|
|
4
|
+
const routerGenerator = unpluginRouterGeneratorFactory(options);
|
|
5
|
+
const routerGeneratorOptions = Array.isArray(routerGenerator) ? routerGenerator : [routerGenerator];
|
|
6
|
+
const routerCodeSplitter = unpluginRouterCodeSplitterFactory(options, meta);
|
|
7
|
+
let routerCodeSplitterOptions = Array.isArray(routerCodeSplitter) ? routerCodeSplitter : [routerCodeSplitter];
|
|
8
|
+
if (meta.framework === "rspack") {
|
|
9
|
+
routerCodeSplitterOptions = [];
|
|
10
|
+
}
|
|
11
|
+
return [...routerGeneratorOptions, ...routerCodeSplitterOptions];
|
|
12
|
+
};
|
|
13
|
+
export {
|
|
14
|
+
unpluginRouterComposedFactory
|
|
15
|
+
};
|
|
16
|
+
//# sourceMappingURL=composed.js.map
|
|
@@ -0,0 +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;"}
|
|
@@ -7,6 +7,7 @@ const checkLock = () => lock;
|
|
|
7
7
|
const setLock = (bool) => {
|
|
8
8
|
lock = bool;
|
|
9
9
|
};
|
|
10
|
+
const PLUGIN_NAME = "unplugin:router-generator";
|
|
10
11
|
const unpluginRouterGeneratorFactory = (options = {}) => {
|
|
11
12
|
let ROOT = process.cwd();
|
|
12
13
|
let userConfig = options;
|
|
@@ -56,6 +57,13 @@ const unpluginRouterGeneratorFactory = (options = {}) => {
|
|
|
56
57
|
userConfig = await getConfig(options, ROOT);
|
|
57
58
|
await run(generate);
|
|
58
59
|
}
|
|
60
|
+
},
|
|
61
|
+
async rspack(compiler) {
|
|
62
|
+
userConfig = await getConfig(options, ROOT);
|
|
63
|
+
await run(generate);
|
|
64
|
+
compiler.hooks.watchRun.tap(PLUGIN_NAME, async () => {
|
|
65
|
+
await run(generate);
|
|
66
|
+
});
|
|
59
67
|
}
|
|
60
68
|
};
|
|
61
69
|
};
|
|
@@ -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 {
|
|
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,QAAQ;AAC3B,MAAI,aAAa;AAEjB,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;AAC1C;AAAA,IACF;AAEA,QACE,UAAU,YACV,aAAa,QAAQ,WAAW,kBAAkB,GAClD;AAEA;AAAA,IACF;AAEM,UAAA,sBAAsB,WAAW,WAAW,eAAe,IAC7D,WAAW,kBACX,KAAK,MAAM,WAAW,eAAe;AAErC,QAAA,SAAS,WAAW,mBAAmB,GAAG;AAC5C,YAAM,SAAS;AAAA,IACjB;AAAA,EAAA;AAGI,QAAA,MAAyD,OAAO,OAAO;AACvE,QAAA,WAAW,yBAAyB,MAAM;AAC5C,YAAM,GAAG;AAAA,IACX;AAAA,EAAA;AAGK,SAAA;AAAA,IACL,MAAM;AAAA,IACN,MAAM,YAAY,IAAI,EAAE,SAAS;AAC/B,YAAM,IAAI,YAAY;AACd,cAAA,WAAW,IAAI,KAAK;AAAA,MAAA,CAC3B;AAAA,IACH;AAAA,IACA,MAAM;AAAA,MACJ,MAAM,eAAe,QAAQ;AAC3B,eAAO,OAAO;AACD,qBAAA,MAAM,UAAU,SAAS,IAAI;AAE1C,cAAM,IAAI,QAAQ;AAAA,MACpB;AAAA,IACF;AAAA,IACA,MAAM,OAAO,UAAU;AACR,mBAAA,MAAM,UAAU,SAAS,IAAI;AAE1C,YAAM,IAAI,QAAQ;AAElB,eAAS,MAAM,SAAS,IAAI,aAAa,YAAY;AACnD,cAAM,IAAI,QAAQ;AAAA,MAAA,CACnB;AAAA,IACH;AAAA,EAAA;AAEJ;"}
|
|
@@ -0,0 +1,107 @@
|
|
|
1
|
+
import { configSchema, Config } from './config.js';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* export default defineConfig({
|
|
7
|
+
* // ...
|
|
8
|
+
* tools: {
|
|
9
|
+
* rspack: {
|
|
10
|
+
* plugins: [TanStackRouterGeneratorRspack()],
|
|
11
|
+
* },
|
|
12
|
+
* },
|
|
13
|
+
* })
|
|
14
|
+
* ```
|
|
15
|
+
*/
|
|
16
|
+
declare const TanStackRouterGeneratorRspack: (options?: Partial<{
|
|
17
|
+
routeFileIgnorePrefix: string;
|
|
18
|
+
routesDirectory: string;
|
|
19
|
+
generatedRouteTree: string;
|
|
20
|
+
quoteStyle: "single" | "double";
|
|
21
|
+
semicolons: boolean;
|
|
22
|
+
disableTypes: boolean;
|
|
23
|
+
addExtensions: boolean;
|
|
24
|
+
disableLogging: boolean;
|
|
25
|
+
routeTreeFileHeader: string[];
|
|
26
|
+
routeTreeFileFooter: string[];
|
|
27
|
+
enableRouteGeneration?: boolean | undefined;
|
|
28
|
+
experimental?: {
|
|
29
|
+
enableCodeSplitting?: boolean | undefined;
|
|
30
|
+
} | undefined;
|
|
31
|
+
routeFilePrefix?: string | undefined;
|
|
32
|
+
routeFileIgnorePattern?: string | undefined;
|
|
33
|
+
}> | undefined) => _rspack_core_dist_config_zod.RspackPluginInstance;
|
|
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
|
+
* @example
|
|
45
|
+
* ```ts
|
|
46
|
+
* export default defineConfig({
|
|
47
|
+
* // ...
|
|
48
|
+
* tools: {
|
|
49
|
+
* rspack: {
|
|
50
|
+
* plugins: [unstable_TanStackRouterCodeSplitterRspack()],
|
|
51
|
+
* },
|
|
52
|
+
* },
|
|
53
|
+
* })
|
|
54
|
+
* ```
|
|
55
|
+
*/
|
|
56
|
+
declare const unstable_TanStackRouterCodeSplitterRspack: (options?: Partial<{
|
|
57
|
+
routeFileIgnorePrefix: string;
|
|
58
|
+
routesDirectory: string;
|
|
59
|
+
generatedRouteTree: string;
|
|
60
|
+
quoteStyle: "single" | "double";
|
|
61
|
+
semicolons: boolean;
|
|
62
|
+
disableTypes: boolean;
|
|
63
|
+
addExtensions: boolean;
|
|
64
|
+
disableLogging: boolean;
|
|
65
|
+
routeTreeFileHeader: string[];
|
|
66
|
+
routeTreeFileFooter: string[];
|
|
67
|
+
enableRouteGeneration?: boolean | undefined;
|
|
68
|
+
experimental?: {
|
|
69
|
+
enableCodeSplitting?: boolean | undefined;
|
|
70
|
+
} | undefined;
|
|
71
|
+
routeFilePrefix?: string | undefined;
|
|
72
|
+
routeFileIgnorePattern?: string | undefined;
|
|
73
|
+
}> | undefined) => _rspack_core_dist_config_zod.RspackPluginInstance;
|
|
74
|
+
/**
|
|
75
|
+
* @example
|
|
76
|
+
* ```ts
|
|
77
|
+
* export default defineConfig({
|
|
78
|
+
* // ...
|
|
79
|
+
* tools: {
|
|
80
|
+
* rspack: {
|
|
81
|
+
* plugins: [TanStackRouterRspack()],
|
|
82
|
+
* },
|
|
83
|
+
* },
|
|
84
|
+
* })
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
declare const TanStackRouterRspack: (options?: Partial<{
|
|
88
|
+
routeFileIgnorePrefix: string;
|
|
89
|
+
routesDirectory: string;
|
|
90
|
+
generatedRouteTree: string;
|
|
91
|
+
quoteStyle: "single" | "double";
|
|
92
|
+
semicolons: boolean;
|
|
93
|
+
disableTypes: boolean;
|
|
94
|
+
addExtensions: boolean;
|
|
95
|
+
disableLogging: boolean;
|
|
96
|
+
routeTreeFileHeader: string[];
|
|
97
|
+
routeTreeFileFooter: string[];
|
|
98
|
+
enableRouteGeneration?: boolean | undefined;
|
|
99
|
+
experimental?: {
|
|
100
|
+
enableCodeSplitting?: boolean | undefined;
|
|
101
|
+
} | undefined;
|
|
102
|
+
routeFilePrefix?: string | undefined;
|
|
103
|
+
routeFileIgnorePattern?: string | undefined;
|
|
104
|
+
}> | undefined) => _rspack_core_dist_config_zod.RspackPluginInstance;
|
|
105
|
+
export default TanStackRouterRspack;
|
|
106
|
+
export { configSchema, TanStackRouterRspack, TanStackRouterGeneratorRspack, unstable_TanStackRouterCodeSplitterRspack, };
|
|
107
|
+
export type { Config };
|
|
@@ -0,0 +1,20 @@
|
|
|
1
|
+
import { createRspackPlugin } 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 TanStackRouterGeneratorRspack = /* @__PURE__ */ createRspackPlugin(
|
|
7
|
+
unpluginRouterGeneratorFactory
|
|
8
|
+
);
|
|
9
|
+
const unstable_TanStackRouterCodeSplitterRspack = /* @__PURE__ */ createRspackPlugin(unpluginRouterCodeSplitterFactory);
|
|
10
|
+
const TanStackRouterRspack = /* @__PURE__ */ createRspackPlugin(
|
|
11
|
+
unpluginRouterComposedFactory
|
|
12
|
+
);
|
|
13
|
+
export {
|
|
14
|
+
TanStackRouterGeneratorRspack,
|
|
15
|
+
TanStackRouterRspack,
|
|
16
|
+
configSchema,
|
|
17
|
+
TanStackRouterRspack as default,
|
|
18
|
+
unstable_TanStackRouterCodeSplitterRspack
|
|
19
|
+
};
|
|
20
|
+
//# sourceMappingURL=rspack.js.map
|
|
@@ -0,0 +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;"}
|
package/dist/esm/vite.d.ts
CHANGED
|
@@ -1,6 +1,14 @@
|
|
|
1
1
|
import { configSchema, Config } from './config.js';
|
|
2
|
-
import { VitePlugin } from 'unplugin';
|
|
3
2
|
|
|
3
|
+
/**
|
|
4
|
+
* @example
|
|
5
|
+
* ```ts
|
|
6
|
+
* export default defineConfig({
|
|
7
|
+
* plugins: [TanStackRouterGeneratorVite()],
|
|
8
|
+
* // ...
|
|
9
|
+
* })
|
|
10
|
+
* ```
|
|
11
|
+
*/
|
|
4
12
|
declare const TanStackRouterGeneratorVite: (options?: Partial<{
|
|
5
13
|
routeFileIgnorePrefix: string;
|
|
6
14
|
routesDirectory: string;
|
|
@@ -18,7 +26,16 @@ declare const TanStackRouterGeneratorVite: (options?: Partial<{
|
|
|
18
26
|
} | undefined;
|
|
19
27
|
routeFilePrefix?: string | undefined;
|
|
20
28
|
routeFileIgnorePattern?: string | undefined;
|
|
21
|
-
}> | undefined) =>
|
|
29
|
+
}> | undefined) => import('vite').Plugin<any> | import('vite').Plugin<any>[];
|
|
30
|
+
/**
|
|
31
|
+
* @example
|
|
32
|
+
* ```ts
|
|
33
|
+
* export default defineConfig({
|
|
34
|
+
* plugins: [TanStackRouterCodeSplitterVite()],
|
|
35
|
+
* // ...
|
|
36
|
+
* })
|
|
37
|
+
* ```
|
|
38
|
+
*/
|
|
22
39
|
declare const TanStackRouterCodeSplitterVite: (options?: Partial<{
|
|
23
40
|
routeFileIgnorePrefix: string;
|
|
24
41
|
routesDirectory: string;
|
|
@@ -36,8 +53,34 @@ declare const TanStackRouterCodeSplitterVite: (options?: Partial<{
|
|
|
36
53
|
} | undefined;
|
|
37
54
|
routeFilePrefix?: string | undefined;
|
|
38
55
|
routeFileIgnorePattern?: string | undefined;
|
|
39
|
-
}> | undefined) =>
|
|
40
|
-
|
|
56
|
+
}> | undefined) => import('vite').Plugin<any> | import('vite').Plugin<any>[];
|
|
57
|
+
/**
|
|
58
|
+
* @example
|
|
59
|
+
* ```ts
|
|
60
|
+
* export default defineConfig({
|
|
61
|
+
* plugins: [TanStackRouterVite()],
|
|
62
|
+
* // ...
|
|
63
|
+
* })
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
declare const TanStackRouterVite: (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('vite').Plugin<any> | import('vite').Plugin<any>[];
|
|
41
84
|
export default TanStackRouterVite;
|
|
42
85
|
export { configSchema, TanStackRouterGeneratorVite, TanStackRouterCodeSplitterVite, TanStackRouterVite, };
|
|
43
86
|
export type { Config };
|
package/dist/esm/vite.js
CHANGED
|
@@ -2,18 +2,14 @@ import { createVitePlugin } from "unplugin";
|
|
|
2
2
|
import { unpluginRouterCodeSplitterFactory } from "./code-splitter.js";
|
|
3
3
|
import { configSchema } from "./config.js";
|
|
4
4
|
import { unpluginRouterGeneratorFactory } from "./router-generator.js";
|
|
5
|
+
import { unpluginRouterComposedFactory } from "./composed.js";
|
|
5
6
|
const TanStackRouterGeneratorVite = createVitePlugin(
|
|
6
7
|
unpluginRouterGeneratorFactory
|
|
7
8
|
);
|
|
8
9
|
const TanStackRouterCodeSplitterVite = createVitePlugin(
|
|
9
10
|
unpluginRouterCodeSplitterFactory
|
|
10
11
|
);
|
|
11
|
-
|
|
12
|
-
return [
|
|
13
|
-
TanStackRouterGeneratorVite(inlineConfig),
|
|
14
|
-
TanStackRouterCodeSplitterVite(inlineConfig)
|
|
15
|
-
];
|
|
16
|
-
}
|
|
12
|
+
const TanStackRouterVite = createVitePlugin(unpluginRouterComposedFactory);
|
|
17
13
|
export {
|
|
18
14
|
TanStackRouterCodeSplitterVite,
|
|
19
15
|
TanStackRouterGeneratorVite,
|
package/dist/esm/vite.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"vite.js","sources":["../../src/vite.ts"],"sourcesContent":["import { createVitePlugin } from 'unplugin'\nimport { unpluginRouterCodeSplitterFactory } from './code-splitter'\nimport { configSchema } from './config'\nimport { unpluginRouterGeneratorFactory } from './router-generator'\
|
|
1
|
+
{"version":3,"file":"vite.js","sources":["../../src/vite.ts"],"sourcesContent":["import { createVitePlugin } from 'unplugin'\nimport { unpluginRouterCodeSplitterFactory } from './code-splitter'\nimport { configSchema } from './config'\nimport { unpluginRouterGeneratorFactory } from './router-generator'\nimport { unpluginRouterComposedFactory } from './composed'\n\nimport type { Config } from './config'\n\n/**\n * @example\n * ```ts\n * export default defineConfig({\n * plugins: [TanStackRouterGeneratorVite()],\n * // ...\n * })\n * ```\n */\nconst TanStackRouterGeneratorVite = createVitePlugin(\n unpluginRouterGeneratorFactory,\n)\n\n/**\n * @example\n * ```ts\n * export default defineConfig({\n * plugins: [TanStackRouterCodeSplitterVite()],\n * // ...\n * })\n * ```\n */\nconst TanStackRouterCodeSplitterVite = createVitePlugin(\n unpluginRouterCodeSplitterFactory,\n)\n\n/**\n * @example\n * ```ts\n * export default defineConfig({\n * plugins: [TanStackRouterVite()],\n * // ...\n * })\n * ```\n */\nconst TanStackRouterVite = createVitePlugin(unpluginRouterComposedFactory)\n\nexport default TanStackRouterVite\nexport {\n configSchema,\n TanStackRouterGeneratorVite,\n TanStackRouterCodeSplitterVite,\n TanStackRouterVite,\n}\nexport type { Config }\n"],"names":[],"mappings":";;;;;AAiBA,MAAM,8BAA8B;AAAA,EAClC;AACF;AAWA,MAAM,iCAAiC;AAAA,EACrC;AACF;AAWM,MAAA,qBAAqB,iBAAiB,6BAA6B;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/router-plugin",
|
|
3
|
-
"version": "1.39.
|
|
3
|
+
"version": "1.39.9",
|
|
4
4
|
"description": "",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -36,6 +36,16 @@
|
|
|
36
36
|
"default": "./dist/cjs/vite.cjs"
|
|
37
37
|
}
|
|
38
38
|
},
|
|
39
|
+
"./rspack": {
|
|
40
|
+
"import": {
|
|
41
|
+
"types": "./dist/esm/rspack.d.ts",
|
|
42
|
+
"default": "./dist/esm/rspack.js"
|
|
43
|
+
},
|
|
44
|
+
"require": {
|
|
45
|
+
"types": "./dist/cjs/rspack.d.cts",
|
|
46
|
+
"default": "./dist/cjs/rspack.cjs"
|
|
47
|
+
}
|
|
48
|
+
},
|
|
39
49
|
"./package.json": "./package.json"
|
|
40
50
|
},
|
|
41
51
|
"sideEffects": false,
|
|
@@ -56,11 +66,15 @@
|
|
|
56
66
|
"src/**"
|
|
57
67
|
],
|
|
58
68
|
"peerDependencies": {
|
|
59
|
-
"vite": ">=5"
|
|
69
|
+
"vite": ">=5",
|
|
70
|
+
"@rsbuild/core": ">=0.7.9"
|
|
60
71
|
},
|
|
61
72
|
"peerDependenciesMeta": {
|
|
62
73
|
"vite": {
|
|
63
74
|
"optional": true
|
|
75
|
+
},
|
|
76
|
+
"@rsbuild/core": {
|
|
77
|
+
"optional": true
|
|
64
78
|
}
|
|
65
79
|
},
|
|
66
80
|
"dependencies": {
|
package/src/code-splitter.ts
CHANGED
|
@@ -49,6 +49,8 @@ plugins: [
|
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
51
|
|
|
52
|
+
const PLUGIN_NAME = 'unplugin:router-code-splitter'
|
|
53
|
+
|
|
52
54
|
export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
|
|
53
55
|
Partial<Config> | undefined
|
|
54
56
|
> = (options = {}, { framework }) => {
|
|
@@ -120,6 +122,7 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
|
|
|
120
122
|
return {
|
|
121
123
|
name: 'router-code-splitter-plugin',
|
|
122
124
|
enforce: 'pre',
|
|
125
|
+
|
|
123
126
|
resolveId(source) {
|
|
124
127
|
if (!userConfig.experimental?.enableCodeSplitting) {
|
|
125
128
|
return null
|
|
@@ -130,6 +133,7 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
|
|
|
130
133
|
}
|
|
131
134
|
return null
|
|
132
135
|
},
|
|
136
|
+
|
|
133
137
|
async transform(code, id) {
|
|
134
138
|
if (!userConfig.experimental?.enableCodeSplitting) {
|
|
135
139
|
return null
|
|
@@ -160,11 +164,16 @@ export const unpluginRouterCodeSplitterFactory: UnpluginFactory<
|
|
|
160
164
|
|
|
161
165
|
return null
|
|
162
166
|
},
|
|
167
|
+
|
|
163
168
|
vite: {
|
|
164
169
|
async configResolved(config) {
|
|
165
170
|
ROOT = config.root
|
|
166
171
|
userConfig = await getConfig(options, ROOT)
|
|
167
172
|
},
|
|
168
173
|
},
|
|
174
|
+
|
|
175
|
+
async rspack(compiler) {
|
|
176
|
+
userConfig = await getConfig(options, ROOT)
|
|
177
|
+
},
|
|
169
178
|
}
|
|
170
179
|
}
|
package/src/composed.ts
ADDED
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import { unpluginRouterGeneratorFactory } from './router-generator'
|
|
2
|
+
import { unpluginRouterCodeSplitterFactory } from './code-splitter'
|
|
3
|
+
|
|
4
|
+
import type { Config } from './config'
|
|
5
|
+
import type { UnpluginFactory } from 'unplugin'
|
|
6
|
+
|
|
7
|
+
export const unpluginRouterComposedFactory: UnpluginFactory<
|
|
8
|
+
Partial<Config> | undefined
|
|
9
|
+
> = (options = {}, meta) => {
|
|
10
|
+
const routerGenerator = unpluginRouterGeneratorFactory(options, meta)
|
|
11
|
+
|
|
12
|
+
const routerGeneratorOptions = Array.isArray(routerGenerator)
|
|
13
|
+
? routerGenerator
|
|
14
|
+
: [routerGenerator]
|
|
15
|
+
|
|
16
|
+
const routerCodeSplitter = unpluginRouterCodeSplitterFactory(options, meta)
|
|
17
|
+
let routerCodeSplitterOptions = Array.isArray(routerCodeSplitter)
|
|
18
|
+
? routerCodeSplitter
|
|
19
|
+
: [routerCodeSplitter]
|
|
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
|
+
return [...routerGeneratorOptions, ...routerCodeSplitterOptions]
|
|
30
|
+
}
|
package/src/router-generator.ts
CHANGED
|
@@ -3,8 +3,8 @@ import { generator } from '@tanstack/router-generator'
|
|
|
3
3
|
|
|
4
4
|
import { getConfig } from './config'
|
|
5
5
|
import { CONFIG_FILE_NAME } from './constants'
|
|
6
|
-
import type { Config } from './config'
|
|
7
6
|
import type { UnpluginFactory } from 'unplugin'
|
|
7
|
+
import type { Config } from './config'
|
|
8
8
|
|
|
9
9
|
let lock = false
|
|
10
10
|
const checkLock = () => lock
|
|
@@ -12,6 +12,8 @@ const setLock = (bool: boolean) => {
|
|
|
12
12
|
lock = bool
|
|
13
13
|
}
|
|
14
14
|
|
|
15
|
+
const PLUGIN_NAME = 'unplugin:router-generator'
|
|
16
|
+
|
|
15
17
|
export const unpluginRouterGeneratorFactory: UnpluginFactory<
|
|
16
18
|
Partial<Config> | undefined
|
|
17
19
|
> = (options = {}) => {
|
|
@@ -84,5 +86,14 @@ export const unpluginRouterGeneratorFactory: UnpluginFactory<
|
|
|
84
86
|
await run(generate)
|
|
85
87
|
},
|
|
86
88
|
},
|
|
89
|
+
async rspack(compiler) {
|
|
90
|
+
userConfig = await getConfig(options, ROOT)
|
|
91
|
+
|
|
92
|
+
await run(generate)
|
|
93
|
+
|
|
94
|
+
compiler.hooks.watchRun.tap(PLUGIN_NAME, async () => {
|
|
95
|
+
await run(generate)
|
|
96
|
+
})
|
|
97
|
+
},
|
|
87
98
|
}
|
|
88
99
|
}
|
package/src/rspack.ts
ADDED
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
import { createRspackPlugin } 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 defineConfig({
|
|
12
|
+
* // ...
|
|
13
|
+
* tools: {
|
|
14
|
+
* rspack: {
|
|
15
|
+
* plugins: [TanStackRouterGeneratorRspack()],
|
|
16
|
+
* },
|
|
17
|
+
* },
|
|
18
|
+
* })
|
|
19
|
+
* ```
|
|
20
|
+
*/
|
|
21
|
+
const TanStackRouterGeneratorRspack = /* #__PURE__ */ createRspackPlugin(
|
|
22
|
+
unpluginRouterGeneratorFactory,
|
|
23
|
+
)
|
|
24
|
+
|
|
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
|
+
* @example
|
|
36
|
+
* ```ts
|
|
37
|
+
* export default defineConfig({
|
|
38
|
+
* // ...
|
|
39
|
+
* tools: {
|
|
40
|
+
* rspack: {
|
|
41
|
+
* plugins: [unstable_TanStackRouterCodeSplitterRspack()],
|
|
42
|
+
* },
|
|
43
|
+
* },
|
|
44
|
+
* })
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
const unstable_TanStackRouterCodeSplitterRspack =
|
|
48
|
+
/* #__PURE__ */ createRspackPlugin(unpluginRouterCodeSplitterFactory)
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @example
|
|
52
|
+
* ```ts
|
|
53
|
+
* export default defineConfig({
|
|
54
|
+
* // ...
|
|
55
|
+
* tools: {
|
|
56
|
+
* rspack: {
|
|
57
|
+
* plugins: [TanStackRouterRspack()],
|
|
58
|
+
* },
|
|
59
|
+
* },
|
|
60
|
+
* })
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
const TanStackRouterRspack = /* #__PURE__ */ createRspackPlugin(
|
|
64
|
+
unpluginRouterComposedFactory,
|
|
65
|
+
)
|
|
66
|
+
|
|
67
|
+
export default TanStackRouterRspack
|
|
68
|
+
export {
|
|
69
|
+
configSchema,
|
|
70
|
+
TanStackRouterRspack,
|
|
71
|
+
TanStackRouterGeneratorRspack,
|
|
72
|
+
unstable_TanStackRouterCodeSplitterRspack,
|
|
73
|
+
}
|
|
74
|
+
export type { Config }
|
package/src/vite.ts
CHANGED
|
@@ -2,23 +2,46 @@ import { createVitePlugin } from 'unplugin'
|
|
|
2
2
|
import { unpluginRouterCodeSplitterFactory } from './code-splitter'
|
|
3
3
|
import { configSchema } from './config'
|
|
4
4
|
import { unpluginRouterGeneratorFactory } from './router-generator'
|
|
5
|
+
import { unpluginRouterComposedFactory } from './composed'
|
|
5
6
|
|
|
6
7
|
import type { Config } from './config'
|
|
7
|
-
import type { VitePlugin } from 'unplugin'
|
|
8
8
|
|
|
9
|
+
/**
|
|
10
|
+
* @example
|
|
11
|
+
* ```ts
|
|
12
|
+
* export default defineConfig({
|
|
13
|
+
* plugins: [TanStackRouterGeneratorVite()],
|
|
14
|
+
* // ...
|
|
15
|
+
* })
|
|
16
|
+
* ```
|
|
17
|
+
*/
|
|
9
18
|
const TanStackRouterGeneratorVite = createVitePlugin(
|
|
10
19
|
unpluginRouterGeneratorFactory,
|
|
11
20
|
)
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* @example
|
|
24
|
+
* ```ts
|
|
25
|
+
* export default defineConfig({
|
|
26
|
+
* plugins: [TanStackRouterCodeSplitterVite()],
|
|
27
|
+
* // ...
|
|
28
|
+
* })
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
12
31
|
const TanStackRouterCodeSplitterVite = createVitePlugin(
|
|
13
32
|
unpluginRouterCodeSplitterFactory,
|
|
14
33
|
)
|
|
15
34
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
35
|
+
/**
|
|
36
|
+
* @example
|
|
37
|
+
* ```ts
|
|
38
|
+
* export default defineConfig({
|
|
39
|
+
* plugins: [TanStackRouterVite()],
|
|
40
|
+
* // ...
|
|
41
|
+
* })
|
|
42
|
+
* ```
|
|
43
|
+
*/
|
|
44
|
+
const TanStackRouterVite = createVitePlugin(unpluginRouterComposedFactory)
|
|
22
45
|
|
|
23
46
|
export default TanStackRouterVite
|
|
24
47
|
export {
|