Skip to content

Commit 8175a4a

Browse files
fix(server): use path.posix.join to generate public path
fix #8167
1 parent 5e3823a commit 8175a4a

File tree

2 files changed

+10
-5
lines changed

2 files changed

+10
-5
lines changed

src/server/template-renderer/index.js

+9-5
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ export default class TemplateRenderer {
6060
// extra functionality with client manifest
6161
if (options.clientManifest) {
6262
const clientManifest = this.clientManifest = options.clientManifest
63-
this.publicPath = clientManifest.publicPath.replace(/\/$/, '')
63+
this.publicPath = clientManifest.publicPath
6464
// preload/prefetch directives
6565
this.preloadFiles = (clientManifest.initial || []).map(normalizeFile)
6666
this.prefetchFiles = (clientManifest.async || []).map(normalizeFile)
@@ -114,7 +114,7 @@ export default class TemplateRenderer {
114114
return (
115115
// render links for css files
116116
(cssFiles.length
117-
? cssFiles.map(({ file }) => `<link rel="stylesheet" href="${this.publicPath}/${file}">`).join('')
117+
? cssFiles.map(({ file }) => `<link rel="stylesheet" href="${this.getPublicPath(file)}">`).join('')
118118
: '') +
119119
// context.styles is a getter exposed by vue-style-loader which contains
120120
// the inline component styles collected during SSR
@@ -153,7 +153,7 @@ export default class TemplateRenderer {
153153
extra = ` type="font/${extension}" crossorigin`
154154
}
155155
return `<link rel="preload" href="${
156-
this.publicPath}/${file
156+
this.getPublicPath(file)
157157
}"${
158158
asType !== '' ? ` as="${asType}"` : ''
159159
}${
@@ -179,7 +179,7 @@ export default class TemplateRenderer {
179179
if (alreadyRendered(file)) {
180180
return ''
181181
}
182-
return `<link rel="prefetch" href="${this.publicPath}/${file}">`
182+
return `<link rel="prefetch" href="${this.getPublicPath(file)}">`
183183
}).join('')
184184
} else {
185185
return ''
@@ -206,7 +206,7 @@ export default class TemplateRenderer {
206206
const async = (this.getUsedAsyncFiles(context) || []).filter(({ file }) => isJS(file))
207207
const needed = [initial[0]].concat(async || [], initial.slice(1))
208208
return needed.map(({ file }) => {
209-
return `<script src="${this.publicPath}/${file}" defer></script>`
209+
return `<script src="${this.getPublicPath(file)}" defer></script>`
210210
}).join('')
211211
} else {
212212
return ''
@@ -228,6 +228,10 @@ export default class TemplateRenderer {
228228
}
229229
return new TemplateStream(this, this.parsedTemplate, context || {})
230230
}
231+
232+
getPublicPath (file: string) {
233+
return path.posix.join(this.publicPath, file)
234+
}
231235
}
232236

233237
function normalizeFile (file: string): Resource {

test/ssr/ssr-template.spec.js

+1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ function generateClientManifest (file, cb) {
1212
compileWithWebpack(file, {
1313
output: {
1414
path: '/',
15+
publicPath: '/',
1516
filename: '[name].js'
1617
},
1718
plugins: [

0 commit comments

Comments
 (0)