From 7a1d8bc5a6639f3f9ed687fdb6cd5e6830431785 Mon Sep 17 00:00:00 2001 From: sebastien Date: Thu, 26 Sep 2024 18:19:00 +0200 Subject: [PATCH 1/8] Base setup for LightningCSS faster option --- .../docusaurus-bundler/src/importFaster.ts | 17 ++- .../docusaurus-bundler/src/minification.ts | 27 ++++- packages/docusaurus-faster/package.json | 6 +- packages/docusaurus-faster/src/index.ts | 15 +++ yarn.lock | 101 +++++++++++++++--- 5 files changed, 145 insertions(+), 21 deletions(-) diff --git a/packages/docusaurus-bundler/src/importFaster.ts b/packages/docusaurus-bundler/src/importFaster.ts index fcdf160f7a86..f668f39641ba 100644 --- a/packages/docusaurus-bundler/src/importFaster.ts +++ b/packages/docusaurus-bundler/src/importFaster.ts @@ -6,7 +6,11 @@ */ import type {ConfigureWebpackUtils} from '@docusaurus/types'; -import type {MinimizerOptions, CustomOptions} from 'terser-webpack-plugin'; +import type { + MinimizerOptions as JsMinimizerOptions, + CustomOptions, +} from 'terser-webpack-plugin'; +import type {MinimizerOptions as CssMinimizerOptions} from 'css-minimizer-webpack-plugin'; async function importFaster() { return import('@docusaurus/faster'); @@ -31,8 +35,15 @@ export async function importSwcJsLoaderFactory(): Promise< } export async function importSwcJsMinifierOptions(): Promise< - MinimizerOptions + JsMinimizerOptions > { const faster = await ensureFaster(); - return faster.getSwcJsMinifierOptions() as MinimizerOptions; + return faster.getSwcJsMinifierOptions() as JsMinimizerOptions; +} + +export async function importLightningCssMinimizerOptions(): Promise< + CssMinimizerOptions +> { + const faster = await ensureFaster(); + return faster.getLightningCssMinimizerOptions() as CssMinimizerOptions; } diff --git a/packages/docusaurus-bundler/src/minification.ts b/packages/docusaurus-bundler/src/minification.ts index 49305b7c6d4d..ad2012dd7647 100644 --- a/packages/docusaurus-bundler/src/minification.ts +++ b/packages/docusaurus-bundler/src/minification.ts @@ -7,7 +7,10 @@ import TerserPlugin from 'terser-webpack-plugin'; import CssMinimizerPlugin from 'css-minimizer-webpack-plugin'; -import {importSwcJsMinifierOptions} from './importFaster'; +import { + importSwcJsMinifierOptions, + importLightningCssMinimizerOptions, +} from './importFaster'; import type {CustomOptions, CssNanoOptions} from 'css-minimizer-webpack-plugin'; import type {WebpackPluginInstance} from 'webpack'; import type {CurrentBundler, FasterConfig} from '@docusaurus/types'; @@ -69,6 +72,13 @@ async function getJsMinimizer({faster}: MinimizersConfig) { }); } +async function getLightningCssMinimizer() { + return new CssMinimizerPlugin({ + minify: CssMinimizerPlugin.lightningCssMinify, + minimizerOptions: await importLightningCssMinimizerOptions(), + }); +} + function getAdvancedCssMinifier() { // Using the array syntax to add 2 minimizers // see https://github.com/webpack-contrib/css-minimizer-webpack-plugin#array @@ -101,10 +111,23 @@ function getAdvancedCssMinifier() { }); } -function getCssMinimizer(): WebpackPluginInstance { +async function getCssMinimizer(): Promise { // This is an historical env variable to opt-out of the advanced minifier // Sometimes there's a bug in it and people are happy to disable it const useSimpleCssMinifier = process.env.USE_SIMPLE_CSS_MINIFIER === 'true'; + + // TODO wire this to options + const useLightningCssMinimizer = true; + + if (useLightningCssMinimizer) { + if (useSimpleCssMinifier) { + throw new Error( + "You can't use LightningCSS and the USE_SIMPLE_CSS_MINIFIER=true env variable at the same time", + ); + } + return getLightningCssMinimizer(); + } + if (useSimpleCssMinifier) { return new CssMinimizerPlugin(); } else { diff --git a/packages/docusaurus-faster/package.json b/packages/docusaurus-faster/package.json index a25d313cdcfc..a38f4984cebb 100644 --- a/packages/docusaurus-faster/package.json +++ b/packages/docusaurus-faster/package.json @@ -18,9 +18,11 @@ }, "license": "MIT", "dependencies": { - "webpack": "^5.88.1", "@swc/core": "^1.7.14", - "swc-loader": "^0.2.6" + "browserslist": "^4.24.0", + "lightningcss": "^1.27.0", + "swc-loader": "^0.2.6", + "webpack": "^5.88.1" }, "engines": { "node": ">=18.0" diff --git a/packages/docusaurus-faster/src/index.ts b/packages/docusaurus-faster/src/index.ts index 0f079f68a5c6..686ad35fcd34 100644 --- a/packages/docusaurus-faster/src/index.ts +++ b/packages/docusaurus-faster/src/index.ts @@ -5,6 +5,8 @@ * LICENSE file in the root directory of this source tree. */ +import * as lightningcss from 'lightningcss'; +import browserslist from 'browserslist'; import type {RuleSetRule} from 'webpack'; import type {JsMinifyOptions} from '@swc/core'; @@ -55,3 +57,16 @@ export function getSwcJsMinifierOptions(): JsMinifyOptions { }, }; } + +// LightningCSS doesn't expose any type for css-minimizer-webpack-plugin setup +// So we derive it ourselves +// see https://lightningcss.dev/docs.html#with-webpack +type LightningCssMinimizerOptions = Omit< + lightningcss.TransformOptions, + 'filename' | 'code' +>; + +export function getLightningCssMinimizerOptions(): LightningCssMinimizerOptions { + const queries = browserslist(); + return {targets: lightningcss.browserslistToTargets(queries)}; +} diff --git a/yarn.lock b/yarn.lock index 08b0a1ef68d3..a2108d968687 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4959,13 +4959,13 @@ braces@^3.0.3, braces@~3.0.2: dependencies: fill-range "^7.1.1" -browserslist@^4.0.0, browserslist@^4.18.1, browserslist@^4.21.10, browserslist@^4.23.0, browserslist@^4.23.1, browserslist@^4.23.3: - version "4.23.3" - resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.23.3.tgz#debb029d3c93ebc97ffbc8d9cbb03403e227c800" - integrity sha512-btwCFJVjI4YWDNfau8RhZ+B1Q/VLoUITrm3RlP6y1tYGWIOa+InuYiRGXUBXo8nA1qKmHMyLB/iVQg5TT4eFoA== +browserslist@^4.0.0, browserslist@^4.18.1, browserslist@^4.21.10, browserslist@^4.23.0, browserslist@^4.23.1, browserslist@^4.23.3, browserslist@^4.24.0: + version "4.24.0" + resolved "https://registry.yarnpkg.com/browserslist/-/browserslist-4.24.0.tgz#a1325fe4bc80b64fda169629fc01b3d6cecd38d4" + integrity sha512-Rmb62sR1Zpjql25eSanFGEhAxcFwfA1K0GuQcLoaJBAcENegrQut3hYdhXFF1obQfiDyqIW/cLM5HSJ/9k884A== dependencies: - caniuse-lite "^1.0.30001646" - electron-to-chromium "^1.5.4" + caniuse-lite "^1.0.30001663" + electron-to-chromium "^1.5.28" node-releases "^2.0.18" update-browserslist-db "^1.1.0" @@ -5186,10 +5186,10 @@ caniuse-api@^3.0.0: lodash.memoize "^4.1.2" lodash.uniq "^4.5.0" -caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001646: - version "1.0.30001651" - resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001651.tgz#52de59529e8b02b1aedcaaf5c05d9e23c0c28138" - integrity sha512-9Cf+Xv1jJNe1xPZLGuUXLNkE1BoDkqRqYyFJ9TDYSqhduqA4hu4oR9HluGoWYQC/aj8WHjsGVV+bwkh0+tegRg== +caniuse-lite@^1.0.0, caniuse-lite@^1.0.30001646, caniuse-lite@^1.0.30001663: + version "1.0.30001664" + resolved "https://registry.yarnpkg.com/caniuse-lite/-/caniuse-lite-1.0.30001664.tgz#d588d75c9682d3301956b05a3749652a80677df4" + integrity sha512-AmE7k4dXiNKQipgn7a2xg558IRqPN3jMQY/rOsbxDhrd0tyChwbITBfiwtnqz8bi2M5mIWbxAYBvk7W7QBUS2g== ccount@^2.0.0: version "2.0.1" @@ -6897,6 +6897,11 @@ detect-indent@^5.0.0: resolved "https://registry.yarnpkg.com/detect-indent/-/detect-indent-5.0.0.tgz#3871cc0a6a002e8c3e5b3cf7f336264675f06b9d" integrity sha512-rlpvsxUtM0PQvy9iZe640/IWwWYyBsTApREbA1pHOpmOUIl9MkP/U4z7vTtg4Oaojvqhxt7sdufnT0EzGaR31g== +detect-libc@^1.0.3: + version "1.0.3" + resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-1.0.3.tgz#fa137c4bd698edf55cd5cd02ac559f91a4c4ba9b" + integrity sha512-pGjwhsmsp4kL2RTz08wcOlGN83otlqHeD/Z5T8GXZB+/YcpQ/dgo+lbU8ZsGxV0HIvqqxo9l7mqYwyYMD9bKDg== + detect-libc@^2.0.0, detect-libc@^2.0.2: version "2.0.2" resolved "https://registry.yarnpkg.com/detect-libc/-/detect-libc-2.0.2.tgz#8ccf2ba9315350e1241b88d0ac3b0e1fbd99605d" @@ -7103,10 +7108,10 @@ ejs@^3.1.6, ejs@^3.1.7: dependencies: jake "^10.8.5" -electron-to-chromium@^1.5.4: - version "1.5.13" - resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.13.tgz#1abf0410c5344b2b829b7247e031f02810d442e6" - integrity sha512-lbBcvtIJ4J6sS4tb5TLp1b4LyfCdMkwStzXPyAgVgTRAsep4bvrAGaBOP7ZJtQMNJpSQ9SqG4brWOroNaQtm7Q== +electron-to-chromium@^1.5.28: + version "1.5.29" + resolved "https://registry.yarnpkg.com/electron-to-chromium/-/electron-to-chromium-1.5.29.tgz#aa592a3caa95d07cc26a66563accf99fa573a1ee" + integrity sha512-PF8n2AlIhCKXQ+gTpiJi0VhcHDb69kYX4MtCiivctc2QD3XuNZ/XIOlbGzt7WAjjEev0TtaH6Cu3arZExm5DOw== emittery@^0.13.1: version "0.13.1" @@ -10737,6 +10742,74 @@ libnpmpublish@7.1.4: sigstore "^1.4.0" ssri "^10.0.1" +lightningcss-darwin-arm64@1.27.0: + version "1.27.0" + resolved "https://registry.yarnpkg.com/lightningcss-darwin-arm64/-/lightningcss-darwin-arm64-1.27.0.tgz#565bd610533941cba648a70e105987578d82f996" + integrity sha512-Gl/lqIXY+d+ySmMbgDf0pgaWSqrWYxVHoc88q+Vhf2YNzZ8DwoRzGt5NZDVqqIW5ScpSnmmjcgXP87Dn2ylSSQ== + +lightningcss-darwin-x64@1.27.0: + version "1.27.0" + resolved "https://registry.yarnpkg.com/lightningcss-darwin-x64/-/lightningcss-darwin-x64-1.27.0.tgz#c906a267237b1c7fe08bff6c5ac032c099bc9482" + integrity sha512-0+mZa54IlcNAoQS9E0+niovhyjjQWEMrwW0p2sSdLRhLDc8LMQ/b67z7+B5q4VmjYCMSfnFi3djAAQFIDuj/Tg== + +lightningcss-freebsd-x64@1.27.0: + version "1.27.0" + resolved "https://registry.yarnpkg.com/lightningcss-freebsd-x64/-/lightningcss-freebsd-x64-1.27.0.tgz#a7c3c4d6ee18dffeb8fa69f14f8f9267f7dc0c34" + integrity sha512-n1sEf85fePoU2aDN2PzYjoI8gbBqnmLGEhKq7q0DKLj0UTVmOTwDC7PtLcy/zFxzASTSBlVQYJUhwIStQMIpRA== + +lightningcss-linux-arm-gnueabihf@1.27.0: + version "1.27.0" + resolved "https://registry.yarnpkg.com/lightningcss-linux-arm-gnueabihf/-/lightningcss-linux-arm-gnueabihf-1.27.0.tgz#c7c16432a571ec877bf734fe500e4a43d48c2814" + integrity sha512-MUMRmtdRkOkd5z3h986HOuNBD1c2lq2BSQA1Jg88d9I7bmPGx08bwGcnB75dvr17CwxjxD6XPi3Qh8ArmKFqCA== + +lightningcss-linux-arm64-gnu@1.27.0: + version "1.27.0" + resolved "https://registry.yarnpkg.com/lightningcss-linux-arm64-gnu/-/lightningcss-linux-arm64-gnu-1.27.0.tgz#cfd9e18df1cd65131da286ddacfa3aee6862a752" + integrity sha512-cPsxo1QEWq2sfKkSq2Bq5feQDHdUEwgtA9KaB27J5AX22+l4l0ptgjMZZtYtUnteBofjee+0oW1wQ1guv04a7A== + +lightningcss-linux-arm64-musl@1.27.0: + version "1.27.0" + resolved "https://registry.yarnpkg.com/lightningcss-linux-arm64-musl/-/lightningcss-linux-arm64-musl-1.27.0.tgz#6682ff6b9165acef9a6796bd9127a8e1247bb0ed" + integrity sha512-rCGBm2ax7kQ9pBSeITfCW9XSVF69VX+fm5DIpvDZQl4NnQoMQyRwhZQm9pd59m8leZ1IesRqWk2v/DntMo26lg== + +lightningcss-linux-x64-gnu@1.27.0: + version "1.27.0" + resolved "https://registry.yarnpkg.com/lightningcss-linux-x64-gnu/-/lightningcss-linux-x64-gnu-1.27.0.tgz#714221212ad184ddfe974bbb7dbe9300dfde4bc0" + integrity sha512-Dk/jovSI7qqhJDiUibvaikNKI2x6kWPN79AQiD/E/KeQWMjdGe9kw51RAgoWFDi0coP4jinaH14Nrt/J8z3U4A== + +lightningcss-linux-x64-musl@1.27.0: + version "1.27.0" + resolved "https://registry.yarnpkg.com/lightningcss-linux-x64-musl/-/lightningcss-linux-x64-musl-1.27.0.tgz#247958daf622a030a6dc2285afa16b7184bdf21e" + integrity sha512-QKjTxXm8A9s6v9Tg3Fk0gscCQA1t/HMoF7Woy1u68wCk5kS4fR+q3vXa1p3++REW784cRAtkYKrPy6JKibrEZA== + +lightningcss-win32-arm64-msvc@1.27.0: + version "1.27.0" + resolved "https://registry.yarnpkg.com/lightningcss-win32-arm64-msvc/-/lightningcss-win32-arm64-msvc-1.27.0.tgz#64cfe473c264ef5dc275a4d57a516d77fcac6bc9" + integrity sha512-/wXegPS1hnhkeG4OXQKEMQeJd48RDC3qdh+OA8pCuOPCyvnm/yEayrJdJVqzBsqpy1aJklRCVxscpFur80o6iQ== + +lightningcss-win32-x64-msvc@1.27.0: + version "1.27.0" + resolved "https://registry.yarnpkg.com/lightningcss-win32-x64-msvc/-/lightningcss-win32-x64-msvc-1.27.0.tgz#237d0dc87d9cdc9cf82536bcbc07426fa9f3f422" + integrity sha512-/OJLj94Zm/waZShL8nB5jsNj3CfNATLCTyFxZyouilfTmSoLDX7VlVAmhPHoZWVFp4vdmoiEbPEYC8HID3m6yw== + +lightningcss@^1.27.0: + version "1.27.0" + resolved "https://registry.yarnpkg.com/lightningcss/-/lightningcss-1.27.0.tgz#d4608e63044343836dd9769f6c8b5d607867649a" + integrity sha512-8f7aNmS1+etYSLHht0fQApPc2kNO8qGRutifN5rVIc6Xo6ABsEbqOr758UwI7ALVbTt4x1fllKt0PYgzD9S3yQ== + dependencies: + detect-libc "^1.0.3" + optionalDependencies: + lightningcss-darwin-arm64 "1.27.0" + lightningcss-darwin-x64 "1.27.0" + lightningcss-freebsd-x64 "1.27.0" + lightningcss-linux-arm-gnueabihf "1.27.0" + lightningcss-linux-arm64-gnu "1.27.0" + lightningcss-linux-arm64-musl "1.27.0" + lightningcss-linux-x64-gnu "1.27.0" + lightningcss-linux-x64-musl "1.27.0" + lightningcss-win32-arm64-msvc "1.27.0" + lightningcss-win32-x64-msvc "1.27.0" + lilconfig@2.1.0: version "2.1.0" resolved "https://registry.yarnpkg.com/lilconfig/-/lilconfig-2.1.0.tgz#78e23ac89ebb7e1bfbf25b18043de756548e7f52" From c8c12a190e46ab0ea02a10c24042497f2333c2b2 Mon Sep 17 00:00:00 2001 From: sebastien Date: Thu, 26 Sep 2024 18:29:29 +0200 Subject: [PATCH 2/8] wire lightningCssMinimizer faster option --- .../docusaurus-bundler/src/importFaster.ts | 4 +- .../docusaurus-bundler/src/minification.ts | 51 ++++++------- packages/docusaurus-faster/src/index.ts | 2 +- packages/docusaurus-types/src/config.d.ts | 1 + .../server/__tests__/configValidation.test.ts | 74 +++++++++++++++++++ .../docusaurus/src/server/configValidation.ts | 5 ++ 6 files changed, 105 insertions(+), 32 deletions(-) diff --git a/packages/docusaurus-bundler/src/importFaster.ts b/packages/docusaurus-bundler/src/importFaster.ts index f668f39641ba..a880d2275b1e 100644 --- a/packages/docusaurus-bundler/src/importFaster.ts +++ b/packages/docusaurus-bundler/src/importFaster.ts @@ -34,11 +34,11 @@ export async function importSwcJsLoaderFactory(): Promise< return faster.getSwcJsLoaderFactory; } -export async function importSwcJsMinifierOptions(): Promise< +export async function importSwcJsMinimizerOptions(): Promise< JsMinimizerOptions > { const faster = await ensureFaster(); - return faster.getSwcJsMinifierOptions() as JsMinimizerOptions; + return faster.getSwcJsMinimizerOptions() as JsMinimizerOptions; } export async function importLightningCssMinimizerOptions(): Promise< diff --git a/packages/docusaurus-bundler/src/minification.ts b/packages/docusaurus-bundler/src/minification.ts index ad2012dd7647..4cd001d7322d 100644 --- a/packages/docusaurus-bundler/src/minification.ts +++ b/packages/docusaurus-bundler/src/minification.ts @@ -8,7 +8,7 @@ import TerserPlugin from 'terser-webpack-plugin'; import CssMinimizerPlugin from 'css-minimizer-webpack-plugin'; import { - importSwcJsMinifierOptions, + importSwcJsMinimizerOptions, importLightningCssMinimizerOptions, } from './importFaster'; import type {CustomOptions, CssNanoOptions} from 'css-minimizer-webpack-plugin'; @@ -16,7 +16,7 @@ import type {WebpackPluginInstance} from 'webpack'; import type {CurrentBundler, FasterConfig} from '@docusaurus/types'; export type MinimizersConfig = { - faster: Pick; + faster: Pick; currentBundler: CurrentBundler; }; @@ -34,9 +34,11 @@ function getTerserParallel() { return terserParallel; } -async function getJsMinimizer({faster}: MinimizersConfig) { +async function getJsMinimizer({ + faster, +}: MinimizersConfig): Promise { if (faster.swcJsMinimizer) { - const terserOptions = await importSwcJsMinifierOptions(); + const terserOptions = await importSwcJsMinimizerOptions(); return new TerserPlugin({ parallel: getTerserParallel(), minify: TerserPlugin.swcMinify, @@ -72,14 +74,21 @@ async function getJsMinimizer({faster}: MinimizersConfig) { }); } -async function getLightningCssMinimizer() { +async function getLightningCssMinimizer(): Promise { return new CssMinimizerPlugin({ minify: CssMinimizerPlugin.lightningCssMinify, minimizerOptions: await importLightningCssMinimizerOptions(), }); } -function getAdvancedCssMinifier() { +async function getCssNanoMinimizer(): Promise { + // This is an historical env variable to opt-out of the advanced minimizer + // Sometimes there's a bug in it and people are happy to disable it + const useSimpleCssMinifier = process.env.USE_SIMPLE_CSS_MINIFIER === 'true'; + if (useSimpleCssMinifier) { + return new CssMinimizerPlugin(); + } + // Using the array syntax to add 2 minimizers // see https://github.com/webpack-contrib/css-minimizer-webpack-plugin#array return new CssMinimizerPlugin<[CssNanoOptions, CustomOptions]>({ @@ -111,34 +120,18 @@ function getAdvancedCssMinifier() { }); } -async function getCssMinimizer(): Promise { - // This is an historical env variable to opt-out of the advanced minifier - // Sometimes there's a bug in it and people are happy to disable it - const useSimpleCssMinifier = process.env.USE_SIMPLE_CSS_MINIFIER === 'true'; - - // TODO wire this to options - const useLightningCssMinimizer = true; - - if (useLightningCssMinimizer) { - if (useSimpleCssMinifier) { - throw new Error( - "You can't use LightningCSS and the USE_SIMPLE_CSS_MINIFIER=true env variable at the same time", - ); - } - return getLightningCssMinimizer(); - } - - if (useSimpleCssMinifier) { - return new CssMinimizerPlugin(); - } else { - return getAdvancedCssMinifier(); - } +async function getCssMinimizer( + params: MinimizersConfig, +): Promise { + return params.faster.lightningCssMinimizer + ? getLightningCssMinimizer() + : getCssNanoMinimizer(); } async function getWebpackMinimizers( params: MinimizersConfig, ): Promise { - return Promise.all([getJsMinimizer(params), getCssMinimizer()]); + return Promise.all([getJsMinimizer(params), getCssMinimizer(params)]); } async function getRspackMinimizers({ diff --git a/packages/docusaurus-faster/src/index.ts b/packages/docusaurus-faster/src/index.ts index 686ad35fcd34..e54ed6979b48 100644 --- a/packages/docusaurus-faster/src/index.ts +++ b/packages/docusaurus-faster/src/index.ts @@ -41,7 +41,7 @@ export function getSwcJsLoaderFactory({ // They should rather be kept in sync for now to avoid any unexpected behavior // The goal of faster minifier is not to fine-tune options but only to be faster // See core minification.ts -export function getSwcJsMinifierOptions(): JsMinifyOptions { +export function getSwcJsMinimizerOptions(): JsMinifyOptions { return { ecma: 2020, compress: { diff --git a/packages/docusaurus-types/src/config.d.ts b/packages/docusaurus-types/src/config.d.ts index 460333a483d9..b7e4221beed0 100644 --- a/packages/docusaurus-types/src/config.d.ts +++ b/packages/docusaurus-types/src/config.d.ts @@ -126,6 +126,7 @@ export type StorageConfig = { export type FasterConfig = { swcJsLoader: boolean; swcJsMinimizer: boolean; + lightningCssMinimizer: boolean; mdxCrossCompilerCache: boolean; rspackBundler: boolean; }; diff --git a/packages/docusaurus/src/server/__tests__/configValidation.test.ts b/packages/docusaurus/src/server/__tests__/configValidation.test.ts index 0521af1e3e97..59dfaca37ae4 100644 --- a/packages/docusaurus/src/server/__tests__/configValidation.test.ts +++ b/packages/docusaurus/src/server/__tests__/configValidation.test.ts @@ -48,6 +48,7 @@ describe('normalizeConfig', () => { experimental_faster: { swcJsLoader: true, swcJsMinimizer: true, + lightningCssMinimizer: true, mdxCrossCompilerCache: true, rspackBundler: true, }, @@ -745,6 +746,7 @@ describe('future', () => { experimental_faster: { swcJsLoader: true, swcJsMinimizer: true, + lightningCssMinimizer: true, mdxCrossCompilerCache: true, rspackBundler: true, }, @@ -1096,6 +1098,7 @@ describe('future', () => { const faster: FasterConfig = { swcJsLoader: true, swcJsMinimizer: true, + lightningCssMinimizer: true, mdxCrossCompilerCache: true, rspackBundler: true, }; @@ -1281,6 +1284,77 @@ describe('future', () => { }); }); + describe('lightningCssMinimizer', () => { + it('accepts - undefined', () => { + const faster: Partial = { + lightningCssMinimizer: undefined, + }; + expect( + normalizeConfig({ + future: { + experimental_faster: faster, + }, + }), + ).toEqual(fasterContaining({lightningCssMinimizer: false})); + }); + + it('accepts - true', () => { + const faster: Partial = { + lightningCssMinimizer: true, + }; + expect( + normalizeConfig({ + future: { + experimental_faster: faster, + }, + }), + ).toEqual(fasterContaining({lightningCssMinimizer: true})); + }); + + it('accepts - false', () => { + const faster: Partial = { + lightningCssMinimizer: false, + }; + expect( + normalizeConfig({ + future: { + experimental_faster: faster, + }, + }), + ).toEqual(fasterContaining({lightningCssMinimizer: false})); + }); + + it('rejects - null', () => { + // @ts-expect-error: invalid + const faster: Partial = {lightningCssMinimizer: 42}; + expect(() => + normalizeConfig({ + future: { + experimental_faster: faster, + }, + }), + ).toThrowErrorMatchingInlineSnapshot(` + ""future.experimental_faster.lightningCssMinimizer" must be a boolean + " + `); + }); + + it('rejects - number', () => { + // @ts-expect-error: invalid + const faster: Partial = {lightningCssMinimizer: 42}; + expect(() => + normalizeConfig({ + future: { + experimental_faster: faster, + }, + }), + ).toThrowErrorMatchingInlineSnapshot(` + ""future.experimental_faster.lightningCssMinimizer" must be a boolean + " + `); + }); + }); + describe('mdxCrossCompilerCache', () => { it('accepts - undefined', () => { const faster: Partial = { diff --git a/packages/docusaurus/src/server/configValidation.ts b/packages/docusaurus/src/server/configValidation.ts index ca5e6c7a1da2..e81c54034cd7 100644 --- a/packages/docusaurus/src/server/configValidation.ts +++ b/packages/docusaurus/src/server/configValidation.ts @@ -44,6 +44,7 @@ export const DEFAULT_STORAGE_CONFIG: StorageConfig = { export const DEFAULT_FASTER_CONFIG: FasterConfig = { swcJsLoader: false, swcJsMinimizer: false, + lightningCssMinimizer: false, mdxCrossCompilerCache: false, rspackBundler: false, }; @@ -52,6 +53,7 @@ export const DEFAULT_FASTER_CONFIG: FasterConfig = { export const DEFAULT_FASTER_CONFIG_TRUE: FasterConfig = { swcJsLoader: true, swcJsMinimizer: true, + lightningCssMinimizer: true, mdxCrossCompilerCache: true, rspackBundler: true, }; @@ -221,6 +223,9 @@ const FASTER_CONFIG_SCHEMA = Joi.alternatives() swcJsMinimizer: Joi.boolean().default( DEFAULT_FASTER_CONFIG.swcJsMinimizer, ), + lightningCssMinimizer: Joi.boolean().default( + DEFAULT_FASTER_CONFIG.lightningCssMinimizer, + ), mdxCrossCompilerCache: Joi.boolean().default( DEFAULT_FASTER_CONFIG.mdxCrossCompilerCache, ), From c61ca5b078933b73072bf5450bc084993e8de50b Mon Sep 17 00:00:00 2001 From: sebastien Date: Thu, 26 Sep 2024 18:30:12 +0200 Subject: [PATCH 3/8] Update snapshots --- .../server/__tests__/__snapshots__/config.test.ts.snap | 10 ++++++++++ .../server/__tests__/__snapshots__/site.test.ts.snap | 1 + 2 files changed, 11 insertions(+) diff --git a/packages/docusaurus/src/server/__tests__/__snapshots__/config.test.ts.snap b/packages/docusaurus/src/server/__tests__/__snapshots__/config.test.ts.snap index af9b1a67560e..ffceecd12de3 100644 --- a/packages/docusaurus/src/server/__tests__/__snapshots__/config.test.ts.snap +++ b/packages/docusaurus/src/server/__tests__/__snapshots__/config.test.ts.snap @@ -9,6 +9,7 @@ exports[`loadSiteConfig website with .cjs siteConfig 1`] = ` "customFields": {}, "future": { "experimental_faster": { + "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, "rspackBundler": false, "swcJsLoader": false, @@ -76,6 +77,7 @@ exports[`loadSiteConfig website with ts + js config 1`] = ` "customFields": {}, "future": { "experimental_faster": { + "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, "rspackBundler": false, "swcJsLoader": false, @@ -143,6 +145,7 @@ exports[`loadSiteConfig website with valid JS CJS config 1`] = ` "customFields": {}, "future": { "experimental_faster": { + "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, "rspackBundler": false, "swcJsLoader": false, @@ -210,6 +213,7 @@ exports[`loadSiteConfig website with valid JS ESM config 1`] = ` "customFields": {}, "future": { "experimental_faster": { + "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, "rspackBundler": false, "swcJsLoader": false, @@ -277,6 +281,7 @@ exports[`loadSiteConfig website with valid TypeScript CJS config 1`] = ` "customFields": {}, "future": { "experimental_faster": { + "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, "rspackBundler": false, "swcJsLoader": false, @@ -344,6 +349,7 @@ exports[`loadSiteConfig website with valid TypeScript ESM config 1`] = ` "customFields": {}, "future": { "experimental_faster": { + "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, "rspackBundler": false, "swcJsLoader": false, @@ -411,6 +417,7 @@ exports[`loadSiteConfig website with valid async config 1`] = ` "customFields": {}, "future": { "experimental_faster": { + "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, "rspackBundler": false, "swcJsLoader": false, @@ -480,6 +487,7 @@ exports[`loadSiteConfig website with valid async config creator function 1`] = ` "customFields": {}, "future": { "experimental_faster": { + "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, "rspackBundler": false, "swcJsLoader": false, @@ -549,6 +557,7 @@ exports[`loadSiteConfig website with valid config creator function 1`] = ` "customFields": {}, "future": { "experimental_faster": { + "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, "rspackBundler": false, "swcJsLoader": false, @@ -621,6 +630,7 @@ exports[`loadSiteConfig website with valid siteConfig 1`] = ` "favicon": "img/docusaurus.ico", "future": { "experimental_faster": { + "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, "rspackBundler": false, "swcJsLoader": false, diff --git a/packages/docusaurus/src/server/__tests__/__snapshots__/site.test.ts.snap b/packages/docusaurus/src/server/__tests__/__snapshots__/site.test.ts.snap index 2c61404bd204..3bc788d98fa3 100644 --- a/packages/docusaurus/src/server/__tests__/__snapshots__/site.test.ts.snap +++ b/packages/docusaurus/src/server/__tests__/__snapshots__/site.test.ts.snap @@ -83,6 +83,7 @@ exports[`load loads props for site with custom i18n path 1`] = ` "customFields": {}, "future": { "experimental_faster": { + "lightningCssMinimizer": false, "mdxCrossCompilerCache": false, "rspackBundler": false, "swcJsLoader": false, From 078731c5f90d7e391795df5ef4e459a2655395dd Mon Sep 17 00:00:00 2001 From: slorber Date: Thu, 26 Sep 2024 16:43:28 +0000 Subject: [PATCH 4/8] refactor: apply lint autofix --- project-words.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/project-words.txt b/project-words.txt index 522989634d7c..5c6c2590ef80 100644 --- a/project-words.txt +++ b/project-words.txt @@ -164,6 +164,7 @@ lastmod Lastmod lifecycles Lifecycles +lightningcss linkify Linkify Localizable From a365098f4b7d5d5b913cbcf55720b8db3a0976de Mon Sep 17 00:00:00 2001 From: sebastien Date: Thu, 26 Sep 2024 18:46:55 +0200 Subject: [PATCH 5/8] empty From 9cbde1151272925f7d155111b3fcbff12d27bdb9 Mon Sep 17 00:00:00 2001 From: sebastien Date: Fri, 27 Sep 2024 11:59:03 +0200 Subject: [PATCH 6/8] createLighthouseReport add log of input args --- admin/scripts/formatLighthouseReport.js | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/admin/scripts/formatLighthouseReport.js b/admin/scripts/formatLighthouseReport.js index 0b1343bc4f56..8a1c6a706ed3 100644 --- a/admin/scripts/formatLighthouseReport.js +++ b/admin/scripts/formatLighthouseReport.js @@ -64,7 +64,8 @@ const createMarkdownTableHeader = () => [ * @param {Record} param0.links * @param {{url: string, summary: LighthouseSummary}[]} param0.results */ -const createLighthouseReport = ({results, links}) => { +export default function createLighthouseReport({results, links}) { + console.log('createLighthouseReport', {results, links}); const tableHeader = createMarkdownTableHeader(); const tableBody = results.map((result) => { const testUrl = /** @type {string} */ ( @@ -86,6 +87,4 @@ const createLighthouseReport = ({results, links}) => { '', ]; return comment.join('\n'); -}; - -export default createLighthouseReport; +} From 6db3420e6a75c2d79c9c9361ceb926c98f1a2b05 Mon Sep 17 00:00:00 2001 From: sebastien Date: Fri, 27 Sep 2024 11:59:35 +0200 Subject: [PATCH 7/8] fix harmless CSS order change for LightningCSS --- website/testCSSOrder.mjs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/testCSSOrder.mjs b/website/testCSSOrder.mjs index fbb3bf2fc27a..15fbc1c4f758 100644 --- a/website/testCSSOrder.mjs +++ b/website/testCSSOrder.mjs @@ -29,11 +29,11 @@ const EXPECTED_CSS_MARKERS = [ // Note, Infima and site classes are optimized/deduplicated and put at the top // We don't agree yet on what should be the order for those classes // See https://github.com/facebook/docusaurus/pull/6222 - '.markdown>h2', - '.button--outline.button--active', '--ifm-color-scheme:light', '.col[class*=col--]', '.padding-vert--xl', + '.markdown>h2', + '.button--outline.button--active', '.footer__link-item', '.navbar__title', '.pagination__item', From 9724ec150ef66ef69dfdc12201e54bb27ab3a233 Mon Sep 17 00:00:00 2001 From: sebastien Date: Fri, 27 Sep 2024 13:20:34 +0200 Subject: [PATCH 8/8] Revert "createLighthouseReport add log of input args" This reverts commit 9cbde1151272925f7d155111b3fcbff12d27bdb9. --- admin/scripts/formatLighthouseReport.js | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/admin/scripts/formatLighthouseReport.js b/admin/scripts/formatLighthouseReport.js index 8a1c6a706ed3..0b1343bc4f56 100644 --- a/admin/scripts/formatLighthouseReport.js +++ b/admin/scripts/formatLighthouseReport.js @@ -64,8 +64,7 @@ const createMarkdownTableHeader = () => [ * @param {Record} param0.links * @param {{url: string, summary: LighthouseSummary}[]} param0.results */ -export default function createLighthouseReport({results, links}) { - console.log('createLighthouseReport', {results, links}); +const createLighthouseReport = ({results, links}) => { const tableHeader = createMarkdownTableHeader(); const tableBody = results.map((result) => { const testUrl = /** @type {string} */ ( @@ -87,4 +86,6 @@ export default function createLighthouseReport({results, links}) { '', ]; return comment.join('\n'); -} +}; + +export default createLighthouseReport;