diff --git a/packages/next/build/index.ts b/packages/next/build/index.ts index 37d7f95338da..268c315debbb 100644 --- a/packages/next/build/index.ts +++ b/packages/next/build/index.ts @@ -2085,14 +2085,15 @@ export default async function build( }, []), ]) { const filePath = path.join(dir, file) - await promises.copyFile( - filePath, - path.join( - distDir, - 'standalone', - path.relative(outputFileTracingRoot, filePath) - ) + const outputPath = path.join( + distDir, + 'standalone', + path.relative(outputFileTracingRoot, filePath) ) + await promises.mkdir(path.dirname(outputPath), { + recursive: true, + }) + await promises.copyFile(filePath, outputPath) } await recursiveCopy( path.join(distDir, SERVER_DIRECTORY, 'pages'), diff --git a/test/production/standalone-mode-and-optimizecss/index.test.ts b/test/production/standalone-mode-and-optimizecss/index.test.ts new file mode 100644 index 000000000000..5a337d0ef1c0 --- /dev/null +++ b/test/production/standalone-mode-and-optimizecss/index.test.ts @@ -0,0 +1,43 @@ +import { createNext } from 'e2e-utils' +import { NextInstance } from 'test/lib/next-modes/base' +import { renderViaHTTP } from 'next-test-utils' + +describe('standalone mode and optimizeCss', () => { + let next: NextInstance + + beforeAll(async () => { + next = await createNext({ + files: { + 'pages/index.js': ` + import styles from './index.module.css' + + export default function Page() { + return

hello world

+ } + `, + 'pages/index.module.css': ` + .home { + background: orange; + color: black; + } + `, + }, + nextConfig: { + experimental: { + optimizeCss: true, + outputStandalone: true, + }, + }, + dependencies: { + critters: 'latest', + }, + }) + }) + afterAll(() => next.destroy()) + + it('should work', async () => { + const html = await renderViaHTTP(next.url, '/') + expect(html).toContain('hello world') + expect(html).toContain('background:orange') + }) +})