-
-
Notifications
You must be signed in to change notification settings - Fork 3.3k
feat(loaderapi): create initial loader api #364
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
Conversation
|
||
## The loader context | ||
|
||
The loader context represents the properties that are available inside of a loader assigned to the `this` property |
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.
End with a dot ;). This also happens in a few other sentences btw.
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.
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. |
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.
s/The this/The this
/
(I didn't know at first if you were talking about the JS this
or real-life this 😄)
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.
s/String/String
/
s/Buffer/Buffer
/
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.
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. |
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.
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.
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.
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. |
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.
(saying as a user) what does this mean? aren't all loaders compiled by webpack?
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.
Loader runner is a separate module so could be used externally. I should mark that.
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.
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, |
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.
s/require()/require()
/ for consistency (same thing for line below this)
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.
done
Nice work @TheLarkInn!! |
…ype information more colorful
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.
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 |
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.
Small error with the backticks here, sorry for nitpicking haha.
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.
No problem it's a good catch!!
Oh what the crawling assets about? |
I think it has to do with an invalid link. Unfortunately it shows no information to narrow it down at all... |
@bebraw do you know what these errors might pertain to? @SpaceK33z and I both had passing builds locally for lint:links |
Fix links
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. |
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.
@SpaceK33z @bebraw looks like it was the /api/plugins link. Fixed!!!!!! Going to merge! |
Fixes #21 |
No description provided.