Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(server): use path.posix.join to generate public path, fix #8167 #8177

Merged
merged 1 commit into from
Oct 24, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 9 additions & 5 deletions src/server/template-renderer/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ export default class TemplateRenderer {
// extra functionality with client manifest
if (options.clientManifest) {
const clientManifest = this.clientManifest = options.clientManifest
this.publicPath = clientManifest.publicPath.replace(/\/$/, '')
this.publicPath = clientManifest.publicPath
// preload/prefetch directives
this.preloadFiles = (clientManifest.initial || []).map(normalizeFile)
this.prefetchFiles = (clientManifest.async || []).map(normalizeFile)
Expand Down Expand Up @@ -114,7 +114,7 @@ export default class TemplateRenderer {
return (
// render links for css files
(cssFiles.length
? cssFiles.map(({ file }) => `<link rel="stylesheet" href="${this.publicPath}/${file}">`).join('')
? cssFiles.map(({ file }) => `<link rel="stylesheet" href="${this.getPublicPath(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 +153,7 @@ export default class TemplateRenderer {
extra = ` type="font/${extension}" crossorigin`
}
return `<link rel="preload" href="${
this.publicPath}/${file
this.getPublicPath(file)
}"${
asType !== '' ? ` as="${asType}"` : ''
}${
Expand All @@ -179,7 +179,7 @@ export default class TemplateRenderer {
if (alreadyRendered(file)) {
return ''
}
return `<link rel="prefetch" href="${this.publicPath}/${file}">`
return `<link rel="prefetch" href="${this.getPublicPath(file)}">`
}).join('')
} else {
return ''
Expand All @@ -206,7 +206,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.publicPath}/${file}" defer></script>`
return `<script src="${this.getPublicPath(file)}" defer></script>`
}).join('')
} else {
return ''
Expand All @@ -228,6 +228,10 @@ 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
1 change: 1 addition & 0 deletions test/ssr/ssr-template.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ function generateClientManifest (file, cb) {
compileWithWebpack(file, {
output: {
path: '/',
publicPath: '/',
filename: '[name].js'
},
plugins: [
Expand Down