@@ -23,15 +23,33 @@ import { createViteDevToolsUi } from './ui'
2323export interface BuildStaticOptions {
2424 context : ViteDevToolsNodeContext
2525 outDir : string
26+ /**
27+ * Absolute path the snapshot is deployed under (e.g. `/ci-build-123456/`).
28+ * Prefixes the root-relative URLs baked into the output — the root redirect
29+ * and the dock-renderer import specifiers — so the snapshot works when hosted
30+ * below the domain root. Defaults to `/`.
31+ */
32+ base ?: string
2633 /** Dock renderer modules copied into the static output, replacing built-ins by matching type. */
2734 renderers ?: readonly DockRendererRegistration [ ]
2835 withApp ?: boolean
2936 /** Reference-UI options forwarded to `createUi`. */
3037 ui ?: ViteDevToolsUiOptions
3138}
3239
40+ /**
41+ * Join the deploy `base` with the kit-pinned `/__devtools/` mount so absolute
42+ * URLs in the snapshot point at the right place when hosted below the domain
43+ * root. `/` (the default) collapses to the bare mount path.
44+ */
45+ function resolveMountPath ( base : string ) : string {
46+ const prefix = base . replace ( / \/ + $ / , '' )
47+ return prefix ? `${ prefix } ${ DEVTOOLS_MOUNT_PATH } ` : DEVTOOLS_MOUNT_PATH
48+ }
49+
3350export async function buildStaticDevTools ( options : BuildStaticOptions ) : Promise < void > {
3451 const { context, outDir, withApp } = options
52+ const mountPath = resolveMountPath ( options . base ?? '/' )
3553
3654 if ( ! withApp && existsSync ( outDir ) )
3755 await fs . rm ( outDir , { recursive : true } )
@@ -82,7 +100,7 @@ export async function buildStaticDevTools(options: BuildStaticOptions): Promise<
82100 for ( const registration of resolveDockRendererRegistrations ( options . renderers ) ) {
83101 await fs . cp ( registration . file , resolve ( renderersRoot , `${ registration . type } .mjs` ) )
84102 rendererManifest [ registration . type ] = {
85- importFrom : `${ DEVTOOLS_MOUNT_PATH } __renderers/${ registration . type } .mjs` ,
103+ importFrom : `${ mountPath } __renderers/${ registration . type } .mjs` ,
86104 }
87105 }
88106 ; ( await context . rpc . sharedState . get ( DOCK_RENDERERS_STATE_KEY , { initialValue : { } } ) ) . mutate ( ( ) => rendererManifest )
@@ -121,10 +139,10 @@ export async function buildStaticDevTools(options: BuildStaticOptions): Promise<
121139 ' <meta charset="UTF-8">' ,
122140 ' <meta name="viewport" content="width=device-width, initial-scale=1.0">' ,
123141 ' <title>Vite DevTools</title>' ,
124- ` <meta http-equiv="refresh" content="0; url=${ DEVTOOLS_MOUNT_PATH } ">` ,
142+ ` <meta http-equiv="refresh" content="0; url=${ mountPath } ">` ,
125143 '</head>' ,
126144 '<body>' ,
127- ` <script>location.replace(${ JSON . stringify ( DEVTOOLS_MOUNT_PATH ) } )</script>` ,
145+ ` <script>location.replace(${ JSON . stringify ( mountPath ) } )</script>` ,
128146 '</body>' ,
129147 '</html>' ,
130148 ] . join ( '\n' ) ,
0 commit comments