@@ -13,16 +13,20 @@ const TARGET = '../devtools-assets/dist'
1313// relative base directly). Rewrite each HTML shell so it works at any mount
1414// point:
1515//
16- // 1. The inline runtime config's `baseURL` becomes a `location`-derived
17- // expression. The client uses hash routing in production, so
18- // `location.pathname` is always the mount path (possibly ending in
19- // `index.html`, hence stripping the trailing filename).
16+ // 1. The inline runtime config's `app` object gets a `baseURL` set to a
17+ // `location`-derived expression (Nuxt no longer serializes `baseURL` into
18+ // the prerendered shell's `window.__NUXT__.config.app` at all — it's read
19+ // at runtime, just never populated for a static `ssr:false` generate — so
20+ // this injects it rather than rewriting an existing value). The client
21+ // uses hash routing in production, so `location.pathname` is always the
22+ // mount path (possibly ending in `index.html`, hence stripping the
23+ // trailing filename).
2024// 2. Every other placeholder occurrence (asset `href`/`src`, importmap)
2125// becomes `./`, relative to the document — which, per 1., is always the
2226// mount root.
2327const PLACEHOLDER = '/__NUXT_DEVTOOLS_BASE__/'
24- const RUNTIME_CONFIG_BASE_RE = / b a s e U R L : " \/ _ _ N U X T _ D E V T O O L S _ B A S E _ _ \/ " /
25- const RUNTIME_CONFIG_BASE_REPLACEMENT = 'baseURL: location.pathname.replace(/[^/]*$/,"")'
28+ const RUNTIME_CONFIG_APP_RE = / ( w i n d o w \. _ _ N U X T _ _ \. c o n f i g \s * = \s * \{ [ \s \S ] * ? \b a p p : \{ ) ( [ ^ } ] * ) ( \} ) /
29+ const RUNTIME_CONFIG_BASE_URL = 'location.pathname.replace(/[^/]*$/,"")'
2630
2731rmSync ( TARGET , { recursive : true , force : true } )
2832cpSync ( SOURCE , TARGET , { recursive : true } )
@@ -34,11 +38,14 @@ if (htmlFiles.length === 0)
3438for ( const file of htmlFiles ) {
3539 const path = join ( TARGET , file )
3640 let html = readFileSync ( path , 'utf-8' )
37- if ( ! RUNTIME_CONFIG_BASE_RE . test ( html ) )
38- throw new Error ( `Expected the inline runtime-config \`baseURL:"${ PLACEHOLDER } "\` in ${ file } — Nuxt's serialization may have changed; update copy-client.mjs.` )
39- // Order matters: rewrite the runtime-config occurrence first, then the
40- // remaining (asset URL) occurrences.
41- html = html . replace ( RUNTIME_CONFIG_BASE_RE , RUNTIME_CONFIG_BASE_REPLACEMENT )
41+ if ( ! RUNTIME_CONFIG_APP_RE . test ( html ) )
42+ throw new Error ( `Expected to find \`window.__NUXT__.config\`'s \`app: {...}\` object in ${ file } — Nuxt's serialization may have changed; update copy-client.mjs.` )
43+ // Order matters: inject the runtime-config baseURL first, then rewrite the
44+ // remaining (asset URL) placeholder occurrences.
45+ html = html . replace ( RUNTIME_CONFIG_APP_RE , ( _ , prefix , existingProps , suffix ) => {
46+ const baseUrlProp = `baseURL:${ RUNTIME_CONFIG_BASE_URL } `
47+ return `${ prefix } ${ existingProps ? `${ baseUrlProp } ,${ existingProps } ` : baseUrlProp } ${ suffix } `
48+ } )
4249 html = html . replaceAll ( PLACEHOLDER , './' )
4350 writeFileSync ( path , html )
4451}
0 commit comments