Skip to content

Commit 31158a9

Browse files
committed
documentation and small bugfixes
1 parent fb23424 commit 31158a9

10 files changed

Lines changed: 417 additions & 179 deletions

File tree

README.md

Lines changed: 134 additions & 79 deletions
Original file line numberDiff line numberDiff line change
@@ -303,11 +303,10 @@ if invoked without arguments it prints a usage:
303303
Usage: webpack <options> <input> <output>
304304
305305
Options:
306-
--single Disable Code Splitting [boolean] [default: false]
307306
--min Minimize it with uglifyjs [boolean] [default: false]
308307
--filenames Output Filenames Into File [boolean] [default: false]
309308
--options Options JSON File [string]
310-
--script-src-prefix Path Prefix For JavaScript Loading [string]
309+
--public-prefix Path Prefix For JavaScript Loading [string]
311310
--libary Stores the exports into this variable [string]
312311
--colors Output Stats with colors [boolean] [default: false]
313312
--json Output Stats as JSON [boolean] [default: false]
@@ -330,87 +329,143 @@ webpack(absoluteModulePath, [options], callback)
330329

331330
You can also save this options object in a JSON file and use it with the shell command.
332331

333-
`outputJsonpFunction`
334-
335-
JSONP function used to load chunks
336-
337-
`scriptSrcPrefix`
338-
339-
Path from where chunks are loaded
340-
341-
`outputDirectory`
342-
343-
write files to this directory (absolute path)
344-
345-
`output`
346-
347-
write first chunk to this file
348-
349-
`outputPostfix`
350-
351-
write chunks to files named chunkId plus outputPostfix
352-
353-
`libary`
354-
355-
exports of input file are stored in this variable
356-
357-
`minimize`
358-
359-
minimize outputs with uglify-js
360-
361-
`debug`
362-
363-
prints debug info to output files.
364-
365-
`watch`
366-
367-
recompiles on changes (except loaders)
368-
369-
`includeFilenames`
370-
371-
add absolute filenames of input files as comments
372-
373-
`resolve.alias` (object)
374-
375-
replace a module. ex. `{"old-module": "new-module"}`
376-
377-
`resolve.paths` (array)
378-
379-
search paths
380-
381-
`resolve.extensions` (object)
382-
383-
possible extensions for files
384-
385-
default: `["", ".webpack.js", ".web.js", ".js"]`
386-
387-
`resolve.loaders` (array)
388-
389-
extension to loader mappings. ex. `[{test: /\.extension$/, loader: "myloader"}]`
390-
391-
loads files that matches the RegExp to the loader if no other loader set
392-
393-
`resolve.loaderExtensions` (array)
394-
395-
possible extensions for loaders
396-
397-
default: `[".webpack-web-loader.js", ".webpack-loader.js", ".web-loader.js", ".loader.js", "", ".js"]`
398-
399-
`resolve.loaderPostfixes` (array)
400-
401-
possible postfixes for loaders
402-
403-
default: `["-webpack-web-loader", "-webpack-loader", "-web-loader", "-loader", ""]`
404-
405-
`parse.overwrites` (object)
406-
407-
free module variables which are replaced with a module. ex. `{ "$": "jquery" }`
332+
``` javascript
333+
{
334+
output: "out/file.js", // required
335+
// output file to initial chunk
336+
337+
outputDirectory: "out/dir", // default: extract directory from output
338+
// output directory for file
339+
340+
outputPostfix: ".chunk.js", // default: "." + output
341+
// postfix appended to id of lazy loaded chunks
342+
343+
ouputJsonpFunction: "myJsonp", // default: "webpackJsonp"
344+
// jsonp function used for lazy loaded chunks,
345+
// should be unique for all instances of webpack in a page
346+
347+
publicPrefix: "http://static.url.com/asserts/", // default: ""
348+
// path to create the chunks url relative to page
349+
// deprecated name: scriptSrcPrefix
350+
351+
libary: "mylib", // default: null
352+
// store the exports of the entrace module in a variable of this name
353+
// use this to create a libary from webpack
354+
355+
includeFilenames: true, // default: false
356+
// include the filename of each module as comment before the module
357+
358+
watch: true, // default: false
359+
// recompiles on changes on module and contexts (currently not on loaders)
360+
361+
watchDelay: 1000, // default: 200
362+
// delay in ms before recompile after the last file change
363+
364+
events: new EventEmitter(), // default: new EventEmitter()
365+
// EventEmitter on which events for the compile process are fired
366+
// events: "bundle", "module", "context", "task", "task-end"
367+
368+
parse: {
369+
// options for parsing
370+
371+
overwrites: {
372+
"myglobal": "modulename-of-myglobal"
373+
// defaults: (defaults are also included if you define your own)
374+
// process: "__webpack_process",
375+
// module: "__webpack_module",
376+
// console: "__webpack_console",
377+
// global: "__webpack_global",
378+
// Buffer: "buffer+.Buffer" // -> require("buffer").Buffer
379+
// "__dirname": "__webpack_dirname",
380+
// "__filename": "__webpack_filename"
381+
},
382+
// inject a free variable named "myglobal" which are required as
383+
// require("modulename-of-myglobal")
384+
// to each module which uses "myglobal"
385+
}
386+
387+
resolve: {
388+
// options for resolving
389+
390+
paths: ["/my/absolute/dirname"],
391+
// default: (defaults are also included if you define your own)
392+
// [".../buildin",
393+
// ".../buildin/web_modules", ".../buildin/name_modules",
394+
// ".../node_modules"]
395+
// search paths for modules
396+
397+
alias: {
398+
"old-module": "new-module"
399+
},
400+
// replace a module
401+
402+
extensions: ["", ".www.js", ".js"],
403+
// defaults: (defaults are NOT included if you define your own)
404+
// ["", ".webpack.js", ".web.js", ".js"]
405+
// postfixes for files to try
406+
407+
loaderExtensions: [".loader.js", ".www-loader.js", "", ".js"],
408+
// defaults: (defaults are NOT included if you define your own)
409+
// [".webpack-web-loader.js", ".webpack-loader.js",
410+
// ".web-loader.js", ".loader.js", "", ".js"]
411+
// postfixes for loaders to try
412+
413+
loaderPostfixes: ["-loader", "-xyz", ""],
414+
// defaults: (defaults are NOT included if you define your own)
415+
// ["-webpack-web-loader", "-webpack-loader",
416+
// "-web-loader", "-loader", ""]
417+
// postfixes for loader modules to try
418+
419+
loaders: [{test: /\.generator.js/, loader: "val"}],
420+
// default: (defaults are also included if you define your own)
421+
// [{test: /\.coffee$/, loader: "coffee"},
422+
// {test: /\.json$/, loader: "json"},
423+
// {test: /\.jade$/, loader: "jade"},
424+
// {test: /\.css$/, loader: "style!css"},
425+
// {test: /\.less$/, loader: "style!css!val!less"}]
426+
// automatically use loaders if filename match RegExp
427+
// and no loader is specified
428+
}
429+
}
430+
```
408431

409432
#### `callback`
410433

411434
`function(err, source / stats)`
412-
`source` if `options.output` is not set
413-
else `stats` as json see [example](/sokra/modules-webpack/tree/master/examples/code-splitting)
435+
`source` if `options.output` is not set (DEPRECATED)
436+
else `stats` as json:
437+
438+
``` javascript
439+
{
440+
hash: "52bd9213...38d",
441+
chunkCount: 2,
442+
modulesCount: 10,
443+
modulesIncludingDuplicates: 10,
444+
modulesFirstChunk: 3,
445+
fileSizes: {
446+
"output.js": 1234,
447+
"1.output.js": 2345
448+
},
449+
warnings: [ "Some warning" ],
450+
errors: [ "Some error" ],
451+
fileModules: {
452+
"output.js": [
453+
{ id: 0, size: 123, filename: "/home/.../main.js", reasons: [
454+
{ type: "main" }
455+
]},
456+
{ id: 1, size: 234, filename: "...", reasons: [
457+
{ type: "require", // or "context", "async require", "async context"
458+
count: 2,
459+
filename: "/home/.../main.js",
460+
// or dirname: "..." // for type = "context" or "async context"
461+
}
462+
]},
463+
...
464+
],
465+
"1.output.js": [...]
466+
}
467+
}
468+
```
414469

415470
## Bonus features
416471

api/getPublicPrefix.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1 +1,5 @@
1+
/*
2+
MIT License http://www.opensource.org/licenses/mit-license.php
3+
Author Tobias Koppers @sokra
4+
*/
15
module.exports = "require.valueOf().modules.c";

bin/webpack.js

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,6 @@ var sprintf = require("sprintf").sprintf;
1111
var argv = require("optimist")
1212
.usage("Usage: $0 <input> <output>")
1313

14-
.boolean("single")
15-
.describe("single", "Disable Code Splitting")
16-
.default("single", false)
17-
1814
.boolean("min")
1915
.describe("min", "Minimize it with uglifyjs")
2016
.default("min", false)
@@ -26,8 +22,9 @@ var argv = require("optimist")
2622
.string("options")
2723
.describe("options", "Options JSON File")
2824

29-
.string("script-src-prefix")
30-
.describe("script-src-prefix", "Path Prefix For JavaScript Loading")
25+
.string("public-prefix")
26+
.alias("public-prefix", "script-src-prefix")
27+
.describe("public-prefix", "Path Prefix For JavaScript Loading")
3128

3229
.string("libary")
3330
.describe("libary", "Stores the exports into this variable")
@@ -63,7 +60,7 @@ var argv = require("optimist")
6360
.describe("progress", "Displays a progress while compiling")
6461
.default("progress", false)
6562

66-
.demand(1)
63+
.demand(1) // DEPRECATED
6764
.argv;
6865

6966
var input = argv._[0],
@@ -79,11 +76,11 @@ if (output && output[0] !== '/' && input[1] !== ':') {
7976
var options = {};
8077

8178
if(argv.options) {
82-
options = JSON.parse(fs.readFileSync(argv.options, "utf-8"));
79+
options = require(path.join(process.cwd(), argv.options));
8380
}
8481

85-
if(argv["script-src-prefix"]) {
86-
options.scriptSrcPrefix = argv["script-src-prefix"];
82+
if(argv["public-prefix"]) {
83+
options.publicPrefix = argv["public-prefix"];
8784
}
8885

8986
if(argv.min) {
@@ -126,6 +123,7 @@ function c(str) {
126123
}
127124

128125
if(!output) {
126+
// DEPRECATED
129127
webpack(input, options, function(err, source) {
130128
if(err) {
131129
console.error(err);
@@ -142,10 +140,12 @@ if(!output) {
142140
if(!options.outputDirectory) options.outputDirectory = path.dirname(output);
143141
if(!options.output) options.output = path.basename(output);
144142
if(!options.outputPostfix) options.outputPostfix = "." + path.basename(output);
143+
144+
// some listeners for the progress display
145145
if(argv.progress) {
146146
if(!options.events) options.events = new (require("events").EventEmitter)();
147147
var events = options.events;
148-
148+
149149
var sum = 0;
150150
var finished = 0;
151151
var chars = 0;
@@ -184,6 +184,8 @@ if(!output) {
184184
chars = 0;
185185
});
186186
}
187+
188+
// do the stuff
187189
webpack(input, options, function(err, stats) {
188190
if(err) {
189191
console.error(err);

0 commit comments

Comments
 (0)