mirror of
https://github.com/nuxt/nuxt.git
synced 2024-11-11 08:33:53 +00:00
fix(vite): sanitize client asset chunk names (#7067)
This commit is contained in:
parent
afc9d9bfc8
commit
fd6d1d4fbe
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user