Skip to content

Commit 075be1e

Browse files
authored
feat: add css files to server bundle for optimizeCss feature to work (#904)
* feat: add css files to server bundle for optimizeCss feature to work * feat: add css files to server bundle for optimizeCss feature to work - add css files conditionally depending on optimizeCss flag * feat: add css files to server bundle for optimizeCss feature to work - load all manifests and configs in one place once * feat: add css files to server bundle for optimizeCss feature to work - changeset
1 parent 8aa730a commit 075be1e

File tree

3 files changed

+25
-6
lines changed

3 files changed

+25
-6
lines changed

.changeset/stale-years-arrive.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
---
2+
"@opennextjs/aws": patch
3+
---
4+
5+
- add css files to server bundle for optimizeCss feature to work
6+
7+
- load all manifests and configs in copyTracedFiles in one place once

packages/open-next/src/build/copyTracedFiles.ts

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import url from "node:url";
22

33
import {
44
copyFileSync,
5+
cpSync,
56
existsSync,
67
mkdirSync,
78
readFileSync,
@@ -331,17 +332,17 @@ File ${serverPath} does not exist
331332
);
332333
}
333334
};
335+
336+
const manifests = getManifests(standaloneNextDir);
337+
const { config, prerenderManifest, pagesManifest } = manifests;
338+
334339
// Get all the static files - Should be only for pages dir
335340
// Ideally we would filter only those that might get accessed in this specific functions
336341
// Maybe even move this to s3 directly
337342
if (hasPageDir) {
338343
// First we get truly static files - i.e. pages without getStaticProps
339-
const staticFiles: Array<string> = Object.values(
340-
loadPagesManifest(standaloneNextDir),
341-
);
344+
const staticFiles: Array<string> = Object.values(pagesManifest);
342345
// Then we need to get all fallback: true dynamic routes html
343-
const prerenderManifest = loadPrerenderManifest(standaloneNextDir);
344-
const config = loadConfig(standaloneNextDir);
345346
const locales = config.i18n?.locales;
346347
Object.values(prerenderManifest.dynamicRoutes).forEach((route) => {
347348
if (typeof route.fallback === "string") {
@@ -360,11 +361,21 @@ File ${serverPath} does not exist
360361
.forEach((file) => copyStaticFile(`server/${file}`));
361362
}
362363

364+
// Copy .next/static/css from standalone to output dir
365+
// needed for optimizeCss feature to work
366+
if (config.experimental.optimizeCss) {
367+
cpSync(
368+
path.join(standaloneNextDir, "static", "css"),
369+
path.join(outputNextDir, "static", "css"),
370+
{ recursive: true },
371+
);
372+
}
373+
363374
logger.debug("copyTracedFiles:", Date.now() - tsStart, "ms");
364375

365376
return {
366377
tracedFiles,
367378
nodePackages,
368-
manifests: getManifests(standaloneNextDir),
379+
manifests,
369380
};
370381
}

packages/open-next/src/types/next-types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ export interface NextConfig {
8282
experimental: {
8383
serverActions?: boolean;
8484
appDir?: boolean;
85+
optimizeCss?: boolean;
8586
};
8687
images: ImageConfig;
8788
poweredByHeader?: boolean;

0 commit comments

Comments
 (0)