Skip to content
This repository has been archived by the owner on Apr 6, 2023. It is now read-only.

Commit

Permalink
feat(webpack, vite): default to .js extension for client (#6505)
Browse files Browse the repository at this point in the history
  • Loading branch information
danielroe committed Aug 12, 2022
1 parent 3960f51 commit 0a513a5
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
4 changes: 2 additions & 2 deletions packages/schema/src/config/webpack.ts
Original file line number Diff line number Diff line change
Expand Up @@ -122,8 +122,8 @@ export default {
* ```
*/
filenames: {
app: ({ isDev }) => isDev ? `[name].mjs` : `[contenthash:7].mjs`,
chunk: ({ isDev }) => isDev ? `[name].mjs` : `[contenthash:7].mjs`,
app: ({ isDev }) => isDev ? `[name].js` : `[contenthash:7].js`,
chunk: ({ isDev }) => isDev ? `[name].js` : `[contenthash:7].js`,
css: ({ isDev }) => isDev ? '[name].css' : 'css/[contenthash:7].css',
img: ({ isDev }) => isDev ? '[path][name].[ext]' : 'img/[name].[contenthash:7].[ext]',
font: ({ isDev }) => isDev ? '[path][name].[ext]' : 'fonts/[name].[contenthash:7].[ext]',
Expand Down
18 changes: 10 additions & 8 deletions packages/vite/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,14 +37,6 @@ export async function buildClient (ctx: ViteBuildContext) {
}
},
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,
outDir: resolve(ctx.nuxt.options.buildDir, 'dist/client')
},
Expand Down Expand Up @@ -72,6 +64,16 @@ export async function buildClient (ctx: ViteBuildContext) {
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) {
const hmrPortDefault = 24678 // Vite's default HMR port
const hmrPort = await getPort({
Expand Down

0 comments on commit 0a513a5

Please sign in to comment.