diff --git a/packages/next/build/webpack-config.ts b/packages/next/build/webpack-config.ts index 23df952770384..686ecd3cdde34 100644 --- a/packages/next/build/webpack-config.ts +++ b/packages/next/build/webpack-config.ts @@ -1013,7 +1013,7 @@ export default async function getBaseWebpackConfig( config.experimental.optimizeImages ), 'process.env.__NEXT_OPTIMIZE_CSS': JSON.stringify( - !!config.experimental.optimizeCss && !dev + config.experimental.optimizeCss && !dev ), 'process.env.__NEXT_SCROLL_RESTORATION': JSON.stringify( config.experimental.scrollRestoration @@ -1202,6 +1202,7 @@ export default async function getBaseWebpackConfig( reactMode: config.experimental.reactMode, optimizeFonts: config.experimental.optimizeFonts, optimizeImages: config.experimental.optimizeImages, + optimizeCss: config.experimental.optimizeCss, scrollRestoration: config.experimental.scrollRestoration, basePath: config.basePath, pageEnv: config.experimental.pageEnv, diff --git a/packages/next/next-server/server/next-server.ts b/packages/next/next-server/server/next-server.ts index 382e8c28a2307..7d0325545fe06 100644 --- a/packages/next/next-server/server/next-server.ts +++ b/packages/next/next-server/server/next-server.ts @@ -1575,6 +1575,8 @@ export default class Server { locale, locales, defaultLocale, + optimizeCss: this.renderOpts.optimizeCss, + distDir: this.distDir, fontManifest: this.renderOpts.fontManifest, domainLocales: this.renderOpts.domainLocales, } diff --git a/test/integration/critical-css/pages/index.js b/test/integration/critical-css/pages/index.js index d3eeb9f702094..d367b212757c9 100644 --- a/test/integration/critical-css/pages/index.js +++ b/test/integration/critical-css/pages/index.js @@ -7,3 +7,5 @@ export default function Home() { ) } + +Home.getInitialProps = () => ({}) diff --git a/test/integration/critical-css/test/index.test.js b/test/integration/critical-css/test/index.test.js index bf99ee1b7f998..3144498866871 100644 --- a/test/integration/critical-css/test/index.test.js +++ b/test/integration/critical-css/test/index.test.js @@ -65,3 +65,21 @@ describe('CSS optimization for serverless apps', () => { afterAll(() => killApp(app)) runTests() }) + +describe('Font optimization for emulated serverless apps', () => { + beforeAll(async () => { + await fs.writeFile( + nextConfig, + `module.exports = { target: 'experimental-serverless-trace', experimental: {optimizeCss: true} }`, + 'utf8' + ) + await nextBuild(appDir) + appPort = await findPort() + app = await nextStart(appDir, appPort) + }) + afterAll(async () => { + await killApp(app) + await fs.remove(nextConfig) + }) + runTests() +})