-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
docs: clarify webpack loader execution order (right-to-left) #8136
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
Changes from 3 commits
bef3407
d128213
b19136c
df6994c
33d38e4
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -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. | ||||||
|
|
@@ -95,15 +96,19 @@ npm install --save-dev style-loader css-loader | |||||
| }; | ||||||
| ``` | ||||||
|
|
||||||
| 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). | ||||||
|
|
||||||
|
||||||
| 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"]; | ||||||
|
||||||
| use: ["postcss-loader", "sass-loader"]; | |
| use: ['postcss-loader', 'sass-loader'], |
There was a problem hiding this comment.
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$/iin the config diff, but the explanatory sentence abouttestbeing a regex that selects which files the rule applies to was removed. Consider reintroducing a short explanation (e.g., that this rule targets.cssfiles) so the example is self-contained for readers unfamiliar with webpack’smodule.rulesformat.