Skip to content

Added loader chaining and resolveLoader examples. #1529

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

Merged
merged 8 commits into from
Aug 23, 2017

Conversation

asulaiman
Copy link
Contributor

@asulaiman asulaiman commented Aug 17, 2017

Based on feedback from most users on the old docs (https://webpack.github.io/docs/how-to-write-a-loader.html), ive tried add some clarification over the usage of custom loaders.

Copy link
Collaborator

@skipjack skipjack left a comment

Choose a reason for hiding this comment

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

Thanks for your contribution @asulaiman! Please see my comments -- mostly regarding formatting -- so we can get this merged.

@@ -1,5 +1,7 @@
---
title: How to write a loader?
contributors:
Copy link
Collaborator

Choose a reason for hiding this comment

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

Minor nitpick: can you move the the contributors under sort? It's nice to see the sort order and title easily

@@ -17,6 +19,28 @@ The loader is expected to give back one or two values. The first value is a resu

In the complex case, when multiple loaders are chained, only the last loader gets the resource file and only the first loader is expected to give back one or two values (JavaScript and SourceMap). Values that any other loader give back are passed to the previous loader.

In other words the loading order for chained loaders goes from right to left or bottom to top.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Drop the single line break between here and the next line, it won't change the display at all. Also, you may want to put "or bottom to top" in parentheses as it's essentially the same behavior. Or even better, maybe just rewrite as:

In other words, chained loaders are executed in reverse order -- either right to left or bottom to top depending on the format of your array.

@@ -17,6 +19,28 @@ The loader is expected to give back one or two values. The first value is a resu

In the complex case, when multiple loaders are chained, only the last loader gets the resource file and only the first loader is expected to give back one or two values (JavaScript and SourceMap). Values that any other loader give back are passed to the previous loader.

In other words the loading order for chained loaders goes from right to left or bottom to top.
For example: lets say you have two loaders that go by the name of `fooLoader` and `barLoader`. You would like to execute `fooLoader` and then pass the result of the transformation from `fooLoader` finally to `barLoader`.
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you can drop the "For example:" and just lead off with "Let's say".

Copy link
Collaborator

Choose a reason for hiding this comment

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

You should also probably use foo-loader / bar-loader vs. camel case seeing as that's how most loaders are packaged/named.

use: [{ loader: 'barLoader' }, { loader: 'fooLoader' }]
]
}
```
Copy link
Collaborator

Choose a reason for hiding this comment

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

The formatting is off here -- it should be two spaces within markdown files. Can you double check to make sure your editor is listening to the .editorconfig file?

Copy link
Collaborator

Choose a reason for hiding this comment

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

Also, I think you're missing a closing bracket on the top-level rule. Here's a simplified version with improved formatting:

module: {
  rules: [
    {
      test: /\.js/,
      use: [
        'bar-loader',
        'foo-loader'
      ]
    }
  ]
}


``` javascript
resolveLoader: {
modules: ['node_modules', path_resolve(__dirname, 'loaders')
Copy link
Collaborator

Choose a reason for hiding this comment

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

Should be indented two spaces (one tab if your editor is listening to the .editorconfig).

modules: ['node_modules', path_resolve(__dirname, 'loaders')
}
```

Copy link
Collaborator

Choose a reason for hiding this comment

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

Add another line break between sections.

@asulaiman
Copy link
Contributor Author

@skipjack thanks for reviewing! Ive adjusted based on your comments, didnt realize that we were supposed to follow formatting conventions for JS in the docs as well. Maybe that should also be a part of the contributing doc.

Add trailing bracket and update formatting in `resolveLoader` example.
Copy link
Collaborator

@skipjack skipjack left a comment

Choose a reason for hiding this comment

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

@asulaiman great thanks! Fixed one other configuration issue and now we should be good to go.

@skipjack
Copy link
Collaborator

Maybe that should also be a part of the contributing doc.

Sure, we can add that. Ideally it should just happen automatically via the .editorconfig but it doesn't hurt to note it.

@jsf-clabot
Copy link

jsf-clabot commented Aug 23, 2017

CLA assistant check
All committers have signed the CLA.

@asulaiman
Copy link
Contributor Author

asulaiman commented Aug 23, 2017

@skipjack resolved some conflicts with master today. If alls good here, could we have this merged?

@skipjack skipjack merged commit bdde876 into webpack:master Aug 23, 2017
@skipjack
Copy link
Collaborator

@asulaiman yessir -- thanks for resolving the conflicts, made my life a little easier!

@asulaiman asulaiman deleted the patch-1 branch April 15, 2019 21:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants