Skip to content

docs: clarify webpack loader execution order (right-to-left)#8136

Merged
alexander-akait merged 5 commits intowebpack:mainfrom
mr-baraiya:fix/loader-order-docs
Apr 17, 2026
Merged

docs: clarify webpack loader execution order (right-to-left)#8136
alexander-akait merged 5 commits intowebpack:mainfrom
mr-baraiya:fix/loader-order-docs

Conversation

@mr-baraiya
Copy link
Copy Markdown
Contributor

Summary

Fixes a misleading explanation in asset-management.mdx regarding loader execution order. Clarifies that webpack applies loaders from right to left, so css-loader runs before style-loader.


What kind of change does this PR introduce?

docs


Did you add tests for your changes?

No (documentation change only)


Does this PR introduce a breaking change?

No


Use of AI

No

@vercel
Copy link
Copy Markdown

vercel bot commented Mar 29, 2026

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Actions Updated (UTC)
webpack-js-org Ready Ready Preview, Comment Apr 16, 2026 4:20pm

Request Review

Comment thread src/content/guides/asset-management.mdx Outdated
Module loaders can be chained. Each loader in the chain applies transformations to the processed resource. A chain is executed in reverse order. The first loader passes its result (resource with applied transformations) to the next one, and so forth. Finally, webpack expects JavaScript to be returned by the last loader in the chain.

The above order of loaders should be maintained: [`'style-loader'`](/loaders/style-loader) comes first and followed by [`'css-loader'`](/loaders/css-loader). If this convention is not followed, webpack is likely to throw errors.
The above order of loaders should be maintained: [`'style-loader'`](/loaders/style-loader) should be listed before [`'css-loader'`](/loaders/css-loader) in the `use` array, but webpack applies them from right to left—so `'css-loader'` runs first, then `'style-loader'`. If this convention is not followed, webpack is likely to throw errors.
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

To be honestly and before and now is misleading, I think we should rewrite it...

@mr-baraiya
Copy link
Copy Markdown
Contributor Author

Rewrote this part to make the execution order clear and removed the confusing wording. Let me know if this works 👍

@mr-baraiya
Copy link
Copy Markdown
Contributor Author

Hi @alexander-akait, just checking if the latest rewrite looks good to you.
Happy to make further improvements if needed. Thanks!

Comment thread src/content/guides/asset-management.mdx Outdated

T> webpack uses a regular expression to determine which files it should look for and serve to a specific loader. In this case, any file that ends with `.css` will be served to the `style-loader` and the `css-loader`.
```js
use: ["style-loader", "css-loader"];
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's use other loaders than style-loader and css-loader, they will be deprecated soon in favor of experiments.css, you can use postcss-loader and sass-loader/less-loader for this example

Copilot AI review requested due to automatic review settings April 16, 2026 14:35
@mr-baraiya mr-baraiya force-pushed the fix/loader-order-docs branch from 5723f45 to d128213 Compare April 16, 2026 14:35
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Updates the Asset Management guide to correct the explanation of webpack loader execution order, clarifying that loaders run from right to left in a use array.

Changes:

  • Adds a new contributor entry.
  • Rewrites the loader-chaining explanation to emphasize right-to-left execution order and adds an illustrative example.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/content/guides/asset-management.mdx Outdated
Comment on lines +103 to +109
```js
use: ["postcss-loader", "sass-loader"];
```

Here, `css-loader` runs first and processes the CSS, followed by `style-loader`, which injects the result into the DOM.

This enables you to `import './style.css'` into the file that depends on that styling. Now, when that module is run, a `<style>` tag with the stringified css will be inserted into the `<head>` of your html file.
So even though `style-loader` appears before `css-loader` in the array, the execution happens in reverse order.
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example use: ["postcss-loader", "sass-loader"] doesn’t match the explanation below it: the text talks about css-loader/style-loader and DOM injection, but those loaders are not in the example array. This makes the execution-order clarification incorrect/confusing (with the current example, sass-loader would run before postcss-loader). Consider either switching the example to the ['style-loader', 'css-loader'] chain shown above, or updating the explanation to describe sass-loader -> postcss-loader correctly.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/content/guides/asset-management.mdx Outdated

T> webpack uses a regular expression to determine which files it should look for and serve to a specific loader. In this case, any file that ends with `.css` will be served to the `style-loader` and the `css-loader`.
```js
use: ["postcss-loader", "sass-loader"];
Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The new use snippet is not valid in a typical webpack.config.js object literal (; and double-quotes), and it’s inconsistent with the surrounding examples that use single quotes and a trailing comma. Consider changing it to a config-style property (single quotes, trailing comma) so readers can copy/paste it directly.

Suggested change
use: ["postcss-loader", "sass-loader"];
use: ['postcss-loader', 'sass-loader'],

Copilot uses AI. Check for mistakes.
@@ -95,15 +96,19 @@ npm install --save-dev style-loader css-loader
};
```

Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section shows test: /\.css$/i in the config diff, but the explanatory sentence about test being a regex that selects which files the rule applies to was removed. Consider reintroducing a short explanation (e.g., that this rule targets .css files) so the example is self-contained for readers unfamiliar with webpack’s module.rules format.

Suggested change
In this rule, `test: /\.css$/i` is a regular expression that tells webpack to apply the rule to `.css` files.

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 1 out of 1 changed files in this pull request and generated 2 comments.


💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/content/guides/asset-management.mdx Outdated
Comment on lines 103 to 110
```js
use: ['postcss-loader', 'sass-loader'],
```

In this rule, `test: /\.css$/i` is a regular expression that tells webpack to apply the rule to `.css` files.

Here, `sass-loader` runs first and compiles Sass into CSS, followed by `postcss-loader`, which applies further transformations.

Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The example references test: /\.css$/i and describes how the rule applies to .css files, but the shown use: ['postcss-loader', 'sass-loader'] chain typically corresponds to .scss/.sass input (and the snippet omits the test line entirely). Consider either showing the full rule (including test) with a matching extension for sass-loader, or switching the example loaders to ones that apply to .css so the explanation stays internally consistent.

Copilot uses AI. Check for mistakes.
Comment thread src/content/guides/asset-management.mdx Outdated
Comment on lines 99 to 100
Loaders in webpack are executed from **right to left** (i.e., from last to first in the `use` array).

Copy link

Copilot AI Apr 16, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This section explains the general right-to-left execution order, but it no longer explicitly ties that back to the earlier use: ['style-loader', 'css-loader'] example (i.e., that css-loader runs first and style-loader runs last). Adding one short sentence that applies the rule to the preceding config would better resolve the original confusion this PR is addressing.

Copilot uses AI. Check for mistakes.
@mr-baraiya
Copy link
Copy Markdown
Contributor Author

Addressed all suggestions. Please review 🙌

@alexander-akait alexander-akait merged commit 939b0d8 into webpack:main Apr 17, 2026
9 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants