feat(webpack, vite): default to .js extension for client (#6505)

This commit is contained in:
Daniel Roe 2022-08-12 15:16:08 +01:00 committed by GitHub
parent 3960f513c3
commit 0a513a56b1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 12 additions and 10 deletions

View File

@ -122,8 +122,8 @@ export default {
* ``` * ```
*/ */
filenames: { filenames: {
app: ({ isDev }) => isDev ? `[name].mjs` : `[contenthash:7].mjs`, app: ({ isDev }) => isDev ? `[name].js` : `[contenthash:7].js`,
chunk: ({ isDev }) => isDev ? `[name].mjs` : `[contenthash:7].mjs`, chunk: ({ isDev }) => isDev ? `[name].js` : `[contenthash:7].js`,
css: ({ isDev }) => isDev ? '[name].css' : 'css/[contenthash:7].css', css: ({ isDev }) => isDev ? '[name].css' : 'css/[contenthash:7].css',
img: ({ isDev }) => isDev ? '[path][name].[ext]' : 'img/[name].[contenthash:7].[ext]', img: ({ isDev }) => isDev ? '[path][name].[ext]' : 'img/[name].[contenthash:7].[ext]',
font: ({ isDev }) => isDev ? '[path][name].[ext]' : 'fonts/[name].[contenthash:7].[ext]', font: ({ isDev }) => isDev ? '[path][name].[ext]' : 'fonts/[name].[contenthash:7].[ext]',

View File

@ -37,14 +37,6 @@ export async function buildClient (ctx: ViteBuildContext) {
} }
}, },
build: { 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]')),
chunkFileNames: ctx.nuxt.options.dev ? undefined : withoutLeadingSlash(join(ctx.nuxt.options.app.buildAssetsDir, '[name].[hash].mjs')),
entryFileNames: ctx.nuxt.options.dev ? 'entry.mjs' : withoutLeadingSlash(join(ctx.nuxt.options.app.buildAssetsDir, '[name].[hash].mjs'))
}
},
manifest: true, manifest: true,
outDir: resolve(ctx.nuxt.options.buildDir, 'dist/client') outDir: resolve(ctx.nuxt.options.buildDir, 'dist/client')
}, },
@ -72,6 +64,16 @@ export async function buildClient (ctx: ViteBuildContext) {
clientConfig.server.hmr = false clientConfig.server.hmr = false
} }
// We want to respect users' own rollup output options
ctx.config.build.rollupOptions = defu(ctx.config.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]')),
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'))
}
})
if (clientConfig.server.hmr !== false) { if (clientConfig.server.hmr !== false) {
const hmrPortDefault = 24678 // Vite's default HMR port const hmrPortDefault = 24678 // Vite's default HMR port
const hmrPort = await getPort({ const hmrPort = await getPort({