@@ -5,7 +5,7 @@ import consola from 'consola'
5
5
import devalue from '@nuxt/devalue'
6
6
import invert from 'lodash/invert'
7
7
import template from 'lodash/template'
8
- import { waitFor } from '@nuxt/utils'
8
+ import { waitFor , isUrl , urlJoin } from '@nuxt/utils'
9
9
import { createBundleRenderer } from 'vue-server-renderer'
10
10
11
11
import SPAMetaRenderer from './spa-meta'
@@ -14,6 +14,9 @@ export default class VueRenderer {
14
14
constructor ( context ) {
15
15
this . context = context
16
16
17
+ const { build : { publicPath } , router : { base } } = this . context . options
18
+ this . publicPath = isUrl ( publicPath ) ? publicPath : urlJoin ( base , publicPath )
19
+
17
20
// Will be set by createRenderer
18
21
this . renderer = {
19
22
ssr : undefined ,
@@ -55,11 +58,11 @@ export default class VueRenderer {
55
58
56
59
renderScripts ( context ) {
57
60
if ( this . context . options . modern === 'client' ) {
58
- const { publicPath, crossorigin } = this . context . options . build
59
61
const scriptPattern = / < s c r i p t [ ^ > ] * ?s r c = " ( [ ^ " ] * ?) " [ ^ > ] * ?> [ ^ < ] * ?< \/ s c r i p t > / g
60
62
return context . renderScripts ( ) . replace ( scriptPattern , ( scriptTag , jsFile ) => {
61
- const legacyJsFile = jsFile . replace ( publicPath , '' )
63
+ const legacyJsFile = jsFile . replace ( this . publicPath , '' )
62
64
const modernJsFile = this . assetsMapping [ legacyJsFile ]
65
+ const { build : { crossorigin } } = this . context . options
63
66
const cors = `${ crossorigin ? ` crossorigin="${ crossorigin } "` : '' } `
64
67
const moduleTag = modernJsFile
65
68
? scriptTag
@@ -95,14 +98,14 @@ export default class VueRenderer {
95
98
96
99
renderSsrResourceHints ( context ) {
97
100
if ( this . context . options . modern === 'client' ) {
98
- const { publicPath, crossorigin } = this . context . options . build
99
101
const linkPattern = / < l i n k [ ^ > ] * ?h r e f = " ( [ ^ " ] * ?) " [ ^ > ] * ?a s = " s c r i p t " [ ^ > ] * ?> / g
100
102
return context . renderResourceHints ( ) . replace ( linkPattern , ( linkTag , jsFile ) => {
101
- const legacyJsFile = jsFile . replace ( publicPath , '' )
103
+ const legacyJsFile = jsFile . replace ( this . publicPath , '' )
102
104
const modernJsFile = this . assetsMapping [ legacyJsFile ]
103
105
if ( ! modernJsFile ) {
104
106
return ''
105
107
}
108
+ const { crossorigin } = this . context . options . build
106
109
const cors = `${ crossorigin ? ` crossorigin="${ crossorigin } "` : '' } `
107
110
return linkTag . replace ( 'rel="preload"' , `rel="modulepreload"${ cors } ` ) . replace ( legacyJsFile , modernJsFile )
108
111
} )
0 commit comments