Skip to content

Commit

Permalink
Fix output: export with custom distDir (#62064)
Browse files Browse the repository at this point in the history
This ensures we don't normalize the `distDir` in the webpack config in
dev mode as it won't be moved to the right location like it is during
build.

Fixes: #61105

Closes NEXT-2495
  • Loading branch information
ijjk committed Mar 6, 2024
1 parent 960b738 commit b10a610
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 1 deletion.
2 changes: 1 addition & 1 deletion packages/next/src/build/webpack-config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -372,7 +372,7 @@ export default async function getBaseWebpackConfig(

const babelConfigFile = getBabelConfigFile(dir)

if (hasCustomExportOutput(config)) {
if (!dev && hasCustomExportOutput(config)) {
config.distDir = '.next'
}
const distDir = path.join(dir, config.distDir)
Expand Down
1 change: 1 addition & 0 deletions test/integration/app-dir-export/next.config.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
/** @type {import('next').NextConfig} */
const nextConfig = {
output: 'export',
// distDir: '.next-custom',
trailingSlash: true,
generateBuildId() {
return 'test-build-id'
Expand Down
36 changes: 36 additions & 0 deletions test/integration/app-dir-export/test/dev-custom-dist-dir.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/* eslint-env jest */

import { join } from 'path'
import fs from 'fs-extra'
import {
fetchViaHTTP,
File,
findPort,
killApp,
launchApp,
} from 'next-test-utils'

const appDir = join(__dirname, '..')
const distDir = join(appDir, '.next-custom')
const nextConfig = new File(join(appDir, 'next.config.js'))
let app
let appPort

describe('app dir - with output export and custom distDir (next dev)', () => {
beforeAll(async () => {
nextConfig.replace('// distDir', 'distDir')
appPort = await findPort()
app = await launchApp(appDir, appPort)
})
afterAll(async () => {
nextConfig.restore()
await fs.remove(distDir)
await killApp(app)
})

it('should render properly', async () => {
const res = await fetchViaHTTP(appPort, '/')
expect(res.status).toBe(200)
expect(await res.text()).toContain('Home')
})
})

0 comments on commit b10a610

Please sign in to comment.