@tanstack/start-plugin-core 1.124.2 → 1.125.1
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/start-router-plugin/plugin.cjs +26 -2
- package/dist/cjs/start-router-plugin/plugin.cjs.map +1 -1
- package/dist/cjs/start-router-plugin/plugin.d.cts +1 -1
- package/dist/cjs/start-router-plugin/route-tree-client-plugin.cjs +2 -1
- package/dist/cjs/start-router-plugin/route-tree-client-plugin.cjs.map +1 -1
- package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.cjs +3 -4
- package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.cjs.map +1 -1
- package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.d.cts +0 -1
- package/dist/esm/start-router-plugin/plugin.d.ts +1 -1
- package/dist/esm/start-router-plugin/plugin.js +26 -2
- package/dist/esm/start-router-plugin/plugin.js.map +1 -1
- package/dist/esm/start-router-plugin/route-tree-client-plugin.js +2 -1
- package/dist/esm/start-router-plugin/route-tree-client-plugin.js.map +1 -1
- package/dist/esm/start-router-plugin/virtual-route-tree-plugin.d.ts +0 -1
- package/dist/esm/start-router-plugin/virtual-route-tree-plugin.js +3 -4
- package/dist/esm/start-router-plugin/virtual-route-tree-plugin.js.map +1 -1
- package/package.json +5 -5
- package/src/start-router-plugin/plugin.ts +26 -2
- package/src/start-router-plugin/route-tree-client-plugin.ts +2 -1
- package/src/start-router-plugin/virtual-route-tree-plugin.ts +3 -4
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const vite = require("@tanstack/router-plugin/vite");
|
|
4
|
+
const constants = require("../constants.cjs");
|
|
4
5
|
const routeTreeClientPlugin = require("./route-tree-client-plugin.cjs");
|
|
5
6
|
const virtualRouteTreePlugin = require("./virtual-route-tree-plugin.cjs");
|
|
6
7
|
const routesManifestPlugin = require("./generator-plugins/routes-manifest-plugin.cjs");
|
|
@@ -9,9 +10,32 @@ function tanStackStartRouter(config) {
|
|
|
9
10
|
return [
|
|
10
11
|
vite.tanstackRouterGenerator({
|
|
11
12
|
...config,
|
|
12
|
-
plugins: [serverRoutesPlugin.serverRoutesPlugin(), routesManifestPlugin.routesManifestPlugin()]
|
|
13
|
+
plugins: [serverRoutesPlugin.serverRoutesPlugin(), routesManifestPlugin.routesManifestPlugin()],
|
|
14
|
+
plugin: {
|
|
15
|
+
vite: { environmentName: constants.VITE_ENVIRONMENT_NAMES.client }
|
|
16
|
+
}
|
|
17
|
+
}),
|
|
18
|
+
vite.tanStackRouterCodeSplitter({
|
|
19
|
+
...config,
|
|
20
|
+
codeSplittingOptions: {
|
|
21
|
+
...config.codeSplittingOptions,
|
|
22
|
+
deleteNodes: ["ssr"],
|
|
23
|
+
addHmr: true
|
|
24
|
+
},
|
|
25
|
+
plugin: {
|
|
26
|
+
vite: { environmentName: constants.VITE_ENVIRONMENT_NAMES.client }
|
|
27
|
+
}
|
|
28
|
+
}),
|
|
29
|
+
vite.tanStackRouterCodeSplitter({
|
|
30
|
+
...config,
|
|
31
|
+
codeSplittingOptions: {
|
|
32
|
+
...config.codeSplittingOptions,
|
|
33
|
+
addHmr: false
|
|
34
|
+
},
|
|
35
|
+
plugin: {
|
|
36
|
+
vite: { environmentName: constants.VITE_ENVIRONMENT_NAMES.server }
|
|
37
|
+
}
|
|
13
38
|
}),
|
|
14
|
-
vite.tanStackRouterCodeSplitter(config),
|
|
15
39
|
vite.tanstackRouterAutoImport(config),
|
|
16
40
|
routeTreeClientPlugin.routeTreeClientPlugin(config),
|
|
17
41
|
virtualRouteTreePlugin.virtualRouteTreePlugin(config)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs","sources":["../../../src/start-router-plugin/plugin.ts"],"sourcesContent":["/*\nwhat is this plugin doing, especially compared to one already existing in the @tanstack/router-plugin package?\n\nit configures:\n1. the generator to generate both the render-route-tree as well as the server-route-tree\n2. the code-splitter plugin, so it could possibly be enabled per environment (e.g. disable on the server)\n3. the auto import plugin for both environments\n4. the route tree client plugin, which removes the server part from the generated route tree\n5. the virtual route tree plugin, which provides the route tree to the server\n*/\n\nimport {\n tanStackRouterCodeSplitter,\n tanstackRouterAutoImport,\n tanstackRouterGenerator,\n} from '@tanstack/router-plugin/vite'\nimport { routeTreeClientPlugin } from './route-tree-client-plugin'\nimport { virtualRouteTreePlugin } from './virtual-route-tree-plugin'\nimport { routesManifestPlugin } from './generator-plugins/routes-manifest-plugin'\nimport { serverRoutesPlugin } from './generator-plugins/server-routes-plugin'\nimport type { PluginOption } from 'vite'\nimport type { Config } from '@tanstack/router-
|
|
1
|
+
{"version":3,"file":"plugin.cjs","sources":["../../../src/start-router-plugin/plugin.ts"],"sourcesContent":["/*\nwhat is this plugin doing, especially compared to one already existing in the @tanstack/router-plugin package?\n\nit configures:\n1. the generator to generate both the render-route-tree as well as the server-route-tree\n2. the code-splitter plugin, so it could possibly be enabled per environment (e.g. disable on the server)\n3. the auto import plugin for both environments\n4. the route tree client plugin, which removes the server part from the generated route tree\n5. the virtual route tree plugin, which provides the route tree to the server\n*/\n\nimport {\n tanStackRouterCodeSplitter,\n tanstackRouterAutoImport,\n tanstackRouterGenerator,\n} from '@tanstack/router-plugin/vite'\nimport { VITE_ENVIRONMENT_NAMES } from '../constants'\nimport { routeTreeClientPlugin } from './route-tree-client-plugin'\nimport { virtualRouteTreePlugin } from './virtual-route-tree-plugin'\nimport { routesManifestPlugin } from './generator-plugins/routes-manifest-plugin'\nimport { serverRoutesPlugin } from './generator-plugins/server-routes-plugin'\nimport type { PluginOption } from 'vite'\nimport type { Config } from '@tanstack/router-plugin'\n\nexport function tanStackStartRouter(config: Config): Array<PluginOption> {\n return [\n tanstackRouterGenerator({\n ...config,\n plugins: [serverRoutesPlugin(), routesManifestPlugin()],\n plugin: {\n vite: { environmentName: VITE_ENVIRONMENT_NAMES.client },\n },\n }),\n tanStackRouterCodeSplitter({\n ...config,\n codeSplittingOptions: {\n ...config.codeSplittingOptions,\n deleteNodes: ['ssr'],\n addHmr: true,\n },\n plugin: {\n vite: { environmentName: VITE_ENVIRONMENT_NAMES.client },\n },\n }),\n tanStackRouterCodeSplitter({\n ...config,\n codeSplittingOptions: {\n ...config.codeSplittingOptions,\n addHmr: false,\n },\n plugin: {\n vite: { environmentName: VITE_ENVIRONMENT_NAMES.server },\n },\n }),\n tanstackRouterAutoImport(config),\n routeTreeClientPlugin(config),\n virtualRouteTreePlugin(config),\n ]\n}\n"],"names":["tanstackRouterGenerator","serverRoutesPlugin","routesManifestPlugin","VITE_ENVIRONMENT_NAMES","tanStackRouterCodeSplitter","tanstackRouterAutoImport","routeTreeClientPlugin","virtualRouteTreePlugin"],"mappings":";;;;;;;;AAwBO,SAAS,oBAAoB,QAAqC;AAChE,SAAA;AAAA,IACLA,6BAAwB;AAAA,MACtB,GAAG;AAAA,MACH,SAAS,CAACC,mBAAAA,sBAAsBC,qBAAAA,sBAAsB;AAAA,MACtD,QAAQ;AAAA,QACN,MAAM,EAAE,iBAAiBC,UAAAA,uBAAuB,OAAO;AAAA,MAAA;AAAA,IACzD,CACD;AAAA,IACDC,gCAA2B;AAAA,MACzB,GAAG;AAAA,MACH,sBAAsB;AAAA,QACpB,GAAG,OAAO;AAAA,QACV,aAAa,CAAC,KAAK;AAAA,QACnB,QAAQ;AAAA,MACV;AAAA,MACA,QAAQ;AAAA,QACN,MAAM,EAAE,iBAAiBD,UAAAA,uBAAuB,OAAO;AAAA,MAAA;AAAA,IACzD,CACD;AAAA,IACDC,gCAA2B;AAAA,MACzB,GAAG;AAAA,MACH,sBAAsB;AAAA,QACpB,GAAG,OAAO;AAAA,QACV,QAAQ;AAAA,MACV;AAAA,MACA,QAAQ;AAAA,QACN,MAAM,EAAE,iBAAiBD,UAAAA,uBAAuB,OAAO;AAAA,MAAA;AAAA,IACzD,CACD;AAAA,IACDE,KAAAA,yBAAyB,MAAM;AAAA,IAC/BC,sBAAAA,sBAAsB,MAAM;AAAA,IAC5BC,uBAAAA,uBAAuB,MAAM;AAAA,EAC/B;AACF;;"}
|
|
@@ -6,6 +6,7 @@ const routerUtils = require("@tanstack/router-utils");
|
|
|
6
6
|
const vite = require("vite");
|
|
7
7
|
const babelDeadCodeElimination = require("babel-dead-code-elimination");
|
|
8
8
|
const debug = require("../debug.cjs");
|
|
9
|
+
const constants = require("../constants.cjs");
|
|
9
10
|
function _interopNamespaceDefault(e) {
|
|
10
11
|
const n = Object.create(null, { [Symbol.toStringTag]: { value: "Module" } });
|
|
11
12
|
if (e) {
|
|
@@ -31,7 +32,7 @@ function routeTreeClientPlugin(config) {
|
|
|
31
32
|
name: "tanstack-start:route-tree-client-plugin",
|
|
32
33
|
enforce: "pre",
|
|
33
34
|
// only run this plugin in the client environment
|
|
34
|
-
applyToEnvironment: (env) => env.
|
|
35
|
+
applyToEnvironment: (env) => env.name === constants.VITE_ENVIRONMENT_NAMES.client,
|
|
35
36
|
transform: {
|
|
36
37
|
filter: { id: generatedRouteTreePath },
|
|
37
38
|
handler(code, id) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-tree-client-plugin.cjs","sources":["../../../src/start-router-plugin/route-tree-client-plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport * as t from '@babel/types'\nimport { generateFromAst, logDiff, parseAst } from '@tanstack/router-utils'\nimport { normalizePath } from 'vite'\nimport { deadCodeElimination } from 'babel-dead-code-elimination'\nimport { debug } from '../debug'\nimport type { Plugin } from 'vite'\nimport type { Config } from '@tanstack/router-generator'\n\n/**\n * This removes the server part from the generated route tree so that it can be used on the client.\n */\nexport function routeTreeClientPlugin(config: Config): Plugin {\n const generatedRouteTreePath = normalizePath(\n path.resolve(config.generatedRouteTree),\n )\n\n return {\n name: 'tanstack-start:route-tree-client-plugin',\n enforce: 'pre',\n // only run this plugin in the client environment\n applyToEnvironment: (env) => env.
|
|
1
|
+
{"version":3,"file":"route-tree-client-plugin.cjs","sources":["../../../src/start-router-plugin/route-tree-client-plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport * as t from '@babel/types'\nimport { generateFromAst, logDiff, parseAst } from '@tanstack/router-utils'\nimport { normalizePath } from 'vite'\nimport { deadCodeElimination } from 'babel-dead-code-elimination'\nimport { debug } from '../debug'\nimport { VITE_ENVIRONMENT_NAMES } from '../constants'\nimport type { Plugin } from 'vite'\nimport type { Config } from '@tanstack/router-generator'\n\n/**\n * This removes the server part from the generated route tree so that it can be used on the client.\n */\nexport function routeTreeClientPlugin(config: Config): Plugin {\n const generatedRouteTreePath = normalizePath(\n path.resolve(config.generatedRouteTree),\n )\n\n return {\n name: 'tanstack-start:route-tree-client-plugin',\n enforce: 'pre',\n // only run this plugin in the client environment\n applyToEnvironment: (env) => env.name === VITE_ENVIRONMENT_NAMES.client,\n transform: {\n filter: { id: generatedRouteTreePath },\n handler(code, id) {\n if (id !== generatedRouteTreePath) {\n return null\n }\n if (debug) console.info(`Compiling route tree for the client`, id)\n const ast = parseAst({ code, sourceFilename: id })\n\n // only keep `export const routeTree = ... `\n const filteredBody = ast.program.body.filter((node) => {\n if (t.isExportNamedDeclaration(node)) {\n if (\n node.declaration &&\n t.isVariableDeclaration(node.declaration) &&\n node.declaration.declarations.length === 1 &&\n node.declaration.declarations[0] &&\n t.isVariableDeclarator(node.declaration.declarations[0]) &&\n t.isIdentifier(node.declaration.declarations[0].id) &&\n node.declaration.declarations[0].id.name === 'routeTree'\n ) {\n return true\n }\n return false\n }\n // strip off the typescript interface & module declarations since they also reference the server routes\n if (\n t.isTSInterfaceDeclaration(node) ||\n t.isTSModuleDeclaration(node)\n ) {\n return false\n }\n return true\n })\n\n ast.program.body = filteredBody\n\n deadCodeElimination(ast)\n\n const compiled = generateFromAst(ast, {\n sourceMaps: true,\n sourceFileName: id,\n filename: id,\n })\n if (debug) {\n logDiff(code, compiled.code)\n console.log('Output:\\n', compiled.code, '\\n\\n')\n }\n\n return compiled\n },\n },\n }\n}\n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AAY;AAAA,UACZ,gBAAgB;AAAA,UAChB,UAAU;AAAA,QAAA,CACX;AACD,YAAIJ,aAAO;AACDK,8BAAA,MAAM,SAAS,IAAI;AAC3B,kBAAQ,IAAI,aAAa,SAAS,MAAM,MAAM;AAAA,QAAA;AAGzC,eAAA;AAAA,MAAA;AAAA,IACT;AAAA,EAEJ;AACF;;"}
|
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
Object.defineProperty(exports, Symbol.toStringTag, { value: "Module" });
|
|
3
3
|
const path = require("node:path");
|
|
4
4
|
const vite = require("vite");
|
|
5
|
+
const startServerCore = require("@tanstack/start-server-core");
|
|
5
6
|
const debug = require("../debug.cjs");
|
|
6
|
-
const moduleId = "tanstack-start-route-tree:v";
|
|
7
7
|
function virtualRouteTreePlugin(config) {
|
|
8
8
|
const generatedRouteTreePath = vite.normalizePath(
|
|
9
9
|
path.resolve(config.generatedRouteTree)
|
|
@@ -13,10 +13,10 @@ function virtualRouteTreePlugin(config) {
|
|
|
13
13
|
enforce: "pre",
|
|
14
14
|
sharedDuringBuild: true,
|
|
15
15
|
resolveId: {
|
|
16
|
-
filter: { id: new RegExp(
|
|
16
|
+
filter: { id: new RegExp(startServerCore.VIRTUAL_MODULES.routeTree) },
|
|
17
17
|
handler(id) {
|
|
18
18
|
let resolvedId = null;
|
|
19
|
-
if (id ===
|
|
19
|
+
if (id === startServerCore.VIRTUAL_MODULES.routeTree) {
|
|
20
20
|
if (debug.debug) console.info("resolving id", id, generatedRouteTreePath);
|
|
21
21
|
resolvedId = generatedRouteTreePath;
|
|
22
22
|
}
|
|
@@ -25,6 +25,5 @@ function virtualRouteTreePlugin(config) {
|
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
27
|
}
|
|
28
|
-
exports.moduleId = moduleId;
|
|
29
28
|
exports.virtualRouteTreePlugin = virtualRouteTreePlugin;
|
|
30
29
|
//# sourceMappingURL=virtual-route-tree-plugin.cjs.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual-route-tree-plugin.cjs","sources":["../../../src/start-router-plugin/virtual-route-tree-plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { normalizePath } from 'vite'\nimport { debug } from '../debug'\nimport type { Config } from '@tanstack/router-generator'\nimport type { Plugin } from 'vite'\n\nexport
|
|
1
|
+
{"version":3,"file":"virtual-route-tree-plugin.cjs","sources":["../../../src/start-router-plugin/virtual-route-tree-plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { normalizePath } from 'vite'\nimport { VIRTUAL_MODULES } from '@tanstack/start-server-core'\nimport { debug } from '../debug'\nimport type { Config } from '@tanstack/router-generator'\nimport type { Plugin } from 'vite'\n\nexport function virtualRouteTreePlugin(config: Config): Plugin {\n const generatedRouteTreePath = normalizePath(\n path.resolve(config.generatedRouteTree),\n )\n\n return {\n name: 'tanstack-start:virtual-route-tree',\n enforce: 'pre',\n sharedDuringBuild: true,\n resolveId: {\n filter: { id: new RegExp(VIRTUAL_MODULES.routeTree) },\n handler(id) {\n let resolvedId: string | null = null\n if (id === VIRTUAL_MODULES.routeTree) {\n if (debug) console.info('resolving id', id, generatedRouteTreePath)\n resolvedId = generatedRouteTreePath\n }\n return resolvedId\n },\n },\n }\n}\n"],"names":["normalizePath","VIRTUAL_MODULES","debug"],"mappings":";;;;;;AAOO,SAAS,uBAAuB,QAAwB;AAC7D,QAAM,yBAAyBA,KAAA;AAAA,IAC7B,KAAK,QAAQ,OAAO,kBAAkB;AAAA,EACxC;AAEO,SAAA;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT,mBAAmB;AAAA,IACnB,WAAW;AAAA,MACT,QAAQ,EAAE,IAAI,IAAI,OAAOC,gBAAA,gBAAgB,SAAS,EAAE;AAAA,MACpD,QAAQ,IAAI;AACV,YAAI,aAA4B;AAC5B,YAAA,OAAOA,gCAAgB,WAAW;AACpC,cAAIC,MAAAA,MAAO,SAAQ,KAAK,gBAAgB,IAAI,sBAAsB;AACrD,uBAAA;AAAA,QAAA;AAER,eAAA;AAAA,MAAA;AAAA,IACT;AAAA,EAEJ;AACF;;"}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { tanstackRouterGenerator, tanStackRouterCodeSplitter, tanstackRouterAutoImport } from "@tanstack/router-plugin/vite";
|
|
2
|
+
import { VITE_ENVIRONMENT_NAMES } from "../constants.js";
|
|
2
3
|
import { routeTreeClientPlugin } from "./route-tree-client-plugin.js";
|
|
3
4
|
import { virtualRouteTreePlugin } from "./virtual-route-tree-plugin.js";
|
|
4
5
|
import { routesManifestPlugin } from "./generator-plugins/routes-manifest-plugin.js";
|
|
@@ -7,9 +8,32 @@ function tanStackStartRouter(config) {
|
|
|
7
8
|
return [
|
|
8
9
|
tanstackRouterGenerator({
|
|
9
10
|
...config,
|
|
10
|
-
plugins: [serverRoutesPlugin(), routesManifestPlugin()]
|
|
11
|
+
plugins: [serverRoutesPlugin(), routesManifestPlugin()],
|
|
12
|
+
plugin: {
|
|
13
|
+
vite: { environmentName: VITE_ENVIRONMENT_NAMES.client }
|
|
14
|
+
}
|
|
15
|
+
}),
|
|
16
|
+
tanStackRouterCodeSplitter({
|
|
17
|
+
...config,
|
|
18
|
+
codeSplittingOptions: {
|
|
19
|
+
...config.codeSplittingOptions,
|
|
20
|
+
deleteNodes: ["ssr"],
|
|
21
|
+
addHmr: true
|
|
22
|
+
},
|
|
23
|
+
plugin: {
|
|
24
|
+
vite: { environmentName: VITE_ENVIRONMENT_NAMES.client }
|
|
25
|
+
}
|
|
26
|
+
}),
|
|
27
|
+
tanStackRouterCodeSplitter({
|
|
28
|
+
...config,
|
|
29
|
+
codeSplittingOptions: {
|
|
30
|
+
...config.codeSplittingOptions,
|
|
31
|
+
addHmr: false
|
|
32
|
+
},
|
|
33
|
+
plugin: {
|
|
34
|
+
vite: { environmentName: VITE_ENVIRONMENT_NAMES.server }
|
|
35
|
+
}
|
|
11
36
|
}),
|
|
12
|
-
tanStackRouterCodeSplitter(config),
|
|
13
37
|
tanstackRouterAutoImport(config),
|
|
14
38
|
routeTreeClientPlugin(config),
|
|
15
39
|
virtualRouteTreePlugin(config)
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.js","sources":["../../../src/start-router-plugin/plugin.ts"],"sourcesContent":["/*\nwhat is this plugin doing, especially compared to one already existing in the @tanstack/router-plugin package?\n\nit configures:\n1. the generator to generate both the render-route-tree as well as the server-route-tree\n2. the code-splitter plugin, so it could possibly be enabled per environment (e.g. disable on the server)\n3. the auto import plugin for both environments\n4. the route tree client plugin, which removes the server part from the generated route tree\n5. the virtual route tree plugin, which provides the route tree to the server\n*/\n\nimport {\n tanStackRouterCodeSplitter,\n tanstackRouterAutoImport,\n tanstackRouterGenerator,\n} from '@tanstack/router-plugin/vite'\nimport { routeTreeClientPlugin } from './route-tree-client-plugin'\nimport { virtualRouteTreePlugin } from './virtual-route-tree-plugin'\nimport { routesManifestPlugin } from './generator-plugins/routes-manifest-plugin'\nimport { serverRoutesPlugin } from './generator-plugins/server-routes-plugin'\nimport type { PluginOption } from 'vite'\nimport type { Config } from '@tanstack/router-
|
|
1
|
+
{"version":3,"file":"plugin.js","sources":["../../../src/start-router-plugin/plugin.ts"],"sourcesContent":["/*\nwhat is this plugin doing, especially compared to one already existing in the @tanstack/router-plugin package?\n\nit configures:\n1. the generator to generate both the render-route-tree as well as the server-route-tree\n2. the code-splitter plugin, so it could possibly be enabled per environment (e.g. disable on the server)\n3. the auto import plugin for both environments\n4. the route tree client plugin, which removes the server part from the generated route tree\n5. the virtual route tree plugin, which provides the route tree to the server\n*/\n\nimport {\n tanStackRouterCodeSplitter,\n tanstackRouterAutoImport,\n tanstackRouterGenerator,\n} from '@tanstack/router-plugin/vite'\nimport { VITE_ENVIRONMENT_NAMES } from '../constants'\nimport { routeTreeClientPlugin } from './route-tree-client-plugin'\nimport { virtualRouteTreePlugin } from './virtual-route-tree-plugin'\nimport { routesManifestPlugin } from './generator-plugins/routes-manifest-plugin'\nimport { serverRoutesPlugin } from './generator-plugins/server-routes-plugin'\nimport type { PluginOption } from 'vite'\nimport type { Config } from '@tanstack/router-plugin'\n\nexport function tanStackStartRouter(config: Config): Array<PluginOption> {\n return [\n tanstackRouterGenerator({\n ...config,\n plugins: [serverRoutesPlugin(), routesManifestPlugin()],\n plugin: {\n vite: { environmentName: VITE_ENVIRONMENT_NAMES.client },\n },\n }),\n tanStackRouterCodeSplitter({\n ...config,\n codeSplittingOptions: {\n ...config.codeSplittingOptions,\n deleteNodes: ['ssr'],\n addHmr: true,\n },\n plugin: {\n vite: { environmentName: VITE_ENVIRONMENT_NAMES.client },\n },\n }),\n tanStackRouterCodeSplitter({\n ...config,\n codeSplittingOptions: {\n ...config.codeSplittingOptions,\n addHmr: false,\n },\n plugin: {\n vite: { environmentName: VITE_ENVIRONMENT_NAMES.server },\n },\n }),\n tanstackRouterAutoImport(config),\n routeTreeClientPlugin(config),\n virtualRouteTreePlugin(config),\n ]\n}\n"],"names":[],"mappings":";;;;;;AAwBO,SAAS,oBAAoB,QAAqC;AAChE,SAAA;AAAA,IACL,wBAAwB;AAAA,MACtB,GAAG;AAAA,MACH,SAAS,CAAC,sBAAsB,sBAAsB;AAAA,MACtD,QAAQ;AAAA,QACN,MAAM,EAAE,iBAAiB,uBAAuB,OAAO;AAAA,MAAA;AAAA,IACzD,CACD;AAAA,IACD,2BAA2B;AAAA,MACzB,GAAG;AAAA,MACH,sBAAsB;AAAA,QACpB,GAAG,OAAO;AAAA,QACV,aAAa,CAAC,KAAK;AAAA,QACnB,QAAQ;AAAA,MACV;AAAA,MACA,QAAQ;AAAA,QACN,MAAM,EAAE,iBAAiB,uBAAuB,OAAO;AAAA,MAAA;AAAA,IACzD,CACD;AAAA,IACD,2BAA2B;AAAA,MACzB,GAAG;AAAA,MACH,sBAAsB;AAAA,QACpB,GAAG,OAAO;AAAA,QACV,QAAQ;AAAA,MACV;AAAA,MACA,QAAQ;AAAA,QACN,MAAM,EAAE,iBAAiB,uBAAuB,OAAO;AAAA,MAAA;AAAA,IACzD,CACD;AAAA,IACD,yBAAyB,MAAM;AAAA,IAC/B,sBAAsB,MAAM;AAAA,IAC5B,uBAAuB,MAAM;AAAA,EAC/B;AACF;"}
|
|
@@ -4,6 +4,7 @@ import { parseAst, generateFromAst, logDiff } from "@tanstack/router-utils";
|
|
|
4
4
|
import { normalizePath } from "vite";
|
|
5
5
|
import { deadCodeElimination } from "babel-dead-code-elimination";
|
|
6
6
|
import { debug } from "../debug.js";
|
|
7
|
+
import { VITE_ENVIRONMENT_NAMES } from "../constants.js";
|
|
7
8
|
function routeTreeClientPlugin(config) {
|
|
8
9
|
const generatedRouteTreePath = normalizePath(
|
|
9
10
|
path.resolve(config.generatedRouteTree)
|
|
@@ -12,7 +13,7 @@ function routeTreeClientPlugin(config) {
|
|
|
12
13
|
name: "tanstack-start:route-tree-client-plugin",
|
|
13
14
|
enforce: "pre",
|
|
14
15
|
// only run this plugin in the client environment
|
|
15
|
-
applyToEnvironment: (env) => env.
|
|
16
|
+
applyToEnvironment: (env) => env.name === VITE_ENVIRONMENT_NAMES.client,
|
|
16
17
|
transform: {
|
|
17
18
|
filter: { id: generatedRouteTreePath },
|
|
18
19
|
handler(code, id) {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"route-tree-client-plugin.js","sources":["../../../src/start-router-plugin/route-tree-client-plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport * as t from '@babel/types'\nimport { generateFromAst, logDiff, parseAst } from '@tanstack/router-utils'\nimport { normalizePath } from 'vite'\nimport { deadCodeElimination } from 'babel-dead-code-elimination'\nimport { debug } from '../debug'\nimport type { Plugin } from 'vite'\nimport type { Config } from '@tanstack/router-generator'\n\n/**\n * This removes the server part from the generated route tree so that it can be used on the client.\n */\nexport function routeTreeClientPlugin(config: Config): Plugin {\n const generatedRouteTreePath = normalizePath(\n path.resolve(config.generatedRouteTree),\n )\n\n return {\n name: 'tanstack-start:route-tree-client-plugin',\n enforce: 'pre',\n // only run this plugin in the client environment\n applyToEnvironment: (env) => env.
|
|
1
|
+
{"version":3,"file":"route-tree-client-plugin.js","sources":["../../../src/start-router-plugin/route-tree-client-plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport * as t from '@babel/types'\nimport { generateFromAst, logDiff, parseAst } from '@tanstack/router-utils'\nimport { normalizePath } from 'vite'\nimport { deadCodeElimination } from 'babel-dead-code-elimination'\nimport { debug } from '../debug'\nimport { VITE_ENVIRONMENT_NAMES } from '../constants'\nimport type { Plugin } from 'vite'\nimport type { Config } from '@tanstack/router-generator'\n\n/**\n * This removes the server part from the generated route tree so that it can be used on the client.\n */\nexport function routeTreeClientPlugin(config: Config): Plugin {\n const generatedRouteTreePath = normalizePath(\n path.resolve(config.generatedRouteTree),\n )\n\n return {\n name: 'tanstack-start:route-tree-client-plugin',\n enforce: 'pre',\n // only run this plugin in the client environment\n applyToEnvironment: (env) => env.name === VITE_ENVIRONMENT_NAMES.client,\n transform: {\n filter: { id: generatedRouteTreePath },\n handler(code, id) {\n if (id !== generatedRouteTreePath) {\n return null\n }\n if (debug) console.info(`Compiling route tree for the client`, id)\n const ast = parseAst({ code, sourceFilename: id })\n\n // only keep `export const routeTree = ... `\n const filteredBody = ast.program.body.filter((node) => {\n if (t.isExportNamedDeclaration(node)) {\n if (\n node.declaration &&\n t.isVariableDeclaration(node.declaration) &&\n node.declaration.declarations.length === 1 &&\n node.declaration.declarations[0] &&\n t.isVariableDeclarator(node.declaration.declarations[0]) &&\n t.isIdentifier(node.declaration.declarations[0].id) &&\n node.declaration.declarations[0].id.name === 'routeTree'\n ) {\n return true\n }\n return false\n }\n // strip off the typescript interface & module declarations since they also reference the server routes\n if (\n t.isTSInterfaceDeclaration(node) ||\n t.isTSModuleDeclaration(node)\n ) {\n return false\n }\n return true\n })\n\n ast.program.body = filteredBody\n\n deadCodeElimination(ast)\n\n const compiled = generateFromAst(ast, {\n sourceMaps: true,\n sourceFileName: id,\n filename: id,\n })\n if (debug) {\n logDiff(code, compiled.code)\n console.log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kBAAA,MAAM,SAAS,IAAI;AAC3B,kBAAQ,IAAI,aAAa,SAAS,MAAM,MAAM;AAAA,QAAA;AAGzC,eAAA;AAAA,MAAA;AAAA,IACT;AAAA,EAEJ;AACF;"}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import path from "node:path";
|
|
2
2
|
import { normalizePath } from "vite";
|
|
3
|
+
import { VIRTUAL_MODULES } from "@tanstack/start-server-core";
|
|
3
4
|
import { debug } from "../debug.js";
|
|
4
|
-
const moduleId = "tanstack-start-route-tree:v";
|
|
5
5
|
function virtualRouteTreePlugin(config) {
|
|
6
6
|
const generatedRouteTreePath = normalizePath(
|
|
7
7
|
path.resolve(config.generatedRouteTree)
|
|
@@ -11,10 +11,10 @@ function virtualRouteTreePlugin(config) {
|
|
|
11
11
|
enforce: "pre",
|
|
12
12
|
sharedDuringBuild: true,
|
|
13
13
|
resolveId: {
|
|
14
|
-
filter: { id: new RegExp(
|
|
14
|
+
filter: { id: new RegExp(VIRTUAL_MODULES.routeTree) },
|
|
15
15
|
handler(id) {
|
|
16
16
|
let resolvedId = null;
|
|
17
|
-
if (id ===
|
|
17
|
+
if (id === VIRTUAL_MODULES.routeTree) {
|
|
18
18
|
if (debug) console.info("resolving id", id, generatedRouteTreePath);
|
|
19
19
|
resolvedId = generatedRouteTreePath;
|
|
20
20
|
}
|
|
@@ -24,7 +24,6 @@ function virtualRouteTreePlugin(config) {
|
|
|
24
24
|
};
|
|
25
25
|
}
|
|
26
26
|
export {
|
|
27
|
-
moduleId,
|
|
28
27
|
virtualRouteTreePlugin
|
|
29
28
|
};
|
|
30
29
|
//# sourceMappingURL=virtual-route-tree-plugin.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"virtual-route-tree-plugin.js","sources":["../../../src/start-router-plugin/virtual-route-tree-plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { normalizePath } from 'vite'\nimport { debug } from '../debug'\nimport type { Config } from '@tanstack/router-generator'\nimport type { Plugin } from 'vite'\n\nexport
|
|
1
|
+
{"version":3,"file":"virtual-route-tree-plugin.js","sources":["../../../src/start-router-plugin/virtual-route-tree-plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { normalizePath } from 'vite'\nimport { VIRTUAL_MODULES } from '@tanstack/start-server-core'\nimport { debug } from '../debug'\nimport type { Config } from '@tanstack/router-generator'\nimport type { Plugin } from 'vite'\n\nexport function virtualRouteTreePlugin(config: Config): Plugin {\n const generatedRouteTreePath = normalizePath(\n path.resolve(config.generatedRouteTree),\n )\n\n return {\n name: 'tanstack-start:virtual-route-tree',\n enforce: 'pre',\n sharedDuringBuild: true,\n resolveId: {\n filter: { id: new RegExp(VIRTUAL_MODULES.routeTree) },\n handler(id) {\n let resolvedId: string | null = null\n if (id === VIRTUAL_MODULES.routeTree) {\n if (debug) console.info('resolving id', id, generatedRouteTreePath)\n resolvedId = generatedRouteTreePath\n }\n return resolvedId\n },\n },\n }\n}\n"],"names":[],"mappings":";;;;AAOO,SAAS,uBAAuB,QAAwB;AAC7D,QAAM,yBAAyB;AAAA,IAC7B,KAAK,QAAQ,OAAO,kBAAkB;AAAA,EACxC;AAEO,SAAA;AAAA,IACL,MAAM;AAAA,IACN,SAAS;AAAA,IACT,mBAAmB;AAAA,IACnB,WAAW;AAAA,MACT,QAAQ,EAAE,IAAI,IAAI,OAAO,gBAAgB,SAAS,EAAE;AAAA,MACpD,QAAQ,IAAI;AACV,YAAI,aAA4B;AAC5B,YAAA,OAAO,gBAAgB,WAAW;AACpC,cAAI,MAAO,SAAQ,KAAK,gBAAgB,IAAI,sBAAsB;AACrD,uBAAA;AAAA,QAAA;AAER,eAAA;AAAA,MAAA;AAAA,IACT;AAAA,EAEJ;AACF;"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@tanstack/start-plugin-core",
|
|
3
|
-
"version": "1.
|
|
3
|
+
"version": "1.125.1",
|
|
4
4
|
"description": "Modern and scalable routing for React applications",
|
|
5
5
|
"author": "Tanner Linsley",
|
|
6
6
|
"license": "MIT",
|
|
@@ -63,12 +63,12 @@
|
|
|
63
63
|
"ufo": "^1.5.4",
|
|
64
64
|
"xmlbuilder2": "^3.1.1",
|
|
65
65
|
"zod": "^3.24.2",
|
|
66
|
-
"@tanstack/router-core": "1.
|
|
67
|
-
"@tanstack/router-plugin": "1.
|
|
66
|
+
"@tanstack/router-core": "1.125.1",
|
|
67
|
+
"@tanstack/router-plugin": "1.125.1",
|
|
68
|
+
"@tanstack/router-generator": "1.125.1",
|
|
68
69
|
"@tanstack/router-utils": "1.121.21",
|
|
69
70
|
"@tanstack/server-functions-plugin": "1.124.1",
|
|
70
|
-
"@tanstack/start-server-core": "1.
|
|
71
|
-
"@tanstack/router-generator": "1.124.2"
|
|
71
|
+
"@tanstack/start-server-core": "1.125.1"
|
|
72
72
|
},
|
|
73
73
|
"devDependencies": {
|
|
74
74
|
"vite": "^6.0.0"
|
|
@@ -14,20 +14,44 @@ import {
|
|
|
14
14
|
tanstackRouterAutoImport,
|
|
15
15
|
tanstackRouterGenerator,
|
|
16
16
|
} from '@tanstack/router-plugin/vite'
|
|
17
|
+
import { VITE_ENVIRONMENT_NAMES } from '../constants'
|
|
17
18
|
import { routeTreeClientPlugin } from './route-tree-client-plugin'
|
|
18
19
|
import { virtualRouteTreePlugin } from './virtual-route-tree-plugin'
|
|
19
20
|
import { routesManifestPlugin } from './generator-plugins/routes-manifest-plugin'
|
|
20
21
|
import { serverRoutesPlugin } from './generator-plugins/server-routes-plugin'
|
|
21
22
|
import type { PluginOption } from 'vite'
|
|
22
|
-
import type { Config } from '@tanstack/router-
|
|
23
|
+
import type { Config } from '@tanstack/router-plugin'
|
|
23
24
|
|
|
24
25
|
export function tanStackStartRouter(config: Config): Array<PluginOption> {
|
|
25
26
|
return [
|
|
26
27
|
tanstackRouterGenerator({
|
|
27
28
|
...config,
|
|
28
29
|
plugins: [serverRoutesPlugin(), routesManifestPlugin()],
|
|
30
|
+
plugin: {
|
|
31
|
+
vite: { environmentName: VITE_ENVIRONMENT_NAMES.client },
|
|
32
|
+
},
|
|
33
|
+
}),
|
|
34
|
+
tanStackRouterCodeSplitter({
|
|
35
|
+
...config,
|
|
36
|
+
codeSplittingOptions: {
|
|
37
|
+
...config.codeSplittingOptions,
|
|
38
|
+
deleteNodes: ['ssr'],
|
|
39
|
+
addHmr: true,
|
|
40
|
+
},
|
|
41
|
+
plugin: {
|
|
42
|
+
vite: { environmentName: VITE_ENVIRONMENT_NAMES.client },
|
|
43
|
+
},
|
|
44
|
+
}),
|
|
45
|
+
tanStackRouterCodeSplitter({
|
|
46
|
+
...config,
|
|
47
|
+
codeSplittingOptions: {
|
|
48
|
+
...config.codeSplittingOptions,
|
|
49
|
+
addHmr: false,
|
|
50
|
+
},
|
|
51
|
+
plugin: {
|
|
52
|
+
vite: { environmentName: VITE_ENVIRONMENT_NAMES.server },
|
|
53
|
+
},
|
|
29
54
|
}),
|
|
30
|
-
tanStackRouterCodeSplitter(config),
|
|
31
55
|
tanstackRouterAutoImport(config),
|
|
32
56
|
routeTreeClientPlugin(config),
|
|
33
57
|
virtualRouteTreePlugin(config),
|
|
@@ -4,6 +4,7 @@ import { generateFromAst, logDiff, parseAst } from '@tanstack/router-utils'
|
|
|
4
4
|
import { normalizePath } from 'vite'
|
|
5
5
|
import { deadCodeElimination } from 'babel-dead-code-elimination'
|
|
6
6
|
import { debug } from '../debug'
|
|
7
|
+
import { VITE_ENVIRONMENT_NAMES } from '../constants'
|
|
7
8
|
import type { Plugin } from 'vite'
|
|
8
9
|
import type { Config } from '@tanstack/router-generator'
|
|
9
10
|
|
|
@@ -19,7 +20,7 @@ export function routeTreeClientPlugin(config: Config): Plugin {
|
|
|
19
20
|
name: 'tanstack-start:route-tree-client-plugin',
|
|
20
21
|
enforce: 'pre',
|
|
21
22
|
// only run this plugin in the client environment
|
|
22
|
-
applyToEnvironment: (env) => env.
|
|
23
|
+
applyToEnvironment: (env) => env.name === VITE_ENVIRONMENT_NAMES.client,
|
|
23
24
|
transform: {
|
|
24
25
|
filter: { id: generatedRouteTreePath },
|
|
25
26
|
handler(code, id) {
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
import path from 'node:path'
|
|
2
2
|
import { normalizePath } from 'vite'
|
|
3
|
+
import { VIRTUAL_MODULES } from '@tanstack/start-server-core'
|
|
3
4
|
import { debug } from '../debug'
|
|
4
5
|
import type { Config } from '@tanstack/router-generator'
|
|
5
6
|
import type { Plugin } from 'vite'
|
|
6
7
|
|
|
7
|
-
export const moduleId = 'tanstack-start-route-tree:v'
|
|
8
|
-
|
|
9
8
|
export function virtualRouteTreePlugin(config: Config): Plugin {
|
|
10
9
|
const generatedRouteTreePath = normalizePath(
|
|
11
10
|
path.resolve(config.generatedRouteTree),
|
|
@@ -16,10 +15,10 @@ export function virtualRouteTreePlugin(config: Config): Plugin {
|
|
|
16
15
|
enforce: 'pre',
|
|
17
16
|
sharedDuringBuild: true,
|
|
18
17
|
resolveId: {
|
|
19
|
-
filter: { id: new RegExp(
|
|
18
|
+
filter: { id: new RegExp(VIRTUAL_MODULES.routeTree) },
|
|
20
19
|
handler(id) {
|
|
21
20
|
let resolvedId: string | null = null
|
|
22
|
-
if (id ===
|
|
21
|
+
if (id === VIRTUAL_MODULES.routeTree) {
|
|
23
22
|
if (debug) console.info('resolving id', id, generatedRouteTreePath)
|
|
24
23
|
resolvedId = generatedRouteTreePath
|
|
25
24
|
}
|