@tanstack/start-plugin-core 1.131.6 → 1.132.0-alpha.0

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.
Files changed (146) hide show
  1. package/dist/esm/{nitro-plugin/build-sitemap.d.ts → build-sitemap.d.ts} +3 -3
  2. package/dist/esm/{nitro-plugin/build-sitemap.js → build-sitemap.js} +19 -24
  3. package/dist/esm/build-sitemap.js.map +1 -0
  4. package/dist/esm/compilers.js +7 -10
  5. package/dist/esm/compilers.js.map +1 -1
  6. package/dist/esm/constants.d.ts +6 -2
  7. package/dist/esm/constants.js +7 -10
  8. package/dist/esm/constants.js.map +1 -1
  9. package/dist/esm/debug.js.map +1 -1
  10. package/dist/esm/dev-server-plugin/extract-html-scripts.js.map +1 -1
  11. package/dist/esm/dev-server-plugin/plugin.d.ts +5 -5
  12. package/dist/esm/dev-server-plugin/plugin.js +117 -79
  13. package/dist/esm/dev-server-plugin/plugin.js.map +1 -1
  14. package/dist/esm/index.d.ts +1 -1
  15. package/dist/esm/index.js +0 -4
  16. package/dist/esm/index.js.map +1 -1
  17. package/dist/esm/load-env-plugin/plugin.d.ts +2 -3
  18. package/dist/esm/load-env-plugin/plugin.js +5 -8
  19. package/dist/esm/load-env-plugin/plugin.js.map +1 -1
  20. package/dist/esm/output-directory.d.ts +3 -0
  21. package/dist/esm/output-directory.js +14 -0
  22. package/dist/esm/output-directory.js.map +1 -0
  23. package/dist/esm/plugin.d.ts +6 -290
  24. package/dist/esm/plugin.js +123 -76
  25. package/dist/esm/plugin.js.map +1 -1
  26. package/dist/esm/post-server-build.d.ts +7 -0
  27. package/dist/esm/post-server-build.js +55 -0
  28. package/dist/esm/post-server-build.js.map +1 -0
  29. package/dist/esm/prerender.d.ts +11 -0
  30. package/dist/esm/{nitro-plugin/prerender.js → prerender.js} +85 -73
  31. package/dist/esm/prerender.js.map +1 -0
  32. package/dist/esm/{nitro-plugin/queue.js → queue.js} +7 -10
  33. package/dist/esm/queue.js.map +1 -0
  34. package/dist/esm/resolve-entries.d.ts +8 -0
  35. package/dist/esm/resolve-entries.js +37 -0
  36. package/dist/esm/resolve-entries.js.map +1 -0
  37. package/dist/esm/schema.d.ts +1369 -6719
  38. package/dist/esm/schema.js +52 -85
  39. package/dist/esm/schema.js.map +1 -1
  40. package/dist/esm/start-compiler-plugin.js +2 -2
  41. package/dist/esm/start-compiler-plugin.js.map +1 -1
  42. package/dist/esm/start-manifest-plugin/plugin.d.ts +1 -1
  43. package/dist/esm/start-manifest-plugin/plugin.js +8 -13
  44. package/dist/esm/start-manifest-plugin/plugin.js.map +1 -1
  45. package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js +2 -3
  46. package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js.map +1 -1
  47. package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.js +2 -4
  48. package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.js.map +1 -1
  49. package/dist/esm/start-router-plugin/plugin.js.map +1 -1
  50. package/dist/esm/start-router-plugin/route-tree-client-plugin.js.map +1 -1
  51. package/dist/esm/start-router-plugin/virtual-route-tree-plugin.js.map +1 -1
  52. package/dist/esm/utils.js.map +1 -1
  53. package/package.json +13 -18
  54. package/src/{nitro-plugin/build-sitemap.ts → build-sitemap.ts} +8 -8
  55. package/src/constants.ts +12 -9
  56. package/src/dev-server-plugin/plugin.ts +140 -99
  57. package/src/global.d.ts +0 -2
  58. package/src/index.ts +1 -5
  59. package/src/load-env-plugin/plugin.ts +6 -11
  60. package/src/output-directory.ts +18 -0
  61. package/src/plugin.ts +160 -98
  62. package/src/post-server-build.ts +73 -0
  63. package/src/{nitro-plugin/prerender.ts → prerender.ts} +93 -86
  64. package/src/resolve-entries.ts +52 -0
  65. package/src/schema.ts +88 -121
  66. package/src/start-manifest-plugin/plugin.ts +8 -14
  67. package/dist/cjs/compilers.cjs +0 -416
  68. package/dist/cjs/compilers.cjs.map +0 -1
  69. package/dist/cjs/compilers.d.cts +0 -21
  70. package/dist/cjs/constants.cjs +0 -20
  71. package/dist/cjs/constants.cjs.map +0 -1
  72. package/dist/cjs/constants.d.cts +0 -6
  73. package/dist/cjs/debug.cjs +0 -5
  74. package/dist/cjs/debug.cjs.map +0 -1
  75. package/dist/cjs/debug.d.cts +0 -1
  76. package/dist/cjs/dev-server-plugin/extract-html-scripts.cjs +0 -35
  77. package/dist/cjs/dev-server-plugin/extract-html-scripts.cjs.map +0 -1
  78. package/dist/cjs/dev-server-plugin/extract-html-scripts.d.cts +0 -4
  79. package/dist/cjs/dev-server-plugin/plugin.cjs +0 -121
  80. package/dist/cjs/dev-server-plugin/plugin.cjs.map +0 -1
  81. package/dist/cjs/dev-server-plugin/plugin.d.cts +0 -5
  82. package/dist/cjs/index.cjs +0 -11
  83. package/dist/cjs/index.cjs.map +0 -1
  84. package/dist/cjs/index.d.cts +0 -3
  85. package/dist/cjs/load-env-plugin/plugin.cjs +0 -34
  86. package/dist/cjs/load-env-plugin/plugin.cjs.map +0 -1
  87. package/dist/cjs/load-env-plugin/plugin.d.cts +0 -3
  88. package/dist/cjs/nitro-plugin/build-sitemap.cjs +0 -138
  89. package/dist/cjs/nitro-plugin/build-sitemap.cjs.map +0 -1
  90. package/dist/cjs/nitro-plugin/build-sitemap.d.cts +0 -31
  91. package/dist/cjs/nitro-plugin/plugin.cjs +0 -187
  92. package/dist/cjs/nitro-plugin/plugin.cjs.map +0 -1
  93. package/dist/cjs/nitro-plugin/plugin.d.cts +0 -3
  94. package/dist/cjs/nitro-plugin/prerender.cjs +0 -178
  95. package/dist/cjs/nitro-plugin/prerender.cjs.map +0 -1
  96. package/dist/cjs/nitro-plugin/prerender.d.cts +0 -8
  97. package/dist/cjs/nitro-plugin/queue.cjs +0 -131
  98. package/dist/cjs/nitro-plugin/queue.cjs.map +0 -1
  99. package/dist/cjs/nitro-plugin/queue.d.cts +0 -32
  100. package/dist/cjs/plugin.cjs +0 -227
  101. package/dist/cjs/plugin.cjs.map +0 -1
  102. package/dist/cjs/plugin.d.cts +0 -300
  103. package/dist/cjs/resolve-virtual-entries-plugin/plugin.cjs +0 -80
  104. package/dist/cjs/resolve-virtual-entries-plugin/plugin.cjs.map +0 -1
  105. package/dist/cjs/resolve-virtual-entries-plugin/plugin.d.cts +0 -3
  106. package/dist/cjs/schema.cjs +0 -158
  107. package/dist/cjs/schema.cjs.map +0 -1
  108. package/dist/cjs/schema.d.cts +0 -8878
  109. package/dist/cjs/start-compiler-plugin.cjs +0 -78
  110. package/dist/cjs/start-compiler-plugin.cjs.map +0 -1
  111. package/dist/cjs/start-compiler-plugin.d.cts +0 -13
  112. package/dist/cjs/start-manifest-plugin/plugin.cjs +0 -182
  113. package/dist/cjs/start-manifest-plugin/plugin.cjs.map +0 -1
  114. package/dist/cjs/start-manifest-plugin/plugin.d.cts +0 -6
  115. package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.cjs +0 -39
  116. package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.cjs.map +0 -1
  117. package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.d.cts +0 -6
  118. package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.cjs +0 -121
  119. package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.cjs.map +0 -1
  120. package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.d.cts +0 -2
  121. package/dist/cjs/start-router-plugin/plugin.cjs +0 -45
  122. package/dist/cjs/start-router-plugin/plugin.cjs.map +0 -1
  123. package/dist/cjs/start-router-plugin/plugin.d.cts +0 -3
  124. package/dist/cjs/start-router-plugin/route-tree-client-plugin.cjs +0 -73
  125. package/dist/cjs/start-router-plugin/route-tree-client-plugin.cjs.map +0 -1
  126. package/dist/cjs/start-router-plugin/route-tree-client-plugin.d.cts +0 -6
  127. package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.cjs +0 -29
  128. package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.cjs.map +0 -1
  129. package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.d.cts +0 -3
  130. package/dist/cjs/utils.cjs +0 -18
  131. package/dist/cjs/utils.cjs.map +0 -1
  132. package/dist/cjs/utils.d.cts +0 -8
  133. package/dist/esm/nitro-plugin/build-sitemap.js.map +0 -1
  134. package/dist/esm/nitro-plugin/plugin.d.ts +0 -3
  135. package/dist/esm/nitro-plugin/plugin.js +0 -187
  136. package/dist/esm/nitro-plugin/plugin.js.map +0 -1
  137. package/dist/esm/nitro-plugin/prerender.d.ts +0 -8
  138. package/dist/esm/nitro-plugin/prerender.js.map +0 -1
  139. package/dist/esm/nitro-plugin/queue.js.map +0 -1
  140. package/dist/esm/resolve-virtual-entries-plugin/plugin.d.ts +0 -3
  141. package/dist/esm/resolve-virtual-entries-plugin/plugin.js +0 -63
  142. package/dist/esm/resolve-virtual-entries-plugin/plugin.js.map +0 -1
  143. package/src/nitro-plugin/plugin.ts +0 -252
  144. package/src/resolve-virtual-entries-plugin/plugin.ts +0 -77
  145. /package/dist/esm/{nitro-plugin/queue.d.ts → queue.d.ts} +0 -0
  146. /package/src/{nitro-plugin/queue.ts → queue.ts} +0 -0
@@ -1,8 +1,8 @@
1
1
  import { writeFileSync } from 'node:fs'
2
2
  import path from 'node:path'
3
3
  import { create } from 'xmlbuilder2'
4
- import { createLogger } from '../utils'
5
- import type { TanStackStartOutputConfig } from '../plugin'
4
+ import { createLogger } from './utils'
5
+ import type { TanStackStartOutputConfig } from './schema'
6
6
  import type { XMLBuilder } from 'xmlbuilder2/lib/interfaces'
7
7
 
8
8
  export type SitemapUrl = {
@@ -123,17 +123,17 @@ function jsonToXml(sitemapData: SitemapData): string {
123
123
  }
124
124
 
125
125
  export function buildSitemap({
126
- options,
126
+ startConfig,
127
127
  publicDir,
128
128
  }: {
129
- options: TanStackStartOutputConfig
129
+ startConfig: TanStackStartOutputConfig
130
130
  publicDir: string
131
131
  }) {
132
132
  const logger = createLogger('sitemap')
133
133
 
134
- let sitemapOptions = options.sitemap
134
+ let sitemapOptions = startConfig.sitemap
135
135
 
136
- if (!sitemapOptions && options.pages.length) {
136
+ if (!sitemapOptions && startConfig.pages.length) {
137
137
  sitemapOptions = { enabled: true, outputPath: 'sitemap.xml' }
138
138
  }
139
139
 
@@ -144,7 +144,7 @@ export function buildSitemap({
144
144
  const { host, outputPath } = sitemapOptions
145
145
 
146
146
  if (!host) {
147
- if (!options.sitemap) {
147
+ if (!startConfig.sitemap) {
148
148
  logger.info(
149
149
  'Hint: Pages found, but no sitemap host has been set. To enable sitemap generation, set the `sitemap.host` option.',
150
150
  )
@@ -159,7 +159,7 @@ export function buildSitemap({
159
159
  throw new Error('Sitemap output path is not set')
160
160
  }
161
161
 
162
- const { pages } = options
162
+ const { pages } = startConfig
163
163
 
164
164
  if (!pages.length) {
165
165
  logger.info('No pages were found to build the sitemap. Skipping...')
package/src/constants.ts CHANGED
@@ -1,5 +1,3 @@
1
- import path from 'node:path'
2
-
3
1
  export const VITE_ENVIRONMENT_NAMES = {
4
2
  // 'ssr' is chosen as the name for the server environment to ensure backwards compatibility
5
3
  // with vite plugins that are not compatible with the new vite environment API (e.g. tailwindcss)
@@ -7,10 +5,15 @@ export const VITE_ENVIRONMENT_NAMES = {
7
5
  client: 'client',
8
6
  } as const
9
7
 
10
- export const CLIENT_DIST_DIR = path.join(
11
- '.tanstack',
12
- 'start',
13
- 'build',
14
- 'client-dist',
15
- )
16
- export const SSR_ENTRY_FILE = 'ssr.mjs'
8
+ export type ViteEnvironmentNames =
9
+ (typeof VITE_ENVIRONMENT_NAMES)[keyof typeof VITE_ENVIRONMENT_NAMES]
10
+
11
+ // for client and router:
12
+ // if a user has a custom server/client entry point file, resolve.alias will point to this
13
+ // otherwise it will be aliased to the default entry point in the respective framework plugin
14
+ export const ENTRY_POINTS = {
15
+ client: 'virtual:tanstack-start-client-entry',
16
+ server: 'virtual:tanstack-start-server-request-entry',
17
+ // the router entry point must always be provided by the user
18
+ router: '#tanstack-start-router-entry',
19
+ } as const
@@ -1,117 +1,136 @@
1
- import { createEvent, getHeader, sendWebResponse } from 'h3'
2
1
  import { isRunnableDevEnvironment } from 'vite'
3
- import { VITE_ENVIRONMENT_NAMES } from '../constants'
2
+ import { VIRTUAL_MODULES } from '@tanstack/start-server-core'
3
+ import { NodeRequest, sendNodeResponse } from 'srvx/node'
4
+ import { ENTRY_POINTS, VITE_ENVIRONMENT_NAMES } from '../constants'
5
+ import { resolveViteId } from '../utils'
4
6
  import { extractHtmlScripts } from './extract-html-scripts'
5
- import type { Connect, DevEnvironment, Plugin } from 'vite'
7
+ import type { Connect, DevEnvironment, PluginOption } from 'vite'
8
+ import type { TanStackStartOutputConfig } from '../schema'
6
9
 
7
- /* eslint-disable no-var */
8
- declare global {
9
- var TSS_INJECTED_HEAD_SCRIPTS: string | undefined
10
- }
11
-
12
- export function devServerPlugin(): Plugin {
13
- // let config: UserConfig
10
+ export function devServerPlugin({
11
+ startConfig,
12
+ }: {
13
+ startConfig: TanStackStartOutputConfig
14
+ }): PluginOption {
14
15
  let isTest = false
15
16
 
16
- return {
17
- name: 'start-dev-ssr-plugin',
18
- config(userConfig, { mode }) {
19
- // config = userConfig
20
- isTest = isTest ? isTest : mode === 'test'
21
- // see https://vite.dev/config/shared-options.html#apptype
22
- // this will prevent vite from injecting middlewares that we don't want
23
- userConfig.appType = 'custom'
24
- },
25
- async configureServer(viteDevServer) {
26
- if (isTest) {
27
- return
28
- }
29
-
30
- // Extract the scripts that Vite plugins would inject into the initial HTML
31
- const templateHtml = `<html><head></head><body></body></html>`
32
- const transformedHtml = await viteDevServer.transformIndexHtml(
33
- '/',
34
- templateHtml,
35
- )
36
- const scripts = extractHtmlScripts(transformedHtml)
37
- globalThis.TSS_INJECTED_HEAD_SCRIPTS = scripts
38
- .map((script) => script.content ?? '')
39
- .join(';')
17
+ let injectedHeadScripts: string | undefined
40
18
 
41
- return () => {
42
- // do not install middleware in middlewareMode
43
- if (viteDevServer.config.server.middlewareMode) {
19
+ return [
20
+ {
21
+ name: 'tanstack-start-core:dev-server',
22
+ config(_userConfig, { mode }) {
23
+ isTest = isTest ? isTest : mode === 'test'
24
+ },
25
+ async configureServer(viteDevServer) {
26
+ if (isTest) {
44
27
  return
45
28
  }
46
- viteDevServer.middlewares.use(async (req, res, next) => {
47
- // Create an H3Event to have it passed into the server entry
48
- // i.e: event => defineEventHandler(event)
49
29
 
50
- // fix the request URL to match the original URL
51
- // otherwise, the request URL will '/index.html'
52
- if (req.originalUrl) {
53
- req.url = req.originalUrl
54
- }
55
- const event = createEvent(req, res)
30
+ // Extract the scripts that Vite plugins would inject into the initial HTML
31
+ const templateHtml = `<html><head></head><body></body></html>`
32
+ const transformedHtml = await viteDevServer.transformIndexHtml(
33
+ '/',
34
+ templateHtml,
35
+ )
36
+ const scripts = extractHtmlScripts(transformedHtml)
37
+ injectedHeadScripts = scripts
38
+ .flatMap((script) => script.content ?? [])
39
+ .join(';')
56
40
 
41
+ return () => {
57
42
  const serverEnv = viteDevServer.environments[
58
43
  VITE_ENVIRONMENT_NAMES.server
59
44
  ] as DevEnvironment | undefined
60
45
 
61
- try {
62
- if (!serverEnv) {
63
- throw new Error(
64
- `Server environment ${VITE_ENVIRONMENT_NAMES.server} not found`,
65
- )
46
+ if (!serverEnv) {
47
+ throw new Error(
48
+ `Server environment ${VITE_ENVIRONMENT_NAMES.server} not found`,
49
+ )
50
+ }
51
+ const installMiddleware = startConfig.vite?.installDevServerMiddleware
52
+ if (installMiddleware === false) {
53
+ return
54
+ }
55
+ if (installMiddleware == undefined) {
56
+ // do not install middleware in middlewareMode by default
57
+ if (viteDevServer.config.server.middlewareMode) {
58
+ return
66
59
  }
67
60
 
68
- if (!isRunnableDevEnvironment(serverEnv)) {
69
- return next()
61
+ // do not install middleware if SSR env in case another plugin already did
62
+ if (
63
+ !isRunnableDevEnvironment(serverEnv) ||
64
+ // do not check via `isFetchableDevEnvironment` since nitro does implement the `FetchableDevEnvironment` interface but not via inheritance (which this helper checks)
65
+ 'dispatchFetch' in serverEnv
66
+ ) {
67
+ return
70
68
  }
69
+ }
71
70
 
72
- // Import and resolve the request by running the server entry point
73
- // i.e export default defineEventHandler((event) => { ... })
74
- const serverEntry = await serverEnv.runner.import(
75
- '/~start/server-entry',
71
+ if (!isRunnableDevEnvironment(serverEnv)) {
72
+ throw new Error(
73
+ 'cannot install vite dev server middleware for TanStack Start since the SSR environment is not a RunnableDevEnvironment',
76
74
  )
77
- const response = await serverEntry['default'](event)
75
+ }
78
76
 
79
- return sendWebResponse(event, response)
80
- } catch (e) {
81
- console.error(e)
82
- viteDevServer.ssrFixStacktrace(e as Error)
77
+ viteDevServer.middlewares.use(async (req, res) => {
78
+ // fix the request URL to match the original URL
79
+ // otherwise, the request URL will '/index.html'
80
+ if (req.originalUrl) {
81
+ req.url = req.originalUrl
82
+ }
83
+ const webReq = new NodeRequest({ req, res })
83
84
 
84
- if (
85
- getHeader(event, 'content-type')?.includes('application/json')
86
- ) {
87
- return sendWebResponse(
88
- event,
89
- new Response(
90
- JSON.stringify(
85
+ try {
86
+ // Import and resolve the request by running the server request entry point
87
+ // this request entry point must implement the `fetch` API as follows:
88
+ /**
89
+ * export default {
90
+ * fetch(req: Request): Promise<Response>
91
+ * }
92
+ */
93
+ const serverEntry = await serverEnv.runner.import(
94
+ ENTRY_POINTS.server,
95
+ )
96
+ const webRes = await serverEntry['default'].fetch(webReq)
97
+
98
+ return sendNodeResponse(res, webRes)
99
+ } catch (e) {
100
+ console.error(e)
101
+ viteDevServer.ssrFixStacktrace(e as Error)
102
+
103
+ if (
104
+ webReq.headers.get('content-type')?.includes('application/json')
105
+ ) {
106
+ return sendNodeResponse(
107
+ res,
108
+ new Response(
109
+ JSON.stringify(
110
+ {
111
+ status: 500,
112
+ error: 'Internal Server Error',
113
+ message:
114
+ 'An unexpected error occurred. Please try again later.',
115
+ timestamp: new Date().toISOString(),
116
+ },
117
+ null,
118
+ 2,
119
+ ),
91
120
  {
92
121
  status: 500,
93
- error: 'Internal Server Error',
94
- message:
95
- 'An unexpected error occurred. Please try again later.',
96
- timestamp: new Date().toISOString(),
122
+ headers: {
123
+ 'Content-Type': 'application/json',
124
+ },
97
125
  },
98
- null,
99
- 2,
100
126
  ),
101
- {
102
- status: 500,
103
- headers: {
104
- 'Content-Type': 'application/json',
105
- },
106
- },
107
- ),
108
- )
109
- }
127
+ )
128
+ }
110
129
 
111
- return sendWebResponse(
112
- event,
113
- new Response(
114
- `
130
+ return sendNodeResponse(
131
+ res,
132
+ new Response(
133
+ `
115
134
  <!DOCTYPE html>
116
135
  <html lang="en">
117
136
  <head>
@@ -128,19 +147,41 @@ export function devServerPlugin(): Plugin {
128
147
  </body>
129
148
  </html>
130
149
  `,
131
- {
132
- status: 500,
133
- headers: {
134
- 'Content-Type': 'text/html',
150
+ {
151
+ status: 500,
152
+ headers: {
153
+ 'Content-Type': 'text/html',
154
+ },
135
155
  },
136
- },
137
- ),
138
- )
139
- }
140
- })
141
- }
156
+ ),
157
+ )
158
+ }
159
+ })
160
+ }
161
+ },
142
162
  },
143
- }
163
+ {
164
+ name: 'tanstack-start-core:dev-server:injected-head-scripts',
165
+ sharedDuringBuild: true,
166
+ applyToEnvironment: (env) => env.config.consumer === 'server',
167
+ resolveId: {
168
+ filter: { id: new RegExp(VIRTUAL_MODULES.injectedHeadScripts) },
169
+ handler(_id) {
170
+ return resolveViteId(VIRTUAL_MODULES.injectedHeadScripts)
171
+ },
172
+ },
173
+ load: {
174
+ filter: {
175
+ id: new RegExp(resolveViteId(VIRTUAL_MODULES.injectedHeadScripts)),
176
+ },
177
+ handler() {
178
+ const mod = `
179
+ export const injectedHeadScripts = ${JSON.stringify(injectedHeadScripts) || 'undefined'}`
180
+ return mod
181
+ },
182
+ },
183
+ },
184
+ ]
144
185
  }
145
186
 
146
187
  /**
package/src/global.d.ts CHANGED
@@ -1,10 +1,8 @@
1
1
  import type { Manifest } from '@tanstack/router-core'
2
- import type { Rollup } from 'vite'
3
2
 
4
3
  /* eslint-disable no-var */
5
4
  declare global {
6
5
  var TSS_APP_BASE: string
7
6
  var TSS_ROUTES_MANIFEST: Manifest
8
- var TSS_CLIENT_BUNDLE: Rollup.OutputBundle
9
7
  }
10
8
  export {}
package/src/index.ts CHANGED
@@ -1,8 +1,4 @@
1
- export {
2
- createTanStackConfig,
3
- createTanStackStartOptionsSchema,
4
- pageSchema,
5
- } from './schema'
1
+ export type { TanStackStartInputConfig } from './schema'
6
2
 
7
3
  export { TanStackStartVitePluginCore } from './plugin'
8
4
  export { resolveViteId } from './utils'
@@ -1,17 +1,12 @@
1
- import * as vite from 'vite'
2
- import type { TanStackStartOutputConfig } from '../plugin'
1
+ import { loadEnv } from 'vite'
2
+ import type { Plugin } from 'vite'
3
3
 
4
- export function loadEnvPlugin(
5
- startOpts: TanStackStartOutputConfig,
6
- ): vite.Plugin {
4
+ export function loadEnvPlugin(): Plugin {
7
5
  return {
8
- name: 'tanstack-vite-plugin-nitro-load-env',
6
+ name: 'tanstack-start-core:load-env',
9
7
  enforce: 'pre',
10
- config(userConfig, envConfig) {
11
- Object.assign(
12
- process.env,
13
- vite.loadEnv(envConfig.mode, userConfig.root ?? startOpts.root, ''),
14
- )
8
+ configResolved(config) {
9
+ Object.assign(process.env, loadEnv(config.mode, config.root))
15
10
  },
16
11
  }
17
12
  }
@@ -0,0 +1,18 @@
1
+ import { join } from 'pathe'
2
+ import { VITE_ENVIRONMENT_NAMES } from './constants'
3
+ import type * as vite from 'vite'
4
+
5
+ export function getClientOutputDirectory(userConfig: vite.UserConfig) {
6
+ return (
7
+ userConfig.environments?.[VITE_ENVIRONMENT_NAMES.client]?.build?.outDir ??
8
+ join(getServerOutputDirectory(userConfig), 'public')
9
+ )
10
+ }
11
+
12
+ export function getServerOutputDirectory(userConfig: vite.UserConfig) {
13
+ const rootOutputDirectory = userConfig.build?.outDir ?? 'dist'
14
+ return (
15
+ userConfig.environments?.[VITE_ENVIRONMENT_NAMES.server]?.build?.outDir ??
16
+ rootOutputDirectory
17
+ )
18
+ }