From 41429420172206b3f7e6c790d118077297b2aa16 Mon Sep 17 00:00:00 2001 From: Artem Abramov Date: Fri, 13 Jun 2025 09:44:25 +0400 Subject: [PATCH 1/2] feat: add css files to server bundle for optimizeCss feature to work --- packages/open-next/src/build/copyTracedFiles.ts | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/packages/open-next/src/build/copyTracedFiles.ts b/packages/open-next/src/build/copyTracedFiles.ts index 0dd2f15a8..445b05eba 100644 --- a/packages/open-next/src/build/copyTracedFiles.ts +++ b/packages/open-next/src/build/copyTracedFiles.ts @@ -2,6 +2,7 @@ import url from "node:url"; import { copyFileSync, + cpSync, existsSync, mkdirSync, readFileSync, @@ -360,6 +361,14 @@ File ${serverPath} does not exist .forEach((file) => copyStaticFile(`server/${file}`)); } + // Copy .next/static/css from standalone to output dir + // needed for optimizeCss feature to work + cpSync( + path.join(standaloneNextDir, "static", "css"), + path.join(outputNextDir, "static", "css"), + { recursive: true }, + ); + logger.debug("copyTracedFiles:", Date.now() - tsStart, "ms"); return { From a48b3a7bcd68cbe522da4e2e73cf9ceee5097c5c Mon Sep 17 00:00:00 2001 From: Artem Abramov Date: Mon, 16 Jun 2025 11:21:20 +0400 Subject: [PATCH 2/2] feat: add css files to server bundle for optimizeCss feature to work - add css files conditionally depending on optimizeCss flag --- .../open-next/src/build/copyTracedFiles.ts | 18 ++++++++++++------ packages/open-next/src/types/next-types.ts | 1 + 2 files changed, 13 insertions(+), 6 deletions(-) diff --git a/packages/open-next/src/build/copyTracedFiles.ts b/packages/open-next/src/build/copyTracedFiles.ts index 445b05eba..d38338f7b 100644 --- a/packages/open-next/src/build/copyTracedFiles.ts +++ b/packages/open-next/src/build/copyTracedFiles.ts @@ -361,19 +361,25 @@ File ${serverPath} does not exist .forEach((file) => copyStaticFile(`server/${file}`)); } + const manifests = getManifests(standaloneNextDir); + + const { optimizeCss } = manifests.config.experimental; + // Copy .next/static/css from standalone to output dir // needed for optimizeCss feature to work - cpSync( - path.join(standaloneNextDir, "static", "css"), - path.join(outputNextDir, "static", "css"), - { recursive: true }, - ); + if (optimizeCss) { + cpSync( + path.join(standaloneNextDir, "static", "css"), + path.join(outputNextDir, "static", "css"), + { recursive: true }, + ); + } logger.debug("copyTracedFiles:", Date.now() - tsStart, "ms"); return { tracedFiles, nodePackages, - manifests: getManifests(standaloneNextDir), + manifests, }; } diff --git a/packages/open-next/src/types/next-types.ts b/packages/open-next/src/types/next-types.ts index 83cfb66c5..face7fbaa 100644 --- a/packages/open-next/src/types/next-types.ts +++ b/packages/open-next/src/types/next-types.ts @@ -82,6 +82,7 @@ export interface NextConfig { experimental: { serverActions?: boolean; appDir?: boolean; + optimizeCss?: boolean; }; images: ImageConfig; poweredByHeader?: boolean;