Skip to content

Conversation

TheLarkInn
Copy link
Member

No description provided.


## The loader context

The loader context represents the properties that are available inside of a loader assigned to the `this` property
Copy link
Member

@SpaceK33z SpaceK33z Nov 19, 2016

Choose a reason for hiding this comment

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

End with a dot ;). This also happens in a few other sentences btw.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done


## How to write a loader

A loader is just a file that exports a function. The compiler calls this function and passes the result of the previous loader or the resource file into it. The this context of the function is filled-in by the compiler with some useful methods that allow the loader to, among other things, change its invocation style to async or get query parameters. The first loader is passed one argument: the content of the resource file. The compiler expects a result from the last loader. The result should be a String or a Buffer (which is converted to a string), representing the JavaScript source code of the module. An optional SourceMap result (as JSON object) may also be passed.
Copy link
Member

@SpaceK33z SpaceK33z Nov 19, 2016

Choose a reason for hiding this comment

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

s/The this/The this/
(I didn't know at first if you were talking about the JS this or real-life this 😄)

Copy link
Member

Choose a reason for hiding this comment

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

s/String/String/
s/Buffer/Buffer/

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

Loaders allow you to preprocess files as you require() or “load” them. Loaders are kind of like “tasks” in other build tools,
and provide a powerful way to handle frontend build steps. Loaders can transform files from a different language like, CoffeeScript to JavaScript, or inline images as data URLs. Loaders even allow you to do things like require() css files right in your JavaScript!

To tell webpack to transform a module with a loader, you can specify the loader in the webpack [configuration](../configuration) file (preferred) or in the module request, such as in a `require()` call.
Copy link
Member

Choose a reason for hiding this comment

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

Is there another page that explains how to use a loader in configuration and in a require() call? If so, I'd suggest to link to that.

Copy link
Member Author

Choose a reason for hiding this comment

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

I don't believe those PR's have landed yet. I'll create an issue (after this merges). I'll also add a TODO. Done


### `webpack`

Set to true when this is compiled by webpack.
Copy link
Member

Choose a reason for hiding this comment

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

(saying as a user) what does this mean? aren't all loaders compiled by webpack?

Copy link
Member Author

Choose a reason for hiding this comment

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

Loader runner is a separate module so could be used externally. I should mark that.

Copy link
Member Author

Choose a reason for hiding this comment

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

Done

@@ -3,4 +3,302 @@ title: Loader API
sort: 4
---

> TODO
Loaders allow you to preprocess files as you require() or “load” them. Loaders are kind of like “tasks” in other build tools,
Copy link
Member

@SpaceK33z SpaceK33z Nov 19, 2016

Choose a reason for hiding this comment

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

s/require()/require()/ for consistency (same thing for line below this)

Copy link
Member Author

Choose a reason for hiding this comment

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

done

@SpaceK33z
Copy link
Member

Nice work @TheLarkInn!!

Copy link
Member

@SpaceK33z SpaceK33z left a comment

Choose a reason for hiding this comment

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

Tests seem to be failing, I will save you the hassle to scroll 4000 lines to the bottom in the CI 😄 :

 ✗ Crawling internal assets: should not have any errors loading asset

module.exports = function(content) {
assert(content instanceof Buffer);
return someSyncOperation(content);
// return val`ue can` be a `Buffer` too
Copy link
Member

Choose a reason for hiding this comment

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

Small error with the backticks here, sorry for nitpicking haha.

Copy link
Member Author

Choose a reason for hiding this comment

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

No problem it's a good catch!!

@TheLarkInn
Copy link
Member Author

Oh what the crawling assets about?

@SpaceK33z
Copy link
Member

I think it has to do with an invalid link. Unfortunately it shows no information to narrow it down at all...

@TheLarkInn
Copy link
Member Author

@bebraw do you know what these errors might pertain to? @SpaceK33z and I both had passing builds locally for lint:links

@bebraw
Copy link
Contributor

bebraw commented Nov 19, 2016

No idea. You would have to ask the hyperlink guys to get a better idea of the error. It could be something Node version related etc.

@TheLarkInn
Copy link
Member Author

No worries, Im going to revert the change I just made as it looked like that gave more verbose error.

Revert config links fix (looks like it just breaks more)
Doing some guess work. Trying the plugins api URL this time to fix.
@TheLarkInn
Copy link
Member Author

@SpaceK33z @bebraw looks like it was the /api/plugins link. Fixed!!!!!! Going to merge!

@TheLarkInn TheLarkInn merged commit 3265cc7 into develop Nov 19, 2016
@TheLarkInn TheLarkInn deleted the feature/loader-api branch November 19, 2016 21:32
@TheLarkInn
Copy link
Member Author

Fixes #21

@TheLarkInn TheLarkInn mentioned this pull request Nov 19, 2016
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