Open KStenK opened 2 years ago
I encountered the same problem, When I set the build.publicPath: https://static.domain.com
and using the default staticFilename
setting [publicPath]/image/[hash][ext]
or other setting starting with [publicPath]
, it will generated contain double slashes. like this https://static.domain.com//image/e94057.png
.
And then I checked code. Use the settings above, params.publicPath: '/'
, staticImages[url]
will startWith double slashes, so just delete [publicPath]
, set staticFilename
setting to /image/[name]-[hash][ext]
, It works fine. This doesn't match the example given in the documentation and I'm not sure if it's a bug or not.
nuxt.hook('vue-renderer:ssr:prepareContext', (renderContext: any) => {
renderContext.image = renderContext.image || {}
renderContext.image.mapToStatic = <MapToStatic> function ({ url, format }: ResolvedImage, input: string) {
if (!staticImages[url]) {
const { pathname } = parseURL(input)
const params: any = {
name: trimExt(basename(pathname)),
ext: (format && `.${format}`) || guessExt(input),
hash: hash(url),
// TODO: pass from runtimeConfig to mapStatic as param
publicPath: nuxt.options.app.cdnURL ? '/' : withoutTrailingSlash(nuxt.options.build.publicPath)
}
staticImages[url] = options.staticFilename.replace(/\[(\w+)]/g, (match, key) => params[key] || match)
}
return joinURL(nuxt.options.app.cdnURL || nuxt.options.app.basePath, staticImages[url])
}
})
Hello,
We are using the Images module to convert static images to Webp format. We want to serve static files from other domain, so as I understand that we need to change
build.publicPath
to serve all static files from other domain.Here are our settings:
Unfortunately, after the generate, I see a tag like this.
I'm pretty sure those double slashes (
_nuxt//image
) should not be there.Without a domain (
publicPath: '/some/random/path/'
), there are no double slashes added and everything is correct.