@tanstack/start-plugin-core 1.120.4-alpha.13 → 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.
- package/dist/cjs/nitro/nitro-plugin.cjs +36 -2
- package/dist/cjs/nitro/nitro-plugin.cjs.map +1 -1
- package/dist/cjs/plugin.cjs +1 -2
- package/dist/cjs/plugin.cjs.map +1 -1
- package/dist/cjs/plugin.d.cts +622 -0
- package/dist/cjs/prerender.cjs +22 -13
- package/dist/cjs/prerender.cjs.map +1 -1
- package/dist/cjs/schema.cjs +15 -1
- package/dist/cjs/schema.cjs.map +1 -1
- package/dist/cjs/schema.d.cts +2297 -520
- package/dist/esm/nitro/nitro-plugin.js +36 -2
- package/dist/esm/nitro/nitro-plugin.js.map +1 -1
- package/dist/esm/plugin.d.ts +622 -0
- package/dist/esm/plugin.js +1 -2
- package/dist/esm/plugin.js.map +1 -1
- package/dist/esm/prerender.js +22 -13
- package/dist/esm/prerender.js.map +1 -1
- package/dist/esm/schema.d.ts +2297 -520
- package/dist/esm/schema.js +15 -1
- package/dist/esm/schema.js.map +1 -1
- package/package.json +3 -3
- package/src/nitro/nitro-plugin.ts +40 -0
- package/src/plugin.ts +0 -1
- package/src/prerender.ts +29 -17
- package/src/schema.ts +18 -0
|
@@ -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 ((
|
|
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;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;AAAA,gBAC/B,KAAK;AAAA;AAAA,gBAEL,mBAAmB;AAAA,gBACnB,UAAU;AAAA,gBACV,QAAQ;AAAA,gBACR,cAAc;AAAA,kBACZ;AAAA,oBACE,KAAK,KAAK,QAAQ,QAAQ,MAAMD,OAAa,aAAA;AAAA,kBAAA;AAAA,gBAEjD;AAAA,gBACA,YAAY;AAAA,kBACV,kBAAkB;AAAA,gBACpB;AAAA,gBACA,WAAW;AAAA,gBACX,UAAUE,OAAA;AAAA,gBACV,cAAc;AAAA,kBACZ,SAAS,CAAC,oBAAoB,cAAc,CAAC;AAAA,
|
|
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 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":["devServ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AAAA,IACF;AAAA,EAEJ;AACF;AAEA,SAAS,oBAAoB,WAA+C;AAEpE,QAAA,+BAAe,IAA2B;AAGhD,aAAW,CAAC,UAAU,OAAO,KAAK,OAAO,QAAQ,SAAS,GAAG;AACvD,QAAA,QAAQ,SAAS,SAAS;AAC5B,YAAM,gBAA+B;AAAA,QACnC,MAAM,QAAQ;AAAA,QACd,KAAK;AAAA,MACP;AACA,YAAM,WAAW,UAAU,GAAG,QAAQ,MAAM;AACxC,UAAA,YAAY,SAAS,SAAS,SAAS;AACzC,sBAAc,MAAM,SAAS;AAAA,MAAA;AAEtB,eAAA,IAAI,UAAU,aAAa;AACpC,eAAS,IAAIP,MAAAA,QAAQ,QAAQ,GAAG,aAAa;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,QAAQQ,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;;"}
|
package/dist/cjs/plugin.cjs
CHANGED
package/dist/cjs/plugin.cjs.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"plugin.cjs","sources":["../../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { createNitro } from 'nitropack'\nimport {\n createTanStackConfig,\n createTanStackStartOptionsSchema,\n} from './schema'\nimport { nitroPlugin } from './nitro/nitro-plugin'\nimport { startManifestPlugin } from './routesManifestPlugin'\nimport { TanStackStartCompilerPlugin } from './start-compiler-plugin'\nimport type { PluginOption, Rollup } from 'vite'\nimport type { z } from 'zod'\nimport type { CompileStartFrameworkOptions } from './compilers'\n\nconst TanStackStartOptionsSchema = createTanStackStartOptionsSchema()\nexport type TanStackStartInputConfig = z.input<\n typeof TanStackStartOptionsSchema\n>\n\nconst defaultConfig = createTanStackConfig()\nexport function getTanStackStartOptions(opts?: TanStackStartInputConfig) {\n return defaultConfig.parse(opts)\n}\n\nexport type TanStackStartOutputConfig = ReturnType<\n typeof getTanStackStartOptions\n>\n\nexport const clientDistDir = '.tanstack-start/build/client-dist'\nexport const ssrEntryFile = 'ssr.mjs'\n\n// this needs to live outside of the TanStackStartVitePluginCore since it will be invoked multiple times by vite\nlet ssrBundle: Rollup.OutputBundle\n\nexport function TanStackStartVitePluginCore(\n framework: CompileStartFrameworkOptions,\n opts: TanStackStartOutputConfig,\n): Array<PluginOption> {\n return [\n {\n name: 'tanstack-start-core:config-client',\n async config() {\n const nitroOutputPublicDir = await (async () => {\n // Create a dummy nitro app to get the resolved public output path\n const dummyNitroApp = await createNitro({\n preset: opts.target,\n compatibilityDate: '2024-12-01',\n })\n\n const nitroOutputPublicDir = dummyNitroApp.options.output.publicDir\n await dummyNitroApp.close()\n\n return nitroOutputPublicDir\n })()\n\n return {\n environments: {\n client: {\n consumer: 'client',\n build: {\n manifest: true,\n rollupOptions: {\n input: {\n main: opts.clientEntryPath,\n },\n output: {\n dir: path.resolve(opts.root, clientDistDir),\n },\n // TODO this should be removed\n external: ['node:fs', 'node:path', 'node:os', 'node:crypto'],\n },\n },\n },\n server: {\n consumer: 'server',\n build: {\n ssr: true,\n // we don't write to the file system as the below 'capture-output' plugin will\n // capture the output and write it to the virtual file system\n write: false,\n copyPublicDir: false,\n rollupOptions: {\n output: {\n entryFileNames: ssrEntryFile,\n },\n plugins: [\n {\n name: 'capture-output',\n generateBundle(options, bundle) {\n // TODO can this hook be called more than once?\n ssrBundle = bundle\n },\n },\n ],\n },\n commonjsOptions: {\n include: [/node_modules/],\n },\n },\n },\n },\n resolve: {\n noExternal: [\n '@tanstack/start-client',\n '@tanstack/start-client-core',\n '@tanstack/start-server',\n '@tanstack/start-server-core',\n '@tanstack/start-server-functions-fetcher',\n '@tanstack/start-server-functions-client',\n '@tanstack/start-server-functions-server',\n '@tanstack/start-router-manifest',\n '@tanstack/start-config',\n '@tanstack/server-functions-plugin',\n 'tanstack:start-manifest',\n 'tanstack:server-fn-manifest',\n 'nitropack',\n '@tanstack/**',\n ],\n
|
|
1
|
+
{"version":3,"file":"plugin.cjs","sources":["../../src/plugin.ts"],"sourcesContent":["import path from 'node:path'\nimport { createNitro } from 'nitropack'\nimport {\n createTanStackConfig,\n createTanStackStartOptionsSchema,\n} from './schema'\nimport { nitroPlugin } from './nitro/nitro-plugin'\nimport { startManifestPlugin } from './routesManifestPlugin'\nimport { TanStackStartCompilerPlugin } from './start-compiler-plugin'\nimport type { PluginOption, Rollup } from 'vite'\nimport type { z } from 'zod'\nimport type { CompileStartFrameworkOptions } from './compilers'\n\nconst TanStackStartOptionsSchema = createTanStackStartOptionsSchema()\nexport type TanStackStartInputConfig = z.input<\n typeof TanStackStartOptionsSchema\n>\n\nconst defaultConfig = createTanStackConfig()\nexport function getTanStackStartOptions(opts?: TanStackStartInputConfig) {\n return defaultConfig.parse(opts)\n}\n\nexport type TanStackStartOutputConfig = ReturnType<\n typeof getTanStackStartOptions\n>\n\nexport const clientDistDir = '.tanstack-start/build/client-dist'\nexport const ssrEntryFile = 'ssr.mjs'\n\n// this needs to live outside of the TanStackStartVitePluginCore since it will be invoked multiple times by vite\nlet ssrBundle: Rollup.OutputBundle\n\nexport function TanStackStartVitePluginCore(\n framework: CompileStartFrameworkOptions,\n opts: TanStackStartOutputConfig,\n): Array<PluginOption> {\n return [\n {\n name: 'tanstack-start-core:config-client',\n async config() {\n const nitroOutputPublicDir = await (async () => {\n // Create a dummy nitro app to get the resolved public output path\n const dummyNitroApp = await createNitro({\n preset: opts.target,\n compatibilityDate: '2024-12-01',\n })\n\n const nitroOutputPublicDir = dummyNitroApp.options.output.publicDir\n await dummyNitroApp.close()\n\n return nitroOutputPublicDir\n })()\n\n return {\n environments: {\n client: {\n consumer: 'client',\n build: {\n manifest: true,\n rollupOptions: {\n input: {\n main: opts.clientEntryPath,\n },\n output: {\n dir: path.resolve(opts.root, clientDistDir),\n },\n // TODO this should be removed\n external: ['node:fs', 'node:path', 'node:os', 'node:crypto'],\n },\n },\n },\n server: {\n consumer: 'server',\n build: {\n ssr: true,\n // we don't write to the file system as the below 'capture-output' plugin will\n // capture the output and write it to the virtual file system\n write: false,\n copyPublicDir: false,\n rollupOptions: {\n output: {\n entryFileNames: ssrEntryFile,\n },\n plugins: [\n {\n name: 'capture-output',\n generateBundle(options, bundle) {\n // TODO can this hook be called more than once?\n ssrBundle = bundle\n },\n },\n ],\n },\n commonjsOptions: {\n include: [/node_modules/],\n },\n },\n },\n },\n resolve: {\n noExternal: [\n '@tanstack/start-client',\n '@tanstack/start-client-core',\n '@tanstack/start-server',\n '@tanstack/start-server-core',\n '@tanstack/start-server-functions-fetcher',\n '@tanstack/start-server-functions-client',\n '@tanstack/start-server-functions-server',\n '@tanstack/start-router-manifest',\n '@tanstack/start-config',\n '@tanstack/server-functions-plugin',\n 'tanstack:start-manifest',\n 'tanstack:server-fn-manifest',\n 'nitropack',\n '@tanstack/**',\n ],\n },\n /* prettier-ignore */\n define: {\n ...injectDefineEnv('TSS_PUBLIC_BASE', opts.public.base),\n ...injectDefineEnv('TSS_CLIENT_BASE', opts.client.base),\n ...injectDefineEnv('TSS_CLIENT_ENTRY', opts.clientEntryPath),\n ...injectDefineEnv('TSS_SERVER_FN_BASE', opts.serverFns.base),\n ...injectDefineEnv('TSS_OUTPUT_PUBLIC_DIR', nitroOutputPublicDir),\n },\n }\n },\n },\n TanStackStartCompilerPlugin(framework),\n startManifestPlugin(opts),\n nitroPlugin(opts, () => ssrBundle),\n ]\n}\n\nfunction injectDefineEnv<TKey extends string, TValue extends string>(\n key: TKey,\n value: TValue,\n): { [P in `process.env.${TKey}` | `import.meta.env.${TKey}`]: TValue } {\n return {\n [`process.env.${key}`]: JSON.stringify(value),\n [`import.meta.env.${key}`]: JSON.stringify(value),\n } as { [P in `process.env.${TKey}` | `import.meta.env.${TKey}`]: TValue }\n}\n"],"names":["createTanStackStartOptionsSchema","createTanStackConfig","createNitro","nitroOutputPublicDir","TanStackStartCompilerPlugin","startManifestPlugin","nitroPlugin"],"mappings":";;;;;;;;AAamCA,OAAiC,iCAAA;AAK9CC,OAAqB,qBAAA;AASpC,MAAM,gBAAgB;AACtB,MAAM,eAAe;AAG5B,IAAI;AAEY,SAAA,4BACd,WACA,MACqB;AACd,SAAA;AAAA,IACL;AAAA,MACE,MAAM;AAAA,MACN,MAAM,SAAS;AACP,cAAA,uBAAuB,OAAO,YAAY;AAExC,gBAAA,gBAAgB,MAAMC,sBAAY;AAAA,YACtC,QAAQ,KAAK;AAAA,YACb,mBAAmB;AAAA,UAAA,CACpB;AAEKC,gBAAAA,wBAAuB,cAAc,QAAQ,OAAO;AAC1D,gBAAM,cAAc,MAAM;AAEnBA,iBAAAA;AAAAA,QAAAA,GACN;AAEI,eAAA;AAAA,UACL,cAAc;AAAA,YACZ,QAAQ;AAAA,cACN,UAAU;AAAA,cACV,OAAO;AAAA,gBACL,UAAU;AAAA,gBACV,eAAe;AAAA,kBACb,OAAO;AAAA,oBACL,MAAM,KAAK;AAAA,kBACb;AAAA,kBACA,QAAQ;AAAA,oBACN,KAAK,KAAK,QAAQ,KAAK,MAAM,aAAa;AAAA,kBAC5C;AAAA;AAAA,kBAEA,UAAU,CAAC,WAAW,aAAa,WAAW,aAAa;AAAA,gBAAA;AAAA,cAC7D;AAAA,YAEJ;AAAA,YACA,QAAQ;AAAA,cACN,UAAU;AAAA,cACV,OAAO;AAAA,gBACL,KAAK;AAAA;AAAA;AAAA,gBAGL,OAAO;AAAA,gBACP,eAAe;AAAA,gBACf,eA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