From 88eb0fe77f8dad9eb0874c5ebd33a5e9eac808b3 Mon Sep 17 00:00:00 2001 From: Prateek Bhatnagar Date: Wed, 12 Aug 2020 09:55:57 -0700 Subject: [PATCH 1/4] fixing css minification --- .../font-stylesheet-gathering-plugin.ts | 21 +++++++++++++------ .../font-optimization/next.config.js | 1 - .../font-optimization/test/index.test.js | 21 +++++++++++++++++++ .../test/manifest-snapshot.json | 14 +++++++++++++ 4 files changed, 50 insertions(+), 7 deletions(-) delete mode 100644 test/integration/font-optimization/next.config.js create mode 100644 test/integration/font-optimization/test/manifest-snapshot.json diff --git a/packages/next/build/webpack/plugins/font-stylesheet-gathering-plugin.ts b/packages/next/build/webpack/plugins/font-stylesheet-gathering-plugin.ts index 1a25c61f37dca..2101c313adf86 100644 --- a/packages/next/build/webpack/plugins/font-stylesheet-gathering-plugin.ts +++ b/packages/next/build/webpack/plugins/font-stylesheet-gathering-plugin.ts @@ -7,17 +7,26 @@ import { } from '../../../next-server/server/font-utils' // @ts-ignore import BasicEvaluatedExpression from 'webpack/lib/BasicEvaluatedExpression' -import { process as minify } from 'cssnano-simple' +import postcss from 'postcss' +import minifier from 'cssnano-simple' import { OPTIMIZED_FONT_PROVIDERS } from '../../../next-server/lib/constants' const isWebpack5 = parseInt(webpack.version!) === 5 async function minifyCss(css: string): Promise { - return new Promise((resolve) => { - minify(css, { map: false }).then((res) => { - resolve(res.css) - }) - }) + return new Promise((resolve) => + postcss([ + minifier({ + excludeAll: true, + discardComments: true, + normalizeWhitespace: { exclude: false }, + }), + ]) + .process(css, { from: undefined }) + .then((res) => { + resolve(res.css) + }) + ) } export class FontStylesheetGatheringPlugin { diff --git a/test/integration/font-optimization/next.config.js b/test/integration/font-optimization/next.config.js deleted file mode 100644 index 98699f91d5c7b..0000000000000 --- a/test/integration/font-optimization/next.config.js +++ /dev/null @@ -1 +0,0 @@ -module.exports = { target: 'serverless', experimental: { optimizeFonts: true } } diff --git a/test/integration/font-optimization/test/index.test.js b/test/integration/font-optimization/test/index.test.js index d1aa9fd66af5c..b5046b55eb992 100644 --- a/test/integration/font-optimization/test/index.test.js +++ b/test/integration/font-optimization/test/index.test.js @@ -73,6 +73,27 @@ function runTests() { /