Skip to content

Commit

Permalink
refactor(core): Restore null-loader (#10448)
Browse files Browse the repository at this point in the history
  • Loading branch information
slorber committed Aug 26, 2024
1 parent c0b86f4 commit 08da5c2
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 14 deletions.
1 change: 1 addition & 0 deletions packages/docusaurus/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
24 changes: 10 additions & 14 deletions packages/docusaurus/src/webpack/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
? [
Expand All @@ -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 [
Expand All @@ -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
Expand Down
8 changes: 8 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 08da5c2

Please sign in to comment.