Skip to content
Merged
Changes from 4 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
17 changes: 12 additions & 5 deletions src/content/guides/asset-management.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ contributors:
- astonizer
- snitin315
- Brennvo
- mr-baraiya
---

If you've been following the guides from the start, you will now have a small project that shows "Hello webpack". Now let's try to incorporate some other assets, like images, to see how they can be handled.
Expand Down Expand Up @@ -95,15 +96,21 @@ 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.
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.
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.
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.
For example:

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'],
```

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.
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 `postcss-loader` appears before `sass-loader` in the array, the execution happens in reverse order.

Let's try it out by adding a new `style.css` file to our project and import it in our `index.js`:
If this order is not maintained, webpack may throw errors.

**project**

Expand Down
Loading