Skip to content

Commit 21eb499

Browse files
committed
some documentation of loaders
1 parent e133dbd commit 21eb499

1 file changed

Lines changed: 50 additions & 5 deletions

File tree

‎README.md‎

Lines changed: 50 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@ Somethings it happens that browsers require other code than node.js do.
105105
`webpack` allow module developers to specify replacements which are used in the compile process of `webpack`.
106106

107107
Modules in `web_modules` replace modules in `node_modules`.
108-
`filename.web.js` replaces `filename.js` when required without file extention.
108+
`filename.web.js` replaces `filename.js` when required without file extension.
109109

110110
in options: `alias: { "http": "http-browserify" }`
111111

@@ -490,7 +490,7 @@ else `stats` as json see [example](modules-webpack/tree/master/examples/code-spl
490490
require JSON
491491
</td>
492492
<td>
493-
no
493+
yes (NEW)
494494
</td>
495495
<td>
496496
no
@@ -517,14 +517,29 @@ else `stats` as json see [example](modules-webpack/tree/master/examples/code-spl
517517

518518
<tr>
519519
<td>
520-
compile coffee script
520+
loaders
521+
</td>
522+
<td>
523+
yes (NEW)
521524
</td>
522525
<td>
523526
no
524527
</td>
525528
<td>
526529
no
527530
</td>
531+
</tr>
532+
533+
<tr>
534+
<td>
535+
compile coffee script
536+
</td>
537+
<td>
538+
yes (NEW)
539+
</td>
540+
<td>
541+
no
542+
</td>
528543
<td>
529544
yes
530545
</td>
@@ -606,6 +621,38 @@ else `stats` as json see [example](modules-webpack/tree/master/examples/code-spl
606621
</tr>
607622
</table>
608623

624+
## Loaders
625+
626+
You can use a syntax for loader plugins to preprocess files before emitting javascript code to the bundle.
627+
628+
The following example loads the raw content of a file with the `raw` loader:
629+
630+
``` javascript
631+
var content = require("raw!./file.txt");
632+
```
633+
634+
Multiple loader plugins can be prepended by seperating them with `!`.
635+
The loader plugins are resolved like in normal `require` call but with different default extension.
636+
637+
The `raw` loader plugin is looked up at modules `raw-webpack-web-loader`, `raw-webpack-loader`, `raw-web-loader`, `raw-loader`, `raw`
638+
and the following files are looked up: `index.webpack-web-loader.js`, `index.webpack-loader.js`, `index.web-loader.js`, `index.loader.js`, `index`, `index.js`.
639+
Note that the `web-` versions are omitted if loaders are used in node.js.
640+
641+
See [example](modules-webpack/tree/master/examples/loader).
642+
643+
The following loaders are included as optional dependencies:
644+
645+
* `raw`: Loads raw content of a file
646+
* `json` (default at `.json`): Loads file as JSON
647+
* `jade` (default at `.jade`): Loads jade template and returns a function
648+
* `coffee` (default at `.coffee`): Loads coffee-script like javascript
649+
650+
TODO
651+
652+
* `css`: CSS rules are added to DOM on require
653+
* `less`, `sass`: like `css` but compiles
654+
655+
609656
## Tests
610657

611658
You can run the unit tests with `npm test`.
@@ -619,8 +666,6 @@ node build
619666

620667
and open `test.html` in browser. There must be several OKs in the file and no FAIL.
621668

622-
TODO more tests
623-
624669
## Contribution
625670

626671
You are welcome to contribute by writing issues or pull requests.

0 commit comments

Comments
 (0)