diff --git a/.changeset/stale-years-arrive.md b/.changeset/stale-years-arrive.md new file mode 100644 index 000000000..6fd7e6411 --- /dev/null +++ b/.changeset/stale-years-arrive.md @@ -0,0 +1,7 @@ +--- +"@opennextjs/aws": patch +--- + +- add css files to server bundle for optimizeCss feature to work + +- load all manifests and configs in copyTracedFiles in one place once diff --git a/packages/open-next/src/build/copyTracedFiles.ts b/packages/open-next/src/build/copyTracedFiles.ts index 0dd2f15a8..e82b59e25 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, @@ -331,17 +332,17 @@ File ${serverPath} does not exist ); } }; + + const manifests = getManifests(standaloneNextDir); + const { config, prerenderManifest, pagesManifest } = manifests; + // Get all the static files - Should be only for pages dir // Ideally we would filter only those that might get accessed in this specific functions // Maybe even move this to s3 directly if (hasPageDir) { // First we get truly static files - i.e. pages without getStaticProps - const staticFiles: Array = Object.values( - loadPagesManifest(standaloneNextDir), - ); + const staticFiles: Array = Object.values(pagesManifest); // Then we need to get all fallback: true dynamic routes html - const prerenderManifest = loadPrerenderManifest(standaloneNextDir); - const config = loadConfig(standaloneNextDir); const locales = config.i18n?.locales; Object.values(prerenderManifest.dynamicRoutes).forEach((route) => { if (typeof route.fallback === "string") { @@ -360,11 +361,21 @@ 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 + if (config.experimental.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;