Skip to content

Commit 08da5c2

Browse files
authored
refactor(core): Restore null-loader (#10448)
1 parent c0b86f4 commit 08da5c2

3 files changed

Lines changed: 19 additions & 14 deletions

File tree

packages/docusaurus/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,7 @@
7777
"leven": "^3.1.0",
7878
"lodash": "^4.17.21",
7979
"mini-css-extract-plugin": "^2.7.6",
80+
"null-loader": "^4.0.1",
8081
"p-map": "^4.0.0",
8182
"postcss": "^8.4.26",
8283
"postcss-loader": "^7.3.3",

packages/docusaurus/src/webpack/utils.ts

Lines changed: 10 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ export function getStyleLoaders(
5555
...cssOptionsArg,
5656
};
5757

58+
// On the server we don't really need to extract/emit CSS
59+
// We only need to transform CSS module imports to a styles object
5860
if (isServer) {
5961
return cssOptions.modules
6062
? [
@@ -63,20 +65,8 @@ export function getStyleLoaders(
6365
options: cssOptions,
6466
},
6567
]
66-
: [
67-
{
68-
loader: MiniCssExtractPlugin.loader,
69-
options: {
70-
// Don't emit CSS files for SSR (previously used null-loader)
71-
// See https://github.com/webpack-contrib/mini-css-extract-plugin/issues/90#issuecomment-811991738
72-
emit: false,
73-
},
74-
},
75-
{
76-
loader: require.resolve('css-loader'),
77-
options: cssOptions,
78-
},
79-
];
68+
: // Ignore regular CSS files
69+
[{loader: require.resolve('null-loader')}];
8070
}
8171

8272
return [
@@ -90,6 +80,12 @@ export function getStyleLoaders(
9080
loader: require.resolve('css-loader'),
9181
options: cssOptions,
9282
},
83+
84+
// TODO apart for configurePostCss(), do we really need this loader?
85+
// Note: using postcss here looks inefficient/duplicate
86+
// But in practice, it's not a big deal because css-loader also uses postcss
87+
// and is able to reuse the parsed AST from postcss-loader
88+
// See https://github.com/webpack-contrib/css-loader/blob/master/src/index.js#L159
9389
{
9490
// Options for PostCSS as we reference these options twice
9591
// Adds vendor prefixing based on your specified browser support in

yarn.lock

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12688,6 +12688,14 @@ nth-check@^2.0.1:
1268812688
dependencies:
1268912689
boolbase "^1.0.0"
1269012690

12691+
null-loader@^4.0.1:
12692+
version "4.0.1"
12693+
resolved "https://registry.yarnpkg.com/null-loader/-/null-loader-4.0.1.tgz#8e63bd3a2dd3c64236a4679428632edd0a6dbc6a"
12694+
integrity sha512-pxqVbi4U6N26lq+LmgIbB5XATP0VdZKOG25DhHi8btMmJJefGArFyDg1yc4U3hWCJbMqSrw0qyrz1UQX+qYXqg==
12695+
dependencies:
12696+
loader-utils "^2.0.0"
12697+
schema-utils "^3.0.0"
12698+
1269112699
nwsapi@^2.2.2:
1269212700
version "2.2.7"
1269312701
resolved "https://registry.yarnpkg.com/nwsapi/-/nwsapi-2.2.7.tgz#738e0707d3128cb750dddcfe90e4610482df0f30"

0 commit comments

Comments
 (0)