@@ -107,14 +107,17 @@ Somethings it happens that browsers require other code than node.js do.
107107Modules in ` web_modules ` replace modules in ` node_modules ` .
108108` filename.web.js ` replaces ` filename.js ` when required without file extention.
109109
110- TODO specify replacements in options
110+ in options: ` alias: { "http": "http-browserify" } `
111+
112+ in shell: ` --alias http=http-browserify `
111113
112114## require.context
113115
114- If the ` require ` d module is not known while compile time we get into a problem.
116+ If the required module is not known while compile time we get into a problem.
115117A solution is the method ` require.context ` which takes a directory as parameter
116118and returns a function which behaves like the ` require ` function issued from a file
117119in this directory (but only if used for files in that directory).
120+ The whole directory is included while compiling, so you have access to all files in it.
118121
119122### Example
120123
@@ -129,20 +132,21 @@ function getTemplate(templateName) {
129132```
130133
131134In addition to that ` webpack ` uses the ` require.context ` function automatically
132- if you use variables or other non-literal things in the ` require ` function.
135+ if you use variables or other not parseable things in the ` require ` function.
133136That means the following code behaves like the above:
134137
135138``` javascript
136139function getTemplate (templateName ) {
137140 return require (" ./templates/" + templateName);
138141}
139142// is compiled like: return require.context("./templates")("./"+templateName)
143+ // which compiles to: return require(123)("./"+templateName)
140144```
141145
142146See [ details] ( modules-webpack/tree/master/examples/require.context ) for complete example.
143147
144148When try to store the ` require ` function in another variable or try to pass it as parameter,
145- ` webpack ` convert it to a ` require.context(".") ` to be combatible .
149+ ` webpack ` convert it to a ` require.context(".") ` to be compatible .
146150There is a warning emitted in this case.
147151
148152* Warning: The complete code in the directory are included. So use it carefully.*
@@ -151,18 +155,17 @@ There is a warning emitted in this case.
151155
152156### ` require ` -function
153157
154- As dependencies are resolved before running:
155-
158+ * ` require ` should not be overwritten
156159* ` require.ensure ` should not be overwritten or called indirect
157160* ` require.context ` should not be overwritten or called indirect
158161* the argument to ` require.context ` should be a literal or addition of multiple literals
159162* An indirect call of ` require ` should access a file in current directory: This throws an exception: ` var r = require; r("../file"); `
160163
161- The following cases could result in too much code in result file if used wrong:
164+ The following cases could result in ** too much code** in result file if used wrong:
162165
163166* indirect call of ` require ` : ` var r = require; r("./file"); `
164167* ` require.context ` . It includes the whole directory.
165- * expressions in require arguments: ` require(variable) ` , webpack is smart enough for this ` require(condition ? "a" : "b") `
168+ * expressions in require arguments: ` require(variable) ` (but ` webpack ` is smart enough for this ` require(condition ? "a" : "b") ` )
166169* the function passed to ` require.ensure ` is not inlined in the call.
167170
168171
@@ -172,15 +175,16 @@ As node.js specific modules like `fs` will not work in browser they are not incl
172175You should replace them by own modules if you want to use them.
173176For some modules are replacements included in ` webpack ` .
174177Some credit goes to the browserify contributors, as I took some replacements from them.
178+ Expensive replacements are not needed by everyone, so that are not included by default.
179+ You need to specify ` --alias [module]=[replacement] ` to use them.
180+ A warning saying that some module is missing is emitted in the case you use it.
175181
176- ```
177- web_modules
178- fs
179- path
180- ...
181- ```
182+ Here is a list of possible useful replacements:
182183
183- TODO provide some replacements (half way done...)
184+ * ` http=http-browserify `
185+ * ` vm=vm-browserify `
186+ *
187+ * TODO provide some more replacements
184188
185189## Usage
186190
@@ -629,7 +633,7 @@ You are also welcome to correct any spelling mistakes or any language issues, be
629633* loader plugins
630634 * ` require("css!./style.css") `
631635 * ` --loader .coffee=coffee-webpack-loader `
632- * default loaders: ` js ` , ` coffee `
636+ * default loaders: ` js ` , ` coffee ` , ` jade ` , ` json `
633637 * optional included loaders: ` css ` , ` less ` , ...
634638 * ` module.resource("ror13!./a.txt"); `
635639 * loader is a exported ` function([content], callback /* function(err, content) */) `
0 commit comments