From 46b8d2c59dc259995a71662229ed52b8b8beeb38 Mon Sep 17 00:00:00 2001 From: Herrington Darkholme <2883231+HerringtonDarkholme@users.noreply.github.com> Date: Thu, 25 Oct 2018 01:02:11 +0800 Subject: [PATCH] fix(server): use path.posix.join to generate public path (#8177) 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 a6a1570c..2c95e31f 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 63b94e11..2491b591 100644 --- a/test/ssr/ssr-template.spec.js +++ b/test/ssr/ssr-template.spec.js @@ -11,6 +11,7 @@ function generateClientManifest (file, cb) { compileWithWebpack(file, { output: { path: '/', + publicPath: '/', filename: '[name].js' }, optimization: {