diff --git a/packages/docusaurus/package.json b/packages/docusaurus/package.json index 89456c111214..72bdb1e9376b 100644 --- a/packages/docusaurus/package.json +++ b/packages/docusaurus/package.json @@ -77,6 +77,7 @@ "leven": "^3.1.0", "lodash": "^4.17.21", "mini-css-extract-plugin": "^2.7.6", + "null-loader": "^4.0.1", "p-map": "^4.0.0", "postcss": "^8.4.26", "postcss-loader": "^7.3.3", diff --git a/packages/docusaurus/src/webpack/utils.ts b/packages/docusaurus/src/webpack/utils.ts index aa03e7eda82d..a77984832b38 100644 --- a/packages/docusaurus/src/webpack/utils.ts +++ b/packages/docusaurus/src/webpack/utils.ts @@ -55,6 +55,8 @@ export function getStyleLoaders( ...cssOptionsArg, }; + // On the server we don't really need to extract/emit CSS + // We only need to transform CSS module imports to a styles object if (isServer) { return cssOptions.modules ? [ @@ -63,20 +65,8 @@ export function getStyleLoaders( options: cssOptions, }, ] - : [ - { - loader: MiniCssExtractPlugin.loader, - options: { - // Don't emit CSS files for SSR (previously used null-loader) - // See https://github.com/webpack-contrib/mini-css-extract-plugin/issues/90#issuecomment-811991738 - emit: false, - }, - }, - { - loader: require.resolve('css-loader'), - options: cssOptions, - }, - ]; + : // Ignore regular CSS files + [{loader: require.resolve('null-loader')}]; } return [ @@ -90,6 +80,12 @@ export function getStyleLoaders( loader: require.resolve('css-loader'), options: cssOptions, }, + + // TODO apart for configurePostCss(), do we really need this loader? + // Note: using postcss here looks inefficient/duplicate + // But in practice, it's not a big deal because css-loader also uses postcss + // and is able to reuse the parsed AST from postcss-loader + // See https://github.com/webpack-contrib/css-loader/blob/master/src/index.js#L159 { // Options for PostCSS as we reference these options twice // Adds vendor prefixing based on your specified browser support in diff --git a/yarn.lock b/yarn.lock index 50b9cf15aac4..f77a98de154a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -12688,6 +12688,14 @@ nth-check@^2.0.1: dependencies: boolbase "^1.0.0" +null-loader@^4.0.1: + version "4.0.1" + resolved "https://registry.yarnpkg.com/null-loader/-/null-loader-4.0.1.tgz#8e63bd3a2dd3c64236a4679428632edd0a6dbc6a" + integrity sha512-pxqVbi4U6N26lq+LmgIbB5XATP0VdZKOG25DhHi8btMmJJefGArFyDg1yc4U3hWCJbMqSrw0qyrz1UQX+qYXqg== + dependencies: + loader-utils "^2.0.0" + schema-utils "^3.0.0" + nwsapi@^2.2.2: version "2.2.7" resolved "https://registry.yarnpkg.com/nwsapi/-/nwsapi-2.2.7.tgz#738e0707d3128cb750dddcfe90e4610482df0f30"