Skip to content

Commit b10a610

Browse files
committed
Fix output: export with custom distDir (#62064)
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
1 parent 960b738 commit b10a610

File tree

3 files changed

+38
-1
lines changed

3 files changed

+38
-1
lines changed

packages/next/src/build/webpack-config.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -372,7 +372,7 @@ export default async function getBaseWebpackConfig(
372372

373373
const babelConfigFile = getBabelConfigFile(dir)
374374

375-
if (hasCustomExportOutput(config)) {
375+
if (!dev && hasCustomExportOutput(config)) {
376376
config.distDir = '.next'
377377
}
378378
const distDir = path.join(dir, config.distDir)

test/integration/app-dir-export/next.config.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
/** @type {import('next').NextConfig} */
22
const nextConfig = {
33
output: 'export',
4+
// distDir: '.next-custom',
45
trailingSlash: true,
56
generateBuildId() {
67
return 'test-build-id'
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
/* eslint-env jest */
2+
3+
import { join } from 'path'
4+
import fs from 'fs-extra'
5+
import {
6+
fetchViaHTTP,
7+
File,
8+
findPort,
9+
killApp,
10+
launchApp,
11+
} from 'next-test-utils'
12+
13+
const appDir = join(__dirname, '..')
14+
const distDir = join(appDir, '.next-custom')
15+
const nextConfig = new File(join(appDir, 'next.config.js'))
16+
let app
17+
let appPort
18+
19+
describe('app dir - with output export and custom distDir (next dev)', () => {
20+
beforeAll(async () => {
21+
nextConfig.replace('// distDir', 'distDir')
22+
appPort = await findPort()
23+
app = await launchApp(appDir, appPort)
24+
})
25+
afterAll(async () => {
26+
nextConfig.restore()
27+
await fs.remove(distDir)
28+
await killApp(app)
29+
})
30+
31+
it('should render properly', async () => {
32+
const res = await fetchViaHTTP(appPort, '/')
33+
expect(res.status).toBe(200)
34+
expect(await res.text()).toContain('Home')
35+
})
36+
})

0 commit comments

Comments
 (0)