@tanstack/start-plugin-core 1.127.5 → 1.127.6

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.
@@ -90,13 +90,13 @@ function nitroPlugin(options, getSsrBundle) {
90
90
  ];
91
91
  }
92
92
  async function buildNitroApp(builder, nitro, options) {
93
- var _a, _b;
93
+ var _a, _b, _c;
94
94
  await nitropack.prepare(nitro);
95
95
  await nitropack.copyPublicAssets(nitro);
96
96
  if (((_a = options.prerender) == null ? void 0 : _a.enabled) !== false) {
97
97
  options.prerender = {
98
98
  ...options.prerender,
99
- enabled: options.pages.some(
99
+ enabled: ((_b = options.prerender) == null ? void 0 : _b.enabled) ?? options.pages.some(
100
100
  (d) => {
101
101
  var _a2;
102
102
  return typeof d === "string" ? false : !!((_a2 = d.prerender) == null ? void 0 : _a2.enabled);
@@ -104,7 +104,7 @@ async function buildNitroApp(builder, nitro, options) {
104
104
  )
105
105
  };
106
106
  }
107
- if ((_b = options.spa) == null ? void 0 : _b.enabled) {
107
+ if ((_c = options.spa) == null ? void 0 : _c.enabled) {
108
108
  options.prerender = {
109
109
  ...options.prerender,
110
110
  enabled: true
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.cjs","sources":["../../../src/nitro-plugin/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { rmSync } from 'node:fs'\nimport { build, copyPublicAssets, createNitro, prepare } from 'nitropack'\nimport { dirname, resolve } from 'pathe'\nimport {\n CLIENT_DIST_DIR,\n SSR_ENTRY_FILE,\n VITE_ENVIRONMENT_NAMES,\n} from '../constants'\nimport { buildSitemap } from './build-sitemap'\nimport { prerender } from './prerender'\nimport type {\n EnvironmentOptions,\n PluginOption,\n Rollup,\n ViteBuilder,\n} from 'vite'\nimport type { Nitro, NitroConfig } from 'nitropack'\nimport type { TanStackStartOutputConfig } from '../plugin'\n\nexport function nitroPlugin(\n options: TanStackStartOutputConfig,\n getSsrBundle: () => Rollup.OutputBundle,\n): Array<PluginOption> {\n const buildPreset =\n process.env['START_TARGET'] ?? (options.target as string | undefined)\n return [\n {\n name: 'tanstack-vite-plugin-nitro',\n configEnvironment(name) {\n if (name === VITE_ENVIRONMENT_NAMES.server) {\n return {\n build: {\n commonjsOptions: {\n include: [],\n },\n ssr: true,\n sourcemap: true,\n rollupOptions: {\n input: '/~start/server-entry',\n },\n },\n } satisfies EnvironmentOptions\n }\n\n return null\n },\n config() {\n return {\n builder: {\n sharedPlugins: true,\n async buildApp(builder) {\n const client = builder.environments[VITE_ENVIRONMENT_NAMES.client]\n const server = builder.environments[VITE_ENVIRONMENT_NAMES.server]\n\n if (!client) {\n throw new Error('Client environment not found')\n }\n\n if (!server) {\n throw new Error('SSR environment not found')\n }\n\n // Build the client bundle\n // i.e client entry file with `hydrateRoot(...)`\n const clientOutputDir = resolve(options.root, CLIENT_DIST_DIR)\n rmSync(clientOutputDir, { recursive: true, force: true })\n await builder.build(client)\n\n // Build the SSR bundle\n await builder.build(server)\n\n const nitroConfig: NitroConfig = {\n dev: false,\n // TODO: do we need this? should this be made configurable?\n compatibilityDate: '2024-11-19',\n logLevel: 3,\n preset: buildPreset,\n baseURL: globalThis.TSS_APP_BASE,\n publicAssets: [\n {\n dir: path.resolve(options.root, CLIENT_DIST_DIR),\n baseURL: '/',\n maxAge: 31536000, // 1 year\n },\n ],\n typescript: {\n generateTsConfig: false,\n },\n prerender: undefined,\n renderer: SSR_ENTRY_FILE,\n plugins: [], // Nitro's plugins\n appConfigFiles: [],\n scanDirs: [],\n imports: false, // unjs/unimport for global/magic imports\n rollupConfig: {\n plugins: [virtualBundlePlugin(getSsrBundle())],\n },\n virtual: {\n // This is Nitro's way of defining virtual modules\n // Should we define the ones for TanStack Start's here as well?\n },\n }\n\n const nitro = await createNitro(nitroConfig)\n\n await buildNitroApp(builder, nitro, options)\n },\n },\n }\n },\n },\n ]\n}\n\n/**\n * Correctly co-ordinates the nitro app build process to make sure that the\n * app is built, while also correctly handling the prerendering and sitemap\n * generation and including their outputs in the final build.\n */\nasync function buildNitroApp(\n builder: ViteBuilder,\n nitro: Nitro,\n options: TanStackStartOutputConfig,\n) {\n // Cleans the public and server directories for a fresh build\n // i.e the `.output/public` and `.output/server` directories\n await prepare(nitro)\n\n // Creates the `.output/public` directory and copies the public assets\n await copyPublicAssets(nitro)\n\n // If the user has not set a prerender option, we need to set it to true\n // if the pages array is not empty and has sub options requiring for prerendering\n if (options.prerender?.enabled !== false) {\n options.prerender = {\n ...options.prerender,\n enabled: options.pages.some((d) =>\n typeof d === 'string' ? false : !!d.prerender?.enabled,\n ),\n }\n }\n\n // Setup the options for prerendering the SPA shell (i.e `src/routes/__root.tsx`)\n if (options.spa?.enabled) {\n options.prerender = {\n ...options.prerender,\n enabled: true,\n }\n\n const maskUrl = new URL(options.spa.maskPath, 'http://localhost')\n\n options.pages.push({\n path: maskUrl.toString().replace('http://localhost', ''),\n prerender: options.spa.prerender,\n sitemap: {\n exclude: true,\n },\n })\n }\n\n // Run the prerendering process\n if (options.prerender.enabled) {\n await prerender({\n options,\n nitro,\n builder,\n })\n }\n\n // Run the sitemap build process\n if (options.pages.length) {\n buildSitemap({\n options,\n publicDir: nitro.options.output.publicDir,\n })\n }\n\n // Build the nitro app\n // We only build the nitro app, once we've prepared the public assets,\n // prerendered the pages and built the sitemap.\n // If we try to do this earlier, then the public assets may not be available\n // in the production build.\n await build(nitro)\n\n // Close the nitro instance\n await nitro.close()\n nitro.logger.success(\n 'Client and Server bundles for TanStack Start have been successfully built.',\n )\n}\n\ntype NitroRollupPluginOption = NonNullable<\n NitroConfig['rollupConfig']\n>['plugins']\n\nfunction virtualBundlePlugin(\n ssrBundle: Rollup.OutputBundle,\n): NitroRollupPluginOption {\n type VirtualModule = { code: string; map: string | null }\n const _modules = new Map<string, VirtualModule>()\n\n // group chunks and source maps\n for (const [fileName, content] of Object.entries(ssrBundle)) {\n if (content.type === 'chunk') {\n const virtualModule: VirtualModule = {\n code: content.code,\n map: null,\n }\n const maybeMap = ssrBundle[`${fileName}.map`]\n if (maybeMap && maybeMap.type === 'asset') {\n virtualModule.map = maybeMap.source as string\n }\n _modules.set(fileName, virtualModule)\n _modules.set(resolve(fileName), virtualModule)\n }\n }\n\n return {\n name: 'virtual-bundle',\n resolveId(id, importer) {\n if (_modules.has(id)) {\n return resolve(id)\n }\n\n if (importer) {\n const resolved = resolve(dirname(importer), id)\n if (_modules.has(resolved)) {\n return resolved\n }\n }\n return null\n },\n load(id) {\n const m = _modules.get(id)\n if (!m) {\n return null\n }\n return m\n },\n }\n}\n"],"names":["VITE_ENVIRONMENT_NAMES","resolve","CLIENT_DIST_DIR","rmSync","SSR_ENTRY_FILE","createNitro","prepare","copyPublicAssets","_a","prerender","buildSitemap","build","dirname"],"mappings":";;;;;;;;;AAoBgB,SAAA,YACd,SACA,cACqB;AACrB,QAAM,cACJ,QAAQ,IAAI,cAAc,KAAM,QAAQ;AACnC,SAAA;AAAA,IACL;AAAA,MACE,MAAM;AAAA,MACN,kBAAkB,MAAM;AAClB,YAAA,SAASA,iCAAuB,QAAQ;AACnC,iBAAA;AAAA,YACL,OAAO;AAAA,cACL,iBAAiB;AAAA,gBACf,SAAS,CAAA;AAAA,cACX;AAAA,cACA,KAAK;AAAA,cACL,WAAW;AAAA,cACX,eAAe;AAAA,gBACb,OAAO;AAAA,cAAA;AAAA,YACT;AAAA,UAEJ;AAAA,QAAA;AAGK,eAAA;AAAA,MACT;AAAA,MACA,SAAS;AACA,eAAA;AAAA,UACL,SAAS;AAAA,YACP,eAAe;AAAA,YACf,MAAM,SAAS,SAAS;AACtB,oBAAM,SAAS,QAAQ,aAAaA,UAAAA,uBAAuB,MAAM;AACjE,oBAAM,SAAS,QAAQ,aAAaA,UAAAA,uBAAuB,MAAM;AAEjE,kBAAI,CAAC,QAAQ;AACL,sBAAA,IAAI,MAAM,8BAA8B;AAAA,cAAA;AAGhD,kBAAI,CAAC,QAAQ;AACL,sBAAA,IAAI,MAAM,2BAA2B;AAAA,cAAA;AAK7C,oBA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AAAA,IAAA;AAAA,EAC/C;AAGK,SAAA;AAAA,IACL,MAAM;AAAA,IACN,UAAU,IAAI,UAAU;AAClB,UAAA,SAAS,IAAI,EAAE,GAAG;AACpB,eAAOA,MAAAA,QAAQ,EAAE;AAAA,MAAA;AAGnB,UAAI,UAAU;AACZ,cAAM,WAAWA,MAAA,QAAQW,MAAQ,QAAA,QAAQ,GAAG,EAAE;AAC1C,YAAA,SAAS,IAAI,QAAQ,GAAG;AACnB,iBAAA;AAAA,QAAA;AAAA,MACT;AAEK,aAAA;AAAA,IACT;AAAA,IACA,KAAK,IAAI;AACD,YAAA,IAAI,SAAS,IAAI,EAAE;AACzB,UAAI,CAAC,GAAG;AACC,eAAA;AAAA,MAAA;AAEF,aAAA;AAAA,IAAA;AAAA,EAEX;AACF;;"}
1
+ {"version":3,"file":"plugin.cjs","sources":["../../../src/nitro-plugin/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { rmSync } from 'node:fs'\nimport { build, copyPublicAssets, createNitro, prepare } from 'nitropack'\nimport { dirname, resolve } from 'pathe'\nimport {\n CLIENT_DIST_DIR,\n SSR_ENTRY_FILE,\n VITE_ENVIRONMENT_NAMES,\n} from '../constants'\nimport { buildSitemap } from './build-sitemap'\nimport { prerender } from './prerender'\nimport type {\n EnvironmentOptions,\n PluginOption,\n Rollup,\n ViteBuilder,\n} from 'vite'\nimport type { Nitro, NitroConfig } from 'nitropack'\nimport type { TanStackStartOutputConfig } from '../plugin'\n\nexport function nitroPlugin(\n options: TanStackStartOutputConfig,\n getSsrBundle: () => Rollup.OutputBundle,\n): Array<PluginOption> {\n const buildPreset =\n process.env['START_TARGET'] ?? (options.target as string | undefined)\n return [\n {\n name: 'tanstack-vite-plugin-nitro',\n configEnvironment(name) {\n if (name === VITE_ENVIRONMENT_NAMES.server) {\n return {\n build: {\n commonjsOptions: {\n include: [],\n },\n ssr: true,\n sourcemap: true,\n rollupOptions: {\n input: '/~start/server-entry',\n },\n },\n } satisfies EnvironmentOptions\n }\n\n return null\n },\n config() {\n return {\n builder: {\n sharedPlugins: true,\n async buildApp(builder) {\n const client = builder.environments[VITE_ENVIRONMENT_NAMES.client]\n const server = builder.environments[VITE_ENVIRONMENT_NAMES.server]\n\n if (!client) {\n throw new Error('Client environment not found')\n }\n\n if (!server) {\n throw new Error('SSR environment not found')\n }\n\n // Build the client bundle\n // i.e client entry file with `hydrateRoot(...)`\n const clientOutputDir = resolve(options.root, CLIENT_DIST_DIR)\n rmSync(clientOutputDir, { recursive: true, force: true })\n await builder.build(client)\n\n // Build the SSR bundle\n await builder.build(server)\n\n const nitroConfig: NitroConfig = {\n dev: false,\n // TODO: do we need this? should this be made configurable?\n compatibilityDate: '2024-11-19',\n logLevel: 3,\n preset: buildPreset,\n baseURL: globalThis.TSS_APP_BASE,\n publicAssets: [\n {\n dir: path.resolve(options.root, CLIENT_DIST_DIR),\n baseURL: '/',\n maxAge: 31536000, // 1 year\n },\n ],\n typescript: {\n generateTsConfig: false,\n },\n prerender: undefined,\n renderer: SSR_ENTRY_FILE,\n plugins: [], // Nitro's plugins\n appConfigFiles: [],\n scanDirs: [],\n imports: false, // unjs/unimport for global/magic imports\n rollupConfig: {\n plugins: [virtualBundlePlugin(getSsrBundle())],\n },\n virtual: {\n // This is Nitro's way of defining virtual modules\n // Should we define the ones for TanStack Start's here as well?\n },\n }\n\n const nitro = await createNitro(nitroConfig)\n\n await buildNitroApp(builder, nitro, options)\n },\n },\n }\n },\n },\n ]\n}\n\n/**\n * Correctly co-ordinates the nitro app build process to make sure that the\n * app is built, while also correctly handling the prerendering and sitemap\n * generation and including their outputs in the final build.\n */\nasync function buildNitroApp(\n builder: ViteBuilder,\n nitro: Nitro,\n options: TanStackStartOutputConfig,\n) {\n // Cleans the public and server directories for a fresh build\n // i.e the `.output/public` and `.output/server` directories\n await prepare(nitro)\n\n // Creates the `.output/public` directory and copies the public assets\n await copyPublicAssets(nitro)\n\n // If the user has not set a prerender option, we need to set it to true\n // if the pages array is not empty and has sub options requiring for prerendering\n // If the user has explicitly set prerender.enabled, this should be respected\n if (options.prerender?.enabled !== false) {\n options.prerender = {\n ...options.prerender,\n enabled:\n options.prerender?.enabled ??\n options.pages.some((d) =>\n typeof d === 'string' ? false : !!d.prerender?.enabled,\n ),\n }\n }\n\n // Setup the options for prerendering the SPA shell (i.e `src/routes/__root.tsx`)\n if (options.spa?.enabled) {\n options.prerender = {\n ...options.prerender,\n enabled: true,\n }\n\n const maskUrl = new URL(options.spa.maskPath, 'http://localhost')\n\n options.pages.push({\n path: maskUrl.toString().replace('http://localhost', ''),\n prerender: options.spa.prerender,\n sitemap: {\n exclude: true,\n },\n })\n }\n\n // Run the prerendering process\n if (options.prerender.enabled) {\n await prerender({\n options,\n nitro,\n builder,\n })\n }\n\n // Run the sitemap build process\n if (options.pages.length) {\n buildSitemap({\n options,\n publicDir: nitro.options.output.publicDir,\n })\n }\n\n // Build the nitro app\n // We only build the nitro app, once we've prepared the public assets,\n // prerendered the pages and built the sitemap.\n // If we try to do this earlier, then the public assets may not be available\n // in the production build.\n await build(nitro)\n\n // Close the nitro instance\n await nitro.close()\n nitro.logger.success(\n 'Client and Server bundles for TanStack Start have been successfully built.',\n )\n}\n\ntype NitroRollupPluginOption = NonNullable<\n NitroConfig['rollupConfig']\n>['plugins']\n\nfunction virtualBundlePlugin(\n ssrBundle: Rollup.OutputBundle,\n): NitroRollupPluginOption {\n type VirtualModule = { code: string; map: string | null }\n const _modules = new Map<string, VirtualModule>()\n\n // group chunks and source maps\n for (const [fileName, content] of Object.entries(ssrBundle)) {\n if (content.type === 'chunk') {\n const virtualModule: VirtualModule = {\n code: content.code,\n map: null,\n }\n const maybeMap = ssrBundle[`${fileName}.map`]\n if (maybeMap && maybeMap.type === 'asset') {\n virtualModule.map = maybeMap.source as string\n }\n _modules.set(fileName, virtualModule)\n _modules.set(resolve(fileName), virtualModule)\n }\n }\n\n return {\n name: 'virtual-bundle',\n resolveId(id, importer) {\n if (_modules.has(id)) {\n return resolve(id)\n }\n\n if (importer) {\n const resolved = resolve(dirname(importer), id)\n if (_modules.has(resolved)) {\n return resolved\n }\n }\n return null\n },\n load(id) {\n const m = _modules.get(id)\n if (!m) {\n return null\n }\n return m\n },\n }\n}\n"],"names":["VITE_ENVIRONMENT_NAMES","resolve","CLIENT_DIST_DIR","rmSync","SSR_ENTRY_FILE","createNitro","prepare","copyPublicAssets","_a","prerender","buildSitemap","build","dirname"],"mappings":";;;;;;;;;AAoBgB,SAAA,YACd,SACA,cACqB;AACrB,QAAM,cACJ,QAAQ,IAAI,cAAc,KAAM,QAAQ;AACnC,SAAA;AAAA,IACL;AAAA,MACE,MAAM;AAAA,MACN,kBAAkB,MAAM;AAClB,YAAA,SAASA,iCAAuB,QAAQ;AACnC,iBAAA;AAAA,YACL,OAAO;AAAA,cACL,iBAAiB;AAAA,gBACf,SAAS,CAAA;AAAA,cACX;AAAA,cACA,KAAK;AAAA,cACL,WAAW;AAAA,cACX,eAAe;AAAA,gBACb,OAAO;AAAA,cAAA;AAAA,YACT;AAAA,UAEJ;AAAA,QAAA;AAGK,eAAA;AAAA,MACT;AAAA,MACA,SAAS;AACA,eAAA;AAAA,UACL,SAAS;AAAA,YACP,eAAe;AAAA,YACf,MAAM,SAAS,SAAS;AACtB,oBAAM,SAAS,QAAQ,aAAaA,UAAAA,uBAAuB,MAAM;AACjE,oBAAM,SAAS,QAAQ,aAAaA,UAAAA,uBAAuB,MAAM;AAEjE,kBAAI,CAAC,QAAQ;AACL,sBAAA,IAAI,MAAM,8BAA8B;AAAA,cAAA;AAGhD,kBAAI,CAAC,QAAQ;AACL,sBAAA,IAAI,MAAM,2BAA2B;AAAA,cAAA;AAK7C,oBAAM,kBAAkBC,MAAA,QAAQ,QAAQ,MAAMC,UAAAA,eAAe;AAC7DC,sBAAA,OAAO,iBAAiB,EAAE,WAAW,MAAM,OAAO,MAAM;AAClD,oBAAA,QAAQ,MAAM,MAAM;AAGpB,oBAAA,QAAQ,MAAM,MAAM;AAE1B,oBAAM,c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UAAI,UAAU;AACZ,cAAM,WAAWA,MAAA,QAAQW,MAAQ,QAAA,QAAQ,GAAG,EAAE;AAC1C,YAAA,SAAS,IAAI,QAAQ,GAAG;AACnB,iBAAA;AAAA,QAAA;AAAA,MACT;AAEK,aAAA;AAAA,IACT;AAAA,IACA,KAAK,IAAI;AACD,YAAA,IAAI,SAAS,IAAI,EAAE;AACzB,UAAI,CAAC,GAAG;AACC,eAAA;AAAA,MAAA;AAEF,aAAA;AAAA,IAAA;AAAA,EAEX;AACF;;"}
@@ -88,13 +88,13 @@ function nitroPlugin(options, getSsrBundle) {
88
88
  ];
89
89
  }
90
90
  async function buildNitroApp(builder, nitro, options) {
91
- var _a, _b;
91
+ var _a, _b, _c;
92
92
  await prepare(nitro);
93
93
  await copyPublicAssets(nitro);
94
94
  if (((_a = options.prerender) == null ? void 0 : _a.enabled) !== false) {
95
95
  options.prerender = {
96
96
  ...options.prerender,
97
- enabled: options.pages.some(
97
+ enabled: ((_b = options.prerender) == null ? void 0 : _b.enabled) ?? options.pages.some(
98
98
  (d) => {
99
99
  var _a2;
100
100
  return typeof d === "string" ? false : !!((_a2 = d.prerender) == null ? void 0 : _a2.enabled);
@@ -102,7 +102,7 @@ async function buildNitroApp(builder, nitro, options) {
102
102
  )
103
103
  };
104
104
  }
105
- if ((_b = options.spa) == null ? void 0 : _b.enabled) {
105
+ if ((_c = options.spa) == null ? void 0 : _c.enabled) {
106
106
  options.prerender = {
107
107
  ...options.prerender,
108
108
  enabled: true
@@ -1 +1 @@
1
- {"version":3,"file":"plugin.js","sources":["../../../src/nitro-plugin/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { rmSync } from 'node:fs'\nimport { build, copyPublicAssets, createNitro, prepare } from 'nitropack'\nimport { dirname, resolve } from 'pathe'\nimport {\n CLIENT_DIST_DIR,\n SSR_ENTRY_FILE,\n VITE_ENVIRONMENT_NAMES,\n} from '../constants'\nimport { buildSitemap } from './build-sitemap'\nimport { prerender } from './prerender'\nimport type {\n EnvironmentOptions,\n PluginOption,\n Rollup,\n ViteBuilder,\n} from 'vite'\nimport type { Nitro, NitroConfig } from 'nitropack'\nimport type { TanStackStartOutputConfig } from '../plugin'\n\nexport function nitroPlugin(\n options: TanStackStartOutputConfig,\n getSsrBundle: () => Rollup.OutputBundle,\n): Array<PluginOption> {\n const buildPreset =\n process.env['START_TARGET'] ?? (options.target as string | undefined)\n return [\n {\n name: 'tanstack-vite-plugin-nitro',\n configEnvironment(name) {\n if (name === VITE_ENVIRONMENT_NAMES.server) {\n return {\n build: {\n commonjsOptions: {\n include: [],\n },\n ssr: true,\n sourcemap: true,\n rollupOptions: {\n input: '/~start/server-entry',\n },\n },\n } satisfies EnvironmentOptions\n }\n\n return null\n },\n config() {\n return {\n builder: {\n sharedPlugins: true,\n async buildApp(builder) {\n const client = builder.environments[VITE_ENVIRONMENT_NAMES.client]\n const server = builder.environments[VITE_ENVIRONMENT_NAMES.server]\n\n if (!client) {\n throw new Error('Client environment not found')\n }\n\n if (!server) {\n throw new Error('SSR environment not found')\n }\n\n // Build the client bundle\n // i.e client entry file with `hydrateRoot(...)`\n const clientOutputDir = resolve(options.root, CLIENT_DIST_DIR)\n rmSync(clientOutputDir, { recursive: true, force: true })\n await builder.build(client)\n\n // Build the SSR bundle\n await builder.build(server)\n\n const nitroConfig: NitroConfig = {\n dev: false,\n // TODO: do we need this? should this be made configurable?\n compatibilityDate: '2024-11-19',\n logLevel: 3,\n preset: buildPreset,\n baseURL: globalThis.TSS_APP_BASE,\n publicAssets: [\n {\n dir: path.resolve(options.root, CLIENT_DIST_DIR),\n baseURL: '/',\n maxAge: 31536000, // 1 year\n },\n ],\n typescript: {\n generateTsConfig: false,\n },\n prerender: undefined,\n renderer: SSR_ENTRY_FILE,\n plugins: [], // Nitro's plugins\n appConfigFiles: [],\n scanDirs: [],\n imports: false, // unjs/unimport for global/magic imports\n rollupConfig: {\n plugins: [virtualBundlePlugin(getSsrBundle())],\n },\n virtual: {\n // This is Nitro's way of defining virtual modules\n // Should we define the ones for TanStack Start's here as well?\n },\n }\n\n const nitro = await createNitro(nitroConfig)\n\n await buildNitroApp(builder, nitro, options)\n },\n },\n }\n },\n },\n ]\n}\n\n/**\n * Correctly co-ordinates the nitro app build process to make sure that the\n * app is built, while also correctly handling the prerendering and sitemap\n * generation and including their outputs in the final build.\n */\nasync function buildNitroApp(\n builder: ViteBuilder,\n nitro: Nitro,\n options: TanStackStartOutputConfig,\n) {\n // Cleans the public and server directories for a fresh build\n // i.e the `.output/public` and `.output/server` directories\n await prepare(nitro)\n\n // Creates the `.output/public` directory and copies the public assets\n await copyPublicAssets(nitro)\n\n // If the user has not set a prerender option, we need to set it to true\n // if the pages array is not empty and has sub options requiring for prerendering\n if (options.prerender?.enabled !== false) {\n options.prerender = {\n ...options.prerender,\n enabled: options.pages.some((d) =>\n typeof d === 'string' ? false : !!d.prerender?.enabled,\n ),\n }\n }\n\n // Setup the options for prerendering the SPA shell (i.e `src/routes/__root.tsx`)\n if (options.spa?.enabled) {\n options.prerender = {\n ...options.prerender,\n enabled: true,\n }\n\n const maskUrl = new URL(options.spa.maskPath, 'http://localhost')\n\n options.pages.push({\n path: maskUrl.toString().replace('http://localhost', ''),\n prerender: options.spa.prerender,\n sitemap: {\n exclude: true,\n },\n })\n }\n\n // Run the prerendering process\n if (options.prerender.enabled) {\n await prerender({\n options,\n nitro,\n builder,\n })\n }\n\n // Run the sitemap build process\n if (options.pages.length) {\n buildSitemap({\n options,\n publicDir: nitro.options.output.publicDir,\n })\n }\n\n // Build the nitro app\n // We only build the nitro app, once we've prepared the public assets,\n // prerendered the pages and built the sitemap.\n // If we try to do this earlier, then the public assets may not be available\n // in the production build.\n await build(nitro)\n\n // Close the nitro instance\n await nitro.close()\n nitro.logger.success(\n 'Client and Server bundles for TanStack Start have been successfully built.',\n )\n}\n\ntype NitroRollupPluginOption = NonNullable<\n NitroConfig['rollupConfig']\n>['plugins']\n\nfunction virtualBundlePlugin(\n ssrBundle: Rollup.OutputBundle,\n): NitroRollupPluginOption {\n type VirtualModule = { code: string; map: string | null }\n const _modules = new Map<string, VirtualModule>()\n\n // group chunks and source maps\n for (const [fileName, content] of Object.entries(ssrBundle)) {\n if (content.type === 'chunk') {\n const virtualModule: VirtualModule = {\n code: content.code,\n map: null,\n }\n const maybeMap = ssrBundle[`${fileName}.map`]\n if (maybeMap && maybeMap.type === 'asset') {\n virtualModule.map = maybeMap.source as string\n }\n _modules.set(fileName, virtualModule)\n _modules.set(resolve(fileName), virtualModule)\n }\n }\n\n return {\n name: 'virtual-bundle',\n resolveId(id, importer) {\n if (_modules.has(id)) {\n return resolve(id)\n }\n\n if (importer) {\n const resolved = resolve(dirname(importer), id)\n if (_modules.has(resolved)) {\n return resolved\n }\n }\n return null\n },\n load(id) {\n const m = _modules.get(id)\n if (!m) {\n return null\n }\n return m\n },\n }\n}\n"],"names":["_a"],"mappings":";;;;;;;AAoBgB,SAAA,YACd,SACA,cACqB;AACrB,QAAM,cACJ,QAAQ,IAAI,cAAc,KAAM,QAAQ;AACnC,SAAA;AAAA,IACL;AAAA,MACE,MAAM;AAAA,MACN,kBAAkB,MAAM;AAClB,YAAA,SAAS,uBAAuB,QAAQ;AACnC,iBAAA;AAAA,YACL,OAAO;AAAA,cACL,iBAAiB;AAAA,gBACf,SAAS,CAAA;AAAA,cACX;AAAA,cACA,KAAK;AAAA,cACL,WAAW;AAAA,cACX,eAAe;AAAA,gBACb,OAAO;AAAA,cAAA;AAAA,YACT;AAAA,UAEJ;AAAA,QAAA;AAGK,eAAA;AAAA,MACT;AAAA,MACA,SAAS;AACA,eAAA;AAAA,UACL,SAAS;AAAA,YACP,eAAe;AAAA,YACf,MAAM,SAAS,SAAS;AACtB,oBAAM,SAAS,QAAQ,aAAa,uBAAuB,MAAM;AACjE,oBAAM,SAAS,QAAQ,aAAa,uBAAuB,MAAM;AAEjE,kBAAI,CAAC,QAAQ;AACL,sBAAA,IAAI,MAAM,8BAA8B;AAAA,cAAA;AAGhD,kBAAI,CAA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EAC/C;AAGK,SAAA;AAAA,IACL,MAAM;AAAA,IACN,UAAU,IAAI,UAAU;AAClB,UAAA,SAAS,IAAI,EAAE,GAAG;AACpB,eAAO,QAAQ,EAAE;AAAA,MAAA;AAGnB,UAAI,UAAU;AACZ,cAAM,WAAW,QAAQ,QAAQ,QAAQ,GAAG,EAAE;AAC1C,YAAA,SAAS,IAAI,QAAQ,GAAG;AACnB,iBAAA;AAAA,QAAA;AAAA,MACT;AAEK,aAAA;AAAA,IACT;AAAA,IACA,KAAK,IAAI;AACD,YAAA,IAAI,SAAS,IAAI,EAAE;AACzB,UAAI,CAAC,GAAG;AACC,eAAA;AAAA,MAAA;AAEF,aAAA;AAAA,IAAA;AAAA,EAEX;AACF;"}
1
+ {"version":3,"file":"plugin.js","sources":["../../../src/nitro-plugin/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { rmSync } from 'node:fs'\nimport { build, copyPublicAssets, createNitro, prepare } from 'nitropack'\nimport { dirname, resolve } from 'pathe'\nimport {\n CLIENT_DIST_DIR,\n SSR_ENTRY_FILE,\n VITE_ENVIRONMENT_NAMES,\n} from '../constants'\nimport { buildSitemap } from './build-sitemap'\nimport { prerender } from './prerender'\nimport type {\n EnvironmentOptions,\n PluginOption,\n Rollup,\n ViteBuilder,\n} from 'vite'\nimport type { Nitro, NitroConfig } from 'nitropack'\nimport type { TanStackStartOutputConfig } from '../plugin'\n\nexport function nitroPlugin(\n options: TanStackStartOutputConfig,\n getSsrBundle: () => Rollup.OutputBundle,\n): Array<PluginOption> {\n const buildPreset =\n process.env['START_TARGET'] ?? (options.target as string | undefined)\n return [\n {\n name: 'tanstack-vite-plugin-nitro',\n configEnvironment(name) {\n if (name === VITE_ENVIRONMENT_NAMES.server) {\n return {\n build: {\n commonjsOptions: {\n include: [],\n },\n ssr: true,\n sourcemap: true,\n rollupOptions: {\n input: '/~start/server-entry',\n },\n },\n } satisfies EnvironmentOptions\n }\n\n return null\n },\n config() {\n return {\n builder: {\n sharedPlugins: true,\n async buildApp(builder) {\n const client = builder.environments[VITE_ENVIRONMENT_NAMES.client]\n const server = builder.environments[VITE_ENVIRONMENT_NAMES.server]\n\n if (!client) {\n throw new Error('Client environment not found')\n }\n\n if (!server) {\n throw new Error('SSR environment not found')\n }\n\n // Build the client bundle\n // i.e client entry file with `hydrateRoot(...)`\n const clientOutputDir = resolve(options.root, CLIENT_DIST_DIR)\n rmSync(clientOutputDir, { recursive: true, force: true })\n await builder.build(client)\n\n // Build the SSR bundle\n await builder.build(server)\n\n const nitroConfig: NitroConfig = {\n dev: false,\n // TODO: do we need this? should this be made configurable?\n compatibilityDate: '2024-11-19',\n logLevel: 3,\n preset: buildPreset,\n baseURL: globalThis.TSS_APP_BASE,\n publicAssets: [\n {\n dir: path.resolve(options.root, CLIENT_DIST_DIR),\n baseURL: '/',\n maxAge: 31536000, // 1 year\n },\n ],\n typescript: {\n generateTsConfig: false,\n },\n prerender: undefined,\n renderer: SSR_ENTRY_FILE,\n plugins: [], // Nitro's plugins\n appConfigFiles: [],\n scanDirs: [],\n imports: false, // unjs/unimport for global/magic imports\n rollupConfig: {\n plugins: [virtualBundlePlugin(getSsrBundle())],\n },\n virtual: {\n // This is Nitro's way of defining virtual modules\n // Should we define the ones for TanStack Start's here as well?\n },\n }\n\n const nitro = await createNitro(nitroConfig)\n\n await buildNitroApp(builder, nitro, options)\n },\n },\n }\n },\n },\n ]\n}\n\n/**\n * Correctly co-ordinates the nitro app build process to make sure that the\n * app is built, while also correctly handling the prerendering and sitemap\n * generation and including their outputs in the final build.\n */\nasync function buildNitroApp(\n builder: ViteBuilder,\n nitro: Nitro,\n options: TanStackStartOutputConfig,\n) {\n // Cleans the public and server directories for a fresh build\n // i.e the `.output/public` and `.output/server` directories\n await prepare(nitro)\n\n // Creates the `.output/public` directory and copies the public assets\n await copyPublicAssets(nitro)\n\n // If the user has not set a prerender option, we need to set it to true\n // if the pages array is not empty and has sub options requiring for prerendering\n // If the user has explicitly set prerender.enabled, this should be respected\n if (options.prerender?.enabled !== false) {\n options.prerender = {\n ...options.prerender,\n enabled:\n options.prerender?.enabled ??\n options.pages.some((d) =>\n typeof d === 'string' ? false : !!d.prerender?.enabled,\n ),\n }\n }\n\n // Setup the options for prerendering the SPA shell (i.e `src/routes/__root.tsx`)\n if (options.spa?.enabled) {\n options.prerender = {\n ...options.prerender,\n enabled: true,\n }\n\n const maskUrl = new URL(options.spa.maskPath, 'http://localhost')\n\n options.pages.push({\n path: maskUrl.toString().replace('http://localhost', ''),\n prerender: options.spa.prerender,\n sitemap: {\n exclude: true,\n },\n })\n }\n\n // Run the prerendering process\n if (options.prerender.enabled) {\n await prerender({\n options,\n nitro,\n builder,\n })\n }\n\n // Run the sitemap build process\n if (options.pages.length) {\n buildSitemap({\n options,\n publicDir: nitro.options.output.publicDir,\n })\n }\n\n // Build the nitro app\n // We only build the nitro app, once we've prepared the public assets,\n // prerendered the pages and built the sitemap.\n // If we try to do this earlier, then the public assets may not be available\n // in the production build.\n await build(nitro)\n\n // Close the nitro instance\n await nitro.close()\n nitro.logger.success(\n 'Client and Server bundles for TanStack Start have been successfully built.',\n )\n}\n\ntype NitroRollupPluginOption = NonNullable<\n NitroConfig['rollupConfig']\n>['plugins']\n\nfunction virtualBundlePlugin(\n ssrBundle: Rollup.OutputBundle,\n): NitroRollupPluginOption {\n type VirtualModule = { code: string; map: string | null }\n const _modules = new Map<string, VirtualModule>()\n\n // group chunks and source maps\n for (const [fileName, content] of Object.entries(ssrBundle)) {\n if (content.type === 'chunk') {\n const virtualModule: VirtualModule = {\n code: content.code,\n map: null,\n }\n const maybeMap = ssrBundle[`${fileName}.map`]\n if (maybeMap && maybeMap.type === 'asset') {\n virtualModule.map = maybeMap.source as string\n }\n _modules.set(fileName, virtualModule)\n _modules.set(resolve(fileName), virtualModule)\n }\n }\n\n return {\n name: 'virtual-bundle',\n resolveId(id, importer) {\n if (_modules.has(id)) {\n return resolve(id)\n }\n\n if (importer) {\n const resolved = resolve(dirname(importer), id)\n if (_modules.has(resolved)) {\n return resolved\n }\n }\n return null\n },\n load(id) {\n const m = _modules.get(id)\n if (!m) {\n return null\n }\n return m\n },\n }\n}\n"],"names":["_a"],"mappings":";;;;;;;AAoBgB,SAAA,YACd,SACA,cACqB;AACrB,QAAM,cACJ,QAAQ,IAAI,cAAc,KAAM,QAAQ;AACnC,SAAA;AAAA,IACL;AAAA,MACE,MAAM;AAAA,MACN,kBAAkB,MAAM;AAClB,YAAA,SAAS,uBAAuB,QAAQ;AACnC,iBAAA;AAAA,YACL,OAAO;AAAA,cACL,iBAAiB;AAAA,gBACf,SAAS,CAAA;AAAA,cACX;AAAA,cACA,KAAK;AAAA,cACL,WAAW;AAAA,cACX,eAAe;AAAA,gBACb,OAAO;AAAA,cAAA;AAAA,YACT;AAAA,UAEJ;AAAA,QAAA;AAGK,eAAA;AAAA,MACT;AAAA,MACA,SAAS;AACA,eAAA;AAAA,UACL,SAAS;AAAA,YACP,eAAe;AAAA,YACf,MAAM,SAAS,SAAS;AACtB,oBAAM,SAAS,QAAQ,aAAa,uBAAuB,MAAM;AACjE,oBAAM,SAAS,QAAQ,aAAa,uBAAuB,MAAM;AAEjE,kBAAI,CAAC,QAAQ;AACL,sBAAA,IAAI,MAAM,8BAA8B;AAAA,cAAA;AAGhD,kBAAI,CAAC,QAAQ;AACL,sBAAA,IAAI,MAAM,2BAA2B;AAAA,cAAA;AAK7C,oBAAM,kBAAkB,QAAQ,QAAQ,MAAM,eAAe;AAC7D,qBAAO,iBAAiB,EAAE,WAAW,MAAM,OAAO,MAAM;AAClD,oBAAA,QAAQ,MAAM,MAAM;AAGpB,oBAAA,QAAQ,MAAM,MAAM;AAE1B,oBAAM,cAA2B;AAAA,gBAC/B,KAAK;AAAA;AAAA,gBAEL,mBAAmB;AAAA,gBACnB,UAAU;AAAA,gBACV,QAAQ;AAAA,gBACR,SAAS,WAAW;AAAA,gBACpB,cAAc;AAAA,kBACZ;AAAA,oBACE,KAAK,KAAK,QAAQ,QAAQ,MAAM,e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A;AAEF,aAAA;AAAA,IAAA;AAAA,EAEX;AACF;"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tanstack/start-plugin-core",
3
- "version": "1.127.5",
3
+ "version": "1.127.6",
4
4
  "description": "Modern and scalable routing for React applications",
5
5
  "author": "Tanner Linsley",
6
6
  "license": "MIT",
@@ -63,11 +63,11 @@
63
63
  "ufo": "^1.5.4",
64
64
  "xmlbuilder2": "^3.1.1",
65
65
  "zod": "^3.24.2",
66
- "@tanstack/router-utils": "1.121.21",
67
66
  "@tanstack/router-core": "1.127.3",
68
- "@tanstack/router-generator": "1.127.5",
69
67
  "@tanstack/router-plugin": "1.127.5",
68
+ "@tanstack/router-utils": "1.121.21",
70
69
  "@tanstack/server-functions-plugin": "1.124.1",
70
+ "@tanstack/router-generator": "1.127.5",
71
71
  "@tanstack/start-server-core": "1.127.3"
72
72
  },
73
73
  "devDependencies": {
@@ -132,12 +132,15 @@ async function buildNitroApp(
132
132
 
133
133
  // If the user has not set a prerender option, we need to set it to true
134
134
  // if the pages array is not empty and has sub options requiring for prerendering
135
+ // If the user has explicitly set prerender.enabled, this should be respected
135
136
  if (options.prerender?.enabled !== false) {
136
137
  options.prerender = {
137
138
  ...options.prerender,
138
- enabled: options.pages.some((d) =>
139
- typeof d === 'string' ? false : !!d.prerender?.enabled,
140
- ),
139
+ enabled:
140
+ options.prerender?.enabled ??
141
+ options.pages.some((d) =>
142
+ typeof d === 'string' ? false : !!d.prerender?.enabled,
143
+ ),
141
144
  }
142
145
  }
143
146