fix(vite): sanitize client asset chunk names (#7067)

This commit is contained in:
Daniel Roe 2022-08-30 14:13:23 +01:00 committed by GitHub
parent afc9d9bfc8
commit fd6d1d4fbe
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -8,6 +8,9 @@ import { getPort } from 'get-port-please'
import { joinURL, withLeadingSlash, withoutLeadingSlash, withTrailingSlash } from 'ufo'
import escapeRE from 'escape-string-regexp'
import defu from 'defu'
import { sanitizeFilePath } from 'mlly'
import { filename } from 'pathe/utils'
import type { OutputOptions } from 'rollup'
import { cacheDirPlugin } from './plugins/cache-dir'
import { wpfs } from './utils/wpfs'
import type { ViteBuildContext, ViteOptions } from './vite'
@ -76,14 +79,16 @@ export async function buildClient (ctx: ViteBuildContext) {
}
// We want to respect users' own rollup output options
ctx.config.build!.rollupOptions = defu(ctx.config.build!.rollupOptions!, {
clientConfig.build!.rollupOptions = defu(clientConfig.build!.rollupOptions!, {
output: {
// https://github.com/vitejs/vite/tree/main/packages/vite/src/node/build.ts#L464-L478
assetFileNames: ctx.nuxt.options.dev ? undefined : withoutLeadingSlash(join(ctx.nuxt.options.app.buildAssetsDir, '[name].[hash].[ext]')),
assetFileNames: ctx.nuxt.options.dev
? undefined
: chunk => withoutLeadingSlash(join(ctx.nuxt.options.app.buildAssetsDir, `${sanitizeFilePath(filename(chunk.name!))}.[hash].[ext]`)),
chunkFileNames: ctx.nuxt.options.dev ? undefined : withoutLeadingSlash(join(ctx.nuxt.options.app.buildAssetsDir, '[name].[hash].js')),
entryFileNames: ctx.nuxt.options.dev ? 'entry.js' : withoutLeadingSlash(join(ctx.nuxt.options.app.buildAssetsDir, '[name].[hash].js'))
}
})
} as OutputOptions
}) as any
if (clientConfig.server && clientConfig.server.hmr !== false) {
const hmrPortDefault = 24678 // Vite's default HMR port