@tanstack/start-plugin-core 1.120.4-alpha.14 → 1.120.4-alpha.15

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.
@@ -36,7 +36,7 @@ function nitroPlugin(options, getSsrBundle) {
36
36
  builder: {
37
37
  sharedPlugins: true,
38
38
  async buildApp(builder) {
39
- var _a;
39
+ var _a, _b, _c;
40
40
  const clientEnv = builder.environments["client"];
41
41
  const serverEnv = builder.environments["server"];
42
42
  if (!clientEnv) {
@@ -67,11 +67,45 @@ function nitroPlugin(options, getSsrBundle) {
67
67
  renderer: plugin.ssrEntryFile,
68
68
  rollupConfig: {
69
69
  plugins: [virtualBundlePlugin(getSsrBundle())]
70
+ },
71
+ routeRules: {
72
+ // TODO: We need to expose *some* kind of routeRules configuration
73
+ // and it needs to translate to this for now. But we should
74
+ // be cognizant of the probability that we will not use Nitro's
75
+ // routeRules configuration in the future.
76
+ ...((_a = options.shell) == null ? void 0 : _a.enabled) && options.shell.autoRedirect ? {
77
+ "/**": {
78
+ // @ts-expect-error We are using this as a marker
79
+ __TSS_SHELL: true,
80
+ redirect: {
81
+ to: `${options.shell.prerender.outputPath.replace(/[/]{1,}$/, "")}`,
82
+ statusCode: 200
83
+ }
84
+ }
85
+ } : {}
70
86
  }
71
87
  };
72
88
  const nitro = await nitropack.createNitro(nitroConfig);
73
89
  await buildNitro.buildNitroEnvironment(nitro, () => nitropack.build(nitro));
74
- if ((_a = options.prerender) == null ? void 0 : _a.enabled) {
90
+ if ((_b = options.shell) == null ? void 0 : _b.enabled) {
91
+ options.prerender = {
92
+ ...options.prerender,
93
+ enabled: true
94
+ };
95
+ const maskUrl = new URL(
96
+ options.shell.maskPath,
97
+ "http://localhost"
98
+ );
99
+ maskUrl.searchParams.set("__TSS_SHELL", "true");
100
+ options.pages.push({
101
+ path: maskUrl.toString().replace("http://localhost", ""),
102
+ prerender: options.shell.prerender,
103
+ sitemap: {
104
+ exclude: true
105
+ }
106
+ });
107
+ }
108
+ if ((_c = options.prerender) == null ? void 0 : _c.enabled) {
75
109
  await prerender.prerender({
76
110
  options,
77
111
  nitro,
@@ -1 +1 @@
1
- {"version":3,"file":"nitro-plugin.cjs","sources":["../../../src/nitro/nitro-plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { rmSync } from 'node:fs'\nimport { build, createNitro } from 'nitropack'\nimport { dirname, resolve } from 'pathe'\nimport { clientDistDir, ssrEntryFile } from '../plugin'\nimport { prerender } from '../prerender'\nimport { devServerPlugin } from './dev-server-plugin'\nimport { buildNitroEnvironment } from './build-nitro'\nimport type { EnvironmentOptions, PluginOption, Rollup } from 'vite'\nimport type { 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\n return [\n devServerPlugin(),\n {\n name: 'tanstack-vite-plugin-nitro',\n configEnvironment(name) {\n if (name === '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 clientEnv = builder.environments['client']\n const serverEnv = builder.environments['server']\n\n if (!clientEnv) {\n throw new Error('Client environment not found')\n }\n\n if (!serverEnv) {\n throw new Error('SSR environment not found')\n }\n\n const clientOutputDir = resolve(options.root, clientDistDir)\n rmSync(clientOutputDir, { recursive: true, force: true })\n await builder.build(clientEnv)\n\n await builder.build(serverEnv)\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 publicAssets: [\n {\n dir: path.resolve(options.root, clientDistDir),\n },\n ],\n typescript: {\n generateTsConfig: false,\n },\n prerender: undefined,\n renderer: ssrEntryFile,\n rollupConfig: {\n plugins: [virtualBundlePlugin(getSsrBundle())],\n },\n }\n\n const nitro = await createNitro(nitroConfig)\n\n await buildNitroEnvironment(nitro, () => build(nitro))\n\n if (options.prerender?.enabled) {\n await prerender({\n options,\n nitro,\n builder,\n })\n }\n\n // if (nitroConfig.prerender?.routes?.length && options.sitemap) {\n // console.log('Building Sitemap...')\n // // sitemap needs to be built after all directories are built\n // await buildSitemap({\n // host: options.sitemap.host,\n // routes: nitroConfig.prerender.routes,\n // outputDir: resolve(options.root, 'dist/public'),\n // })\n // }\n\n // console.log(\n // `\\n\\n✅ Client and server bundles successfully built.`,\n // )\n },\n },\n }\n },\n },\n ]\n}\n\nfunction virtualBundlePlugin(ssrBundle: Rollup.OutputBundle): Rollup.Plugin {\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":["devServerPlugin","resolve","clientDistDir","rmSync","ssrEntryFile","createNitro","buildNitroEnvironment","build","prerender","dirname"],"mappings":";;;;;;;;;;AAYgB,SAAA,YACd,SACA,cACqB;AACrB,QAAM,cACJ,QAAQ,IAAI,cAAc,KAAM,QAAQ;AAEnC,SAAA;AAAA,IACLA,gCAAgB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{"version":3,"file":"nitro-plugin.cjs","sources":["../../../src/nitro/nitro-plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { rmSync } from 'node:fs'\nimport { build, createNitro } from 'nitropack'\nimport { dirname, resolve } from 'pathe'\nimport { clientDistDir, ssrEntryFile } from '../plugin'\nimport { prerender } from '../prerender'\nimport { devServerPlugin } from './dev-server-plugin'\nimport { buildNitroEnvironment } from './build-nitro'\nimport type { EnvironmentOptions, PluginOption, Rollup } from 'vite'\nimport type { 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\n return [\n devServerPlugin(),\n {\n name: 'tanstack-vite-plugin-nitro',\n configEnvironment(name) {\n if (name === '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 clientEnv = builder.environments['client']\n const serverEnv = builder.environments['server']\n\n if (!clientEnv) {\n throw new Error('Client environment not found')\n }\n\n if (!serverEnv) {\n throw new Error('SSR environment not found')\n }\n\n const clientOutputDir = resolve(options.root, clientDistDir)\n rmSync(clientOutputDir, { recursive: true, force: true })\n await builder.build(clientEnv)\n\n await builder.build(serverEnv)\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 publicAssets: [\n {\n dir: path.resolve(options.root, clientDistDir),\n },\n ],\n typescript: {\n generateTsConfig: false,\n },\n prerender: undefined,\n renderer: ssrEntryFile,\n rollupConfig: {\n plugins: [virtualBundlePlugin(getSsrBundle())],\n },\n routeRules: {\n // TODO: We need to expose *some* kind of routeRules configuration\n // and it needs to translate to this for now. But we should\n // be cognizant of the probability that we will not use Nitro's\n // routeRules configuration in the future.\n ...(options.shell?.enabled && options.shell.autoRedirect\n ? {\n '/**': {\n // @ts-expect-error We are using this as a marker\n __TSS_SHELL: true,\n redirect: {\n to: `${options.shell.prerender.outputPath.replace(/[/]{1,}$/, '')}`,\n statusCode: 200,\n },\n },\n }\n : {}),\n },\n }\n\n const nitro = await createNitro(nitroConfig)\n\n await buildNitroEnvironment(nitro, () => build(nitro))\n\n if (options.shell?.enabled) {\n options.prerender = {\n ...options.prerender,\n enabled: true,\n }\n\n const maskUrl = new URL(\n options.shell.maskPath,\n 'http://localhost',\n )\n\n maskUrl.searchParams.set('__TSS_SHELL', 'true')\n\n options.pages.push({\n path: maskUrl.toString().replace('http://localhost', ''),\n prerender: options.shell.prerender,\n sitemap: {\n exclude: true,\n },\n })\n }\n\n if (options.prerender?.enabled) {\n await prerender({\n options,\n nitro,\n builder,\n })\n }\n\n // if (nitroConfig.prerender?.routes?.length && options.sitemap) {\n // console.log('Building Sitemap...')\n // // sitemap needs to be built after all directories are built\n // await buildSitemap({\n // host: options.sitemap.host,\n // routes: nitroConfig.prerender.routes,\n // outputDir: resolve(options.root, 'dist/public'),\n // })\n // }\n\n // console.log(\n // `\\n\\n✅ Client and server bundles successfully built.`,\n // )\n },\n },\n }\n },\n },\n ]\n}\n\nfunction virtualBundlePlugin(ssrBundle: Rollup.OutputBundle): Rollup.Plugin {\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":["devServerPlugin","resolve","clientDistDir","rmSync","ssrEntryFile","createNitro","buildNitroEnvironment","build","prerender","dirname"],"mappings":";;;;;;;;;;AAYgB,SAAA,YACd,SACA,cACqB;AACrB,QAAM,cACJ,QAAQ,IAAI,cAAc,KAAM,QAAQ;AAEnC,SAAA;AAAA,IACLA,gCAAgB;AAAA,IAChB;AAAA,MACE,MAAM;AAAA,MACN,kBAAkB,MAAM;AACtB,YAAI,SAAS,UAAU;AACd,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;;AAChB,oBAAA,YAAY,QAAQ,aAAa,QAAQ;AACzC,oBAAA,YAAY,QAAQ,aAAa,QAAQ;AAE/C,kBAAI,CAAC,WAAW;AACR,sBAAA,IAAI,MAAM,8BAA8B;AAAA,cAAA;AAGhD,kBAAI,CAAC,WAAW;AACR,sBAAA,IAAI,MAAM,2BAA2B;AAAA,cAAA;AAG7C,oBAAM,kBAAkBC,MAAA,QAAQ,QAAQ,MAAMC,OAAAA,aAAa;AAC3DC,iBAAA,OAAO,iBAAiB,EAAE,WAAW,MAAM,OAAO,MAAM;AAClD,oBAAA,QAAQ,MAAM,SAAS;AAEvB,oBAAA,QAAQ,MAAM,SAAS;AAE7B,oBAAM,cAA2B;A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