Skip to content

Commit 95a8f31

Browse files
authored
Fix outputStandalone with optimizeCss (#36028)
1 parent 8c57979 commit 95a8f31

File tree

2 files changed

+51
-7
lines changed

2 files changed

+51
-7
lines changed

packages/next/build/index.ts

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2085,14 +2085,15 @@ export default async function build(
20852085
}, []),
20862086
]) {
20872087
const filePath = path.join(dir, file)
2088-
await promises.copyFile(
2089-
filePath,
2090-
path.join(
2091-
distDir,
2092-
'standalone',
2093-
path.relative(outputFileTracingRoot, filePath)
2094-
)
2088+
const outputPath = path.join(
2089+
distDir,
2090+
'standalone',
2091+
path.relative(outputFileTracingRoot, filePath)
20952092
)
2093+
await promises.mkdir(path.dirname(outputPath), {
2094+
recursive: true,
2095+
})
2096+
await promises.copyFile(filePath, outputPath)
20962097
}
20972098
await recursiveCopy(
20982099
path.join(distDir, SERVER_DIRECTORY, 'pages'),
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
import { createNext } from 'e2e-utils'
2+
import { NextInstance } from 'test/lib/next-modes/base'
3+
import { renderViaHTTP } from 'next-test-utils'
4+
5+
describe('standalone mode and optimizeCss', () => {
6+
let next: NextInstance
7+
8+
beforeAll(async () => {
9+
next = await createNext({
10+
files: {
11+
'pages/index.js': `
12+
import styles from './index.module.css'
13+
14+
export default function Page() {
15+
return <p className={styles.home}>hello world</p>
16+
}
17+
`,
18+
'pages/index.module.css': `
19+
.home {
20+
background: orange;
21+
color: black;
22+
}
23+
`,
24+
},
25+
nextConfig: {
26+
experimental: {
27+
optimizeCss: true,
28+
outputStandalone: true,
29+
},
30+
},
31+
dependencies: {
32+
critters: 'latest',
33+
},
34+
})
35+
})
36+
afterAll(() => next.destroy())
37+
38+
it('should work', async () => {
39+
const html = await renderViaHTTP(next.url, '/')
40+
expect(html).toContain('hello world')
41+
expect(html).toContain('background:orange')
42+
})
43+
})

0 commit comments

Comments
 (0)