From 8175a4a1f849e533ce87e3f2075ba7acb5fc589c Mon Sep 17 00:00:00 2001 From: Herrington Darkholme Date: Mon, 14 May 2018 17:58:08 +0800 Subject: [PATCH] fix(server): use path.posix.join to generate public path fix #8167 --- src/server/template-renderer/index.js | 14 +++++++++----- test/ssr/ssr-template.spec.js | 1 + 2 files changed, 10 insertions(+), 5 deletions(-) diff --git a/src/server/template-renderer/index.js b/src/server/template-renderer/index.js index a6a1570c6b7..2c95e31fd5a 100644 --- a/src/server/template-renderer/index.js +++ b/src/server/template-renderer/index.js @@ -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) @@ -114,7 +114,7 @@ export default class TemplateRenderer { return ( // render links for css files (cssFiles.length - ? cssFiles.map(({ file }) => ``).join('') + ? cssFiles.map(({ file }) => ``).join('') : '') + // context.styles is a getter exposed by vue-style-loader which contains // the inline component styles collected during SSR @@ -153,7 +153,7 @@ export default class TemplateRenderer { extra = ` type="font/${extension}" crossorigin` } return `` + return `` }).join('') } else { return '' @@ -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 `` + return `` }).join('') } else { return '' @@ -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 { diff --git a/test/ssr/ssr-template.spec.js b/test/ssr/ssr-template.spec.js index d93528466bb..fe4d5a9bb86 100644 --- a/test/ssr/ssr-template.spec.js +++ b/test/ssr/ssr-template.spec.js @@ -12,6 +12,7 @@ function generateClientManifest (file, cb) { compileWithWebpack(file, { output: { path: '/', + publicPath: '/', filename: '[name].js' }, plugins: [