You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+64-40Lines changed: 64 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -151,6 +151,69 @@ There is a warning emitted in this case.
151
151
152
152
*Warning: The complete code in the directory are included. So use it carefully.*
153
153
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
// 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
+
154
217
## Limitations
155
218
156
219
### `require`-function
@@ -183,7 +246,7 @@ Here is a list of possible useful replacements:
183
246
184
247
*`http=http-browserify`
185
248
*`vm=vm-browserify`
186
-
*
249
+
*
187
250
* TODO provide some more replacements
188
251
189
252
## Usage
@@ -621,37 +684,6 @@ else `stats` as json see [example](modules-webpack/tree/master/examples/code-spl
621
684
</tr>
622
685
</table>
623
686
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
687
656
688
## Tests
657
689
@@ -674,14 +706,6 @@ You are also welcome to correct any spelling mistakes or any language issues, be
674
706
675
707
## Future plans
676
708
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) */)`
685
709
* more polyfills for node.js buildin modules, but optional
0 commit comments