@tanstack/start-plugin-core 1.131.10 → 1.132.0-alpha.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/esm/{nitro-plugin/build-sitemap.d.ts → build-sitemap.d.ts} +3 -3
- package/dist/esm/{nitro-plugin/build-sitemap.js → build-sitemap.js} +19 -24
- package/dist/esm/build-sitemap.js.map +1 -0
- package/dist/esm/compilers.js +7 -10
- package/dist/esm/compilers.js.map +1 -1
- package/dist/esm/constants.d.ts +6 -2
- package/dist/esm/constants.js +7 -10
- package/dist/esm/constants.js.map +1 -1
- package/dist/esm/debug.js.map +1 -1
- package/dist/esm/dev-server-plugin/extract-html-scripts.js.map +1 -1
- package/dist/esm/dev-server-plugin/plugin.d.ts +5 -5
- package/dist/esm/dev-server-plugin/plugin.js +117 -79
- package/dist/esm/dev-server-plugin/plugin.js.map +1 -1
- package/dist/esm/index.d.ts +2 -1
- package/dist/esm/index.js +2 -4
- package/dist/esm/load-env-plugin/plugin.d.ts +2 -3
- package/dist/esm/load-env-plugin/plugin.js +5 -8
- package/dist/esm/load-env-plugin/plugin.js.map +1 -1
- package/dist/esm/output-directory.d.ts +3 -0
- package/dist/esm/output-directory.js +14 -0
- package/dist/esm/output-directory.js.map +1 -0
- package/dist/esm/plugin.d.ts +6 -290
- package/dist/esm/plugin.js +135 -76
- package/dist/esm/plugin.js.map +1 -1
- package/dist/esm/post-server-build.d.ts +7 -0
- package/dist/esm/post-server-build.js +55 -0
- package/dist/esm/post-server-build.js.map +1 -0
- package/dist/esm/prerender.d.ts +11 -0
- package/dist/esm/{nitro-plugin/prerender.js → prerender.js} +85 -73
- package/dist/esm/prerender.js.map +1 -0
- package/dist/esm/{nitro-plugin/queue.js → queue.js} +7 -10
- package/dist/esm/queue.js.map +1 -0
- package/dist/esm/resolve-entries.d.ts +8 -0
- package/dist/esm/resolve-entries.js +37 -0
- package/dist/esm/resolve-entries.js.map +1 -0
- package/dist/esm/schema.d.ts +1369 -6719
- package/dist/esm/schema.js +52 -85
- package/dist/esm/schema.js.map +1 -1
- package/dist/esm/start-compiler-plugin.js +2 -2
- package/dist/esm/start-compiler-plugin.js.map +1 -1
- package/dist/esm/start-manifest-plugin/plugin.d.ts +1 -1
- package/dist/esm/start-manifest-plugin/plugin.js +8 -13
- package/dist/esm/start-manifest-plugin/plugin.js.map +1 -1
- package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js +2 -3
- package/dist/esm/start-router-plugin/generator-plugins/routes-manifest-plugin.js.map +1 -1
- package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.js +2 -4
- package/dist/esm/start-router-plugin/generator-plugins/server-routes-plugin.js.map +1 -1
- package/dist/esm/start-router-plugin/plugin.js.map +1 -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.js.map +1 -1
- package/dist/esm/utils.js.map +1 -1
- package/package.json +13 -18
- package/src/{nitro-plugin/build-sitemap.ts → build-sitemap.ts} +8 -8
- package/src/constants.ts +12 -9
- package/src/dev-server-plugin/plugin.ts +140 -99
- package/src/global.d.ts +0 -2
- package/src/index.ts +3 -5
- package/src/load-env-plugin/plugin.ts +6 -11
- package/src/output-directory.ts +18 -0
- package/src/plugin.ts +172 -98
- package/src/post-server-build.ts +73 -0
- package/src/{nitro-plugin/prerender.ts → prerender.ts} +93 -86
- package/src/resolve-entries.ts +52 -0
- package/src/schema.ts +88 -121
- package/src/start-manifest-plugin/plugin.ts +8 -14
- package/dist/cjs/compilers.cjs +0 -416
- package/dist/cjs/compilers.cjs.map +0 -1
- package/dist/cjs/compilers.d.cts +0 -21
- package/dist/cjs/constants.cjs +0 -20
- package/dist/cjs/constants.cjs.map +0 -1
- package/dist/cjs/constants.d.cts +0 -6
- package/dist/cjs/debug.cjs +0 -5
- package/dist/cjs/debug.cjs.map +0 -1
- package/dist/cjs/debug.d.cts +0 -1
- package/dist/cjs/dev-server-plugin/extract-html-scripts.cjs +0 -35
- package/dist/cjs/dev-server-plugin/extract-html-scripts.cjs.map +0 -1
- package/dist/cjs/dev-server-plugin/extract-html-scripts.d.cts +0 -4
- package/dist/cjs/dev-server-plugin/plugin.cjs +0 -121
- package/dist/cjs/dev-server-plugin/plugin.cjs.map +0 -1
- package/dist/cjs/dev-server-plugin/plugin.d.cts +0 -5
- package/dist/cjs/index.cjs +0 -11
- package/dist/cjs/index.cjs.map +0 -1
- package/dist/cjs/index.d.cts +0 -3
- package/dist/cjs/load-env-plugin/plugin.cjs +0 -34
- package/dist/cjs/load-env-plugin/plugin.cjs.map +0 -1
- package/dist/cjs/load-env-plugin/plugin.d.cts +0 -3
- package/dist/cjs/nitro-plugin/build-sitemap.cjs +0 -138
- package/dist/cjs/nitro-plugin/build-sitemap.cjs.map +0 -1
- package/dist/cjs/nitro-plugin/build-sitemap.d.cts +0 -31
- package/dist/cjs/nitro-plugin/plugin.cjs +0 -187
- package/dist/cjs/nitro-plugin/plugin.cjs.map +0 -1
- package/dist/cjs/nitro-plugin/plugin.d.cts +0 -3
- package/dist/cjs/nitro-plugin/prerender.cjs +0 -178
- package/dist/cjs/nitro-plugin/prerender.cjs.map +0 -1
- package/dist/cjs/nitro-plugin/prerender.d.cts +0 -8
- package/dist/cjs/nitro-plugin/queue.cjs +0 -131
- package/dist/cjs/nitro-plugin/queue.cjs.map +0 -1
- package/dist/cjs/nitro-plugin/queue.d.cts +0 -32
- package/dist/cjs/plugin.cjs +0 -227
- package/dist/cjs/plugin.cjs.map +0 -1
- package/dist/cjs/plugin.d.cts +0 -300
- package/dist/cjs/resolve-virtual-entries-plugin/plugin.cjs +0 -80
- package/dist/cjs/resolve-virtual-entries-plugin/plugin.cjs.map +0 -1
- package/dist/cjs/resolve-virtual-entries-plugin/plugin.d.cts +0 -3
- package/dist/cjs/schema.cjs +0 -158
- package/dist/cjs/schema.cjs.map +0 -1
- package/dist/cjs/schema.d.cts +0 -8878
- package/dist/cjs/start-compiler-plugin.cjs +0 -78
- package/dist/cjs/start-compiler-plugin.cjs.map +0 -1
- package/dist/cjs/start-compiler-plugin.d.cts +0 -13
- package/dist/cjs/start-manifest-plugin/plugin.cjs +0 -182
- package/dist/cjs/start-manifest-plugin/plugin.cjs.map +0 -1
- package/dist/cjs/start-manifest-plugin/plugin.d.cts +0 -6
- package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.cjs +0 -39
- package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.cjs.map +0 -1
- package/dist/cjs/start-router-plugin/generator-plugins/routes-manifest-plugin.d.cts +0 -6
- package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.cjs +0 -121
- package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.cjs.map +0 -1
- package/dist/cjs/start-router-plugin/generator-plugins/server-routes-plugin.d.cts +0 -2
- package/dist/cjs/start-router-plugin/plugin.cjs +0 -45
- package/dist/cjs/start-router-plugin/plugin.cjs.map +0 -1
- package/dist/cjs/start-router-plugin/plugin.d.cts +0 -3
- package/dist/cjs/start-router-plugin/route-tree-client-plugin.cjs +0 -73
- package/dist/cjs/start-router-plugin/route-tree-client-plugin.cjs.map +0 -1
- package/dist/cjs/start-router-plugin/route-tree-client-plugin.d.cts +0 -6
- package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.cjs +0 -29
- package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.cjs.map +0 -1
- package/dist/cjs/start-router-plugin/virtual-route-tree-plugin.d.cts +0 -3
- package/dist/cjs/utils.cjs +0 -18
- package/dist/cjs/utils.cjs.map +0 -1
- package/dist/cjs/utils.d.cts +0 -8
- package/dist/esm/nitro-plugin/build-sitemap.js.map +0 -1
- package/dist/esm/nitro-plugin/plugin.d.ts +0 -3
- package/dist/esm/nitro-plugin/plugin.js +0 -187
- package/dist/esm/nitro-plugin/plugin.js.map +0 -1
- package/dist/esm/nitro-plugin/prerender.d.ts +0 -8
- package/dist/esm/nitro-plugin/prerender.js.map +0 -1
- package/dist/esm/nitro-plugin/queue.js.map +0 -1
- package/dist/esm/resolve-virtual-entries-plugin/plugin.d.ts +0 -3
- package/dist/esm/resolve-virtual-entries-plugin/plugin.js +0 -63
- package/dist/esm/resolve-virtual-entries-plugin/plugin.js.map +0 -1
- package/src/nitro-plugin/plugin.ts +0 -252
- package/src/resolve-virtual-entries-plugin/plugin.ts +0 -77
- /package/dist/esm/{nitro-plugin/queue.d.ts → queue.d.ts} +0 -0
- /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 '
|
|
5
|
-
import type { TanStackStartOutputConfig } from '
|
|
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
|
-
|
|
126
|
+
startConfig,
|
|
127
127
|
publicDir,
|
|
128
128
|
}: {
|
|
129
|
-
|
|
129
|
+
startConfig: TanStackStartOutputConfig
|
|
130
130
|
publicDir: string
|
|
131
131
|
}) {
|
|
132
132
|
const logger = createLogger('sitemap')
|
|
133
133
|
|
|
134
|
-
let sitemapOptions =
|
|
134
|
+
let sitemapOptions = startConfig.sitemap
|
|
135
135
|
|
|
136
|
-
if (!sitemapOptions &&
|
|
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 (!
|
|
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 } =
|
|
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
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
export const
|
|
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 {
|
|
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,
|
|
7
|
+
import type { Connect, DevEnvironment, PluginOption } from 'vite'
|
|
8
|
+
import type { TanStackStartOutputConfig } from '../schema'
|
|
6
9
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
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
|
-
|
|
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
|
-
|
|
42
|
-
|
|
43
|
-
|
|
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
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
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
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
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
|
|
69
|
-
|
|
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
|
-
|
|
73
|
-
|
|
74
|
-
|
|
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
|
-
|
|
75
|
+
}
|
|
78
76
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
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
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
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
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
timestamp: new Date().toISOString(),
|
|
122
|
+
headers: {
|
|
123
|
+
'Content-Type': 'application/json',
|
|
124
|
+
},
|
|
97
125
|
},
|
|
98
|
-
null,
|
|
99
|
-
2,
|
|
100
126
|
),
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
headers: {
|
|
104
|
-
'Content-Type': 'application/json',
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
),
|
|
108
|
-
)
|
|
109
|
-
}
|
|
127
|
+
)
|
|
128
|
+
}
|
|
110
129
|
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
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
|
-
|
|
133
|
-
|
|
134
|
-
|
|
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,6 @@
|
|
|
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'
|
|
5
|
+
|
|
6
|
+
export { VITE_ENVIRONMENT_NAMES } from './constants'
|
|
@@ -1,17 +1,12 @@
|
|
|
1
|
-
import
|
|
2
|
-
import type {
|
|
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-
|
|
6
|
+
name: 'tanstack-start-core:load-env',
|
|
9
7
|
enforce: 'pre',
|
|
10
|
-
config
|
|
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
|
+
}
|