Skip to content

Commit

Permalink
fix(ssr): fix ssr template publicPath generation
Browse files Browse the repository at this point in the history
fix #9145
  • Loading branch information
yyx990803 committed Dec 5, 2018
1 parent 93850f4 commit f077ed1
Showing 1 changed file with 8 additions and 9 deletions.
17 changes: 8 additions & 9 deletions src/server/template-renderer/index.js
Expand Up @@ -60,7 +60,10 @@ export default class TemplateRenderer {
// extra functionality with client manifest
if (options.clientManifest) {
const clientManifest = this.clientManifest = options.clientManifest
this.publicPath = clientManifest.publicPath
// ensure publicPath ends with /
this.publicPath = clientManifest.publicPath === ''
? ''
: clientManifest.publicPath.replace(/([^\/])$/, '$1/')
// preload/prefetch directives
this.preloadFiles = (clientManifest.initial || []).map(normalizeFile)
this.prefetchFiles = (clientManifest.async || []).map(normalizeFile)
Expand Down Expand Up @@ -114,7 +117,7 @@ export default class TemplateRenderer {
return (
// render links for css files
(cssFiles.length
? cssFiles.map(({ file }) => `<link rel="stylesheet" href="${this.getPublicPath(file)}">`).join('')
? cssFiles.map(({ file }) => `<link rel="stylesheet" href="${this.publicPath}${file}">`).join('')
: '') +
// context.styles is a getter exposed by vue-style-loader which contains
// the inline component styles collected during SSR
Expand Down Expand Up @@ -153,7 +156,7 @@ export default class TemplateRenderer {
extra = ` type="font/${extension}" crossorigin`
}
return `<link rel="preload" href="${
this.getPublicPath(file)
this.publicPath}${file
}"${
asType !== '' ? ` as="${asType}"` : ''
}${
Expand All @@ -179,7 +182,7 @@ export default class TemplateRenderer {
if (alreadyRendered(file)) {
return ''
}
return `<link rel="prefetch" href="${this.getPublicPath(file)}">`
return `<link rel="prefetch" href="${this.publicPath}${file}">`
}).join('')
} else {
return ''
Expand All @@ -206,7 +209,7 @@ export default class TemplateRenderer {
const async = (this.getUsedAsyncFiles(context) || []).filter(({ file }) => isJS(file))
const needed = [initial[0]].concat(async || [], initial.slice(1))
return needed.map(({ file }) => {
return `<script src="${this.getPublicPath(file)}" defer></script>`
return `<script src="${this.publicPath}${file}" defer></script>`
}).join('')
} else {
return ''
Expand All @@ -228,10 +231,6 @@ export default class TemplateRenderer {
}
return new TemplateStream(this, this.parsedTemplate, context || {})
}

getPublicPath (file: string) {
return path.posix.join(this.publicPath, file)
}
}

function normalizeFile (file: string): Resource {
Expand Down

0 comments on commit f077ed1

Please sign in to comment.