Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(core): Restore null-loader #10448

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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