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
+31-15Lines changed: 31 additions & 15 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,20 +1,27 @@
1
1
# modules-webpack
2
2
3
3
As developer you want to reuse existing code.
4
-
As with node.js and web all file are already in the same language, but it is extra work to use your code with the node.js module system and the browser.
4
+
As with node.js and web all files are already in the same language, but it is extra work to use your code with the node.js module system and the browser.
5
5
6
6
The goal of `webpack` is to bundle CommonJs modules into javascript files which can be loaded by `<script>`-tags.
7
7
Simply concating all required files has a disadvantage: many code to download (and execute) on page load.
8
8
Therefore `webpack` uses the `require.ensure` function ([CommonJs/Modules/Async/A](http://wiki.commonjs.org/wiki/Modules/Async/A)) to split your code automatically into multiple bundles which are loaded on demand.
9
-
This happens mostly transparent to the developer with a single function call. Dependencies are resolved for you.
9
+
This happens mostly transparent to the developer.
10
+
Dependencies are resolved for you.
10
11
The result is a smaller inital code download which results in faster page load.
11
12
13
+
Another common thing in web development is that some files have to be preprocessed before send to the client (ex. template files).
14
+
This introduce more complexity to the compile step.
15
+
`webpack` supports loaders which process files before including them.
16
+
You as developer can use such files like any other module.
17
+
12
18
**TL;DR**
13
19
14
20
* bundle CommonJs modules for browser
15
21
* reuse server-side code (node.js) on client-side
16
22
* create multiple files which are loaded on demand (faster page load in big webapps or on mobile connections)
17
23
* dependencies managed for you, on compile time (no resolution on runtime needed)
If the required module is not known while compile time we get into a problem.
124
131
A solution is the method `require.context` which takes a directory as parameter
@@ -177,15 +184,16 @@ Note that the `web-` versions are omitted if loaders are used in node.js.
177
184
178
185
See [example](/sokra/modules-webpack/tree/master/examples/loader).
179
186
180
-
The following loaders are included as optional dependencies:
187
+
The following loaders are included in webpack:
181
188
182
-
*`raw`: Loads raw content of a file
189
+
*`raw`: Loads raw content of a file (as utf-8)
183
190
*`json` (default at `.json`): Loads file as JSON
184
191
*`jade` (default at `.jade`): Loads jade template and returns a function
185
192
*`coffee` (default at `.coffee`): Loads coffee-script like javascript
186
-
*`css`: Loads css file with resolved imports
193
+
*`css`: Loads css file with resolved imports and returns css code
187
194
*`style`: Adds result of javascript execution to DOM
188
-
*`.css` defaults to `style!css` loader, so all css rules are added to DOM
195
+
* (`.css` defaults to `style!css` loader, so all css rules are added to DOM)
196
+
*`script`: Executes a javascript file once in global context (like in script tag), requires are not parsed. Use this to include a libary. ex. `require("script!./jquery.min.js")`. This is synchron, so the `$` variable is avalible after require.
189
197
190
198
TODO
191
199
@@ -260,7 +268,7 @@ Included simple replacements:
260
268
*`child_process`: disabled
261
269
*`events`: copy of node.js' version
262
270
*`path`: copy of node.js' version
263
-
*`punycode`: copy of node.js' version, one line removed
271
+
*`punycode`: copy of node.js' version, one line removed (http://mths.be/punycode by @mathias)
264
272
*`querystring`: copy of node.js' version
265
273
*`string_decoder`: copy of node.js' version
266
274
*`url`: copy of node.js' version
@@ -294,7 +302,10 @@ Options:
294
302
--libary Stores the exports into this variable [string]
295
303
--colors Output Stats with colors [boolean] [default: false]
296
304
--json Output Stats as JSON [boolean] [default: false]
305
+
--by-size Sort modules by size in Stats [boolean] [default: false]
306
+
--verbose Output dependencies in Stats [boolean] [default: false]
297
307
--alias Set a alias name for a module. ex. http=http-browserify [string]
308
+
--debug Prints debug info to output files [boolean] [default: false]
298
309
```
299
310
300
311
### Programmatically Usage
@@ -336,6 +347,10 @@ exports of input file are stored in this variable
336
347
337
348
minimize outputs with uglify-js
338
349
350
+
`debug`
351
+
352
+
prints debug info to output files.
353
+
339
354
`includeFilenames`
340
355
341
356
add absolute filenames of input files as comments
@@ -500,13 +515,13 @@ else `stats` as json see [example](/sokra/modules-webpack/tree/master/examples/c
500
515
<code>require("http");</code>
501
516
</td>
502
517
<td>
503
-
some optional
518
+
yes
504
519
</td>
505
520
<td>
506
521
no
507
522
</td>
508
523
<td>
509
-
many by default
524
+
yes
510
525
</td>
511
526
</tr>
512
527
@@ -695,7 +710,7 @@ else `stats` as json see [example](/sokra/modules-webpack/tree/master/examples/c
695
710
debug mode
696
711
</td>
697
712
<td>
698
-
no
713
+
yes
699
714
</td>
700
715
<td>
701
716
no
@@ -763,7 +778,7 @@ cd test/browsertests
763
778
node build
764
779
```
765
780
766
-
and open `test.html` in browser. There must be several OKs in the fileand no FAIL.
781
+
and open `test.html` in browser. There must be several OKs in the file, no FAIL and no RED boxes.
767
782
768
783
## Contribution
769
784
@@ -773,9 +788,10 @@ You are also welcome to correct any spelling mistakes or any language issues, be
773
788
774
789
## Future plans
775
790
791
+
* watch mode
792
+
* append hash of file to filename, for better caching
776
793
* more polyfills for node.js buildin modules, but optional
0 commit comments