Skip to content

Commit 04d1c74

Browse files
committed
updates to READMEs
1 parent 9ae768b commit 04d1c74

File tree

2 files changed

+74
-40
lines changed

2 files changed

+74
-40
lines changed

README.md

Lines changed: 64 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -151,6 +151,69 @@ There is a warning emitted in this case.
151151

152152
*Warning: The complete code in the directory are included. So use it carefully.*
153153

154+
## Loaders
155+
156+
You can use a syntax for loader plugins to preprocess files before emitting javascript code to the bundle.
157+
158+
The following example loads the raw content of a file with the `raw` loader:
159+
160+
``` javascript
161+
var content = require("raw!./file.txt");
162+
```
163+
164+
Multiple loader plugins can be prepended by seperating them with `!`.
165+
The loader plugins are resolved like in normal `require` call but with different default extension.
166+
167+
The `raw` loader plugin is looked up at modules `raw-webpack-web-loader`, `raw-webpack-loader`, `raw-web-loader`, `raw-loader`, `raw`
168+
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`.
169+
Note that the `web-` versions are omitted if loaders are used in node.js.
170+
171+
See [example](modules-webpack/tree/master/examples/loader).
172+
173+
The following loaders are included as optional dependencies:
174+
175+
* `raw`: Loads raw content of a file
176+
* `json` (default at `.json`): Loads file as JSON
177+
* `jade` (default at `.jade`): Loads jade template and returns a function
178+
* `coffee` (default at `.coffee`): Loads coffee-script like javascript
179+
180+
TODO
181+
182+
* `css`: CSS rules are added to DOM on require
183+
* `less`, `sass`: like `css` but compiles
184+
185+
## TL;DR
186+
187+
``` javascript
188+
var a = require("a"); // require modules
189+
var b = require("./b"); // and files
190+
// like in node.js
191+
192+
// polyfill require method to use the new members in node.js too
193+
require = require("webpack/require-polyfill")(require.valueOf());
194+
195+
// create a lazy loaded bundle
196+
require.ensure([], function(require) {
197+
var c = require("c");
198+
199+
// require json
200+
var packageJson = require("../package.json");
201+
202+
// or jade templates, coffee-script, and many more with own loaders
203+
var result = require("./template.jade")(require("./dataFrom.coffee"));
204+
205+
// files are compiled to javascript and packed into the bundle...
206+
});
207+
```
208+
209+
... and compile from the shell with:
210+
211+
```
212+
webpack lib/input.js js/output.js
213+
```
214+
215+
try `--min` to minimize with `uglify-js`.
216+
154217
## Limitations
155218

156219
### `require`-function
@@ -183,7 +246,7 @@ Here is a list of possible useful replacements:
183246

184247
* `http=http-browserify`
185248
* `vm=vm-browserify`
186-
*
249+
*
187250
* TODO provide some more replacements
188251

189252
## Usage
@@ -621,37 +684,6 @@ else `stats` as json see [example](modules-webpack/tree/master/examples/code-spl
621684
</tr>
622685
</table>
623686

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-
655687

656688
## Tests
657689

@@ -674,14 +706,6 @@ You are also welcome to correct any spelling mistakes or any language issues, be
674706

675707
## Future plans
676708

677-
* resources `module.resource("./a.txt")`
678-
* loader plugins
679-
* `require("css!./style.css")`
680-
* `--loader .coffee=coffee-webpack-loader`
681-
* default loaders: `js`, `coffee`, `jade`, `json`
682-
* optional included loaders: `css`, `less`, ...
683-
* `module.resource("ror13!./a.txt");`
684-
* loader is a exported `function([content], callback /* function(err, content) */)`
685709
* more polyfills for node.js buildin modules, but optional
686710
* require from protocol `require("http://...")`
687711

examples/loader/README.md

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,16 @@ module.exports = {"foobar":1234}
129129
/******/})
130130
```
131131

132+
# Console output
133+
134+
Prints in node.js (`node example.js`) and in browser:
135+
136+
```
137+
{ answer: 42, foo: 'bar' }
138+
{ foobar: 1234 }
139+
{ foobar: 1234 }
140+
```
141+
132142
# Info
133143

134144
## Uncompressed

0 commit comments

Comments
 (0)