Skip to content

Commit 4785721

Browse files
committed
made stuff ready for worker implementation
1 parent 7a40d0d commit 4785721

5 files changed

Lines changed: 34 additions & 21 deletions

File tree

buildin/__webpack_console.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
var console = (function() { return this["console"] || this["window"].console || {} }());
1+
var console = (function() { return this["console"] || (this["window"] && this["window"].console) || {} }());
22
module.exports = console;
33
for(var name in {log:1, info:1, error:1, warn:1, dir:1, trace:1, assert:1})
44
if(!console[name])

buildin/__webpack_global.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
module.exports = window;
1+
(function() {
2+
module.exports = this;
3+
}).call(null);

lib/formatOutput.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ module.exports = function(stats, options) {
6464
});
6565
});
6666
}
67+
if(stats.subStats.length > 0) {
68+
buf.push("Embedded Stats");
69+
stats.subStats.forEach(function(stats) {
70+
buf.push(" "+c("\033[1m") + compressFilename(stats.request) + c("\033[22m"));
71+
var subFormat = module.exports(stats, options).split(/\n/g).join("\n ");
72+
buf.push(" "+subFormat);
73+
});
74+
}
6775
if(stats.warnings) {
6876
stats.warnings.forEach(function(warning) {
6977
buf.push(c("\033[1m\033[33m")+"WARNING: " + warning + c("\033[39m\033[22m"));

lib/webpack.js

Lines changed: 21 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ module.exports = function(context, moduleName, options, callback) {
8989

9090
options.context = options.context || context;
9191

92+
options.emitFile = options.emitFile || function(filename, content) {
93+
options.internal.fileWrites.push([path.join(options.outputDirectory, filename), content]);
94+
}
95+
9296
if(options.output) {
9397
if(!options.outputDirectory) {
9498
options.outputDirectory = path.dirname(options.output);
@@ -127,8 +131,9 @@ module.exports = function(context, moduleName, options, callback) {
127131
options.postLoaders = options.postLoaders || [];
128132

129133
options.loader = options.loader || {};
130-
options.loader.emitFile = options.loader.emitFile || function(filename, content) {
131-
options.internal.fileWrites.push([path.join(options.outputDirectory, filename), content]);
134+
options.loader.emitFile = options.loader.emitFile || options.emitFile;
135+
options.loader.emitSubStats = options.loader.emitSubStats || function(stats) {
136+
options.internal.subStats.push(stats);
132137
}
133138

134139
// Create a options.events as EventEmitter
@@ -216,8 +221,9 @@ function webpack(context, moduleName, options, callback) {
216221

217222
// all writes to files
218223
// items: [filename, content]
219-
var fileWrites = [];
224+
var fileWrites = [], subStats = [];
220225
options.internal.fileWrites = fileWrites;
226+
options.internal.subStats = subStats;
221227

222228
// Some status info
223229
options.events.emit("task", "create ouput directory");
@@ -277,8 +283,7 @@ function webpack(context, moduleName, options, callback) {
277283
chunksCount++;
278284

279285
// build filename
280-
var filename = chunk.filename = path.join(options.outputDirectory,
281-
chunk.realId === 0 ? options.output : chunk.realId + options.outputPostfix);
286+
var filename = chunk.filename = chunk.realId === 0 ? options.output : chunk.realId + options.outputPostfix;
282287

283288
// get content of chunk
284289
var content = writeChunk(depTree, chunk, options);
@@ -301,17 +306,13 @@ function webpack(context, moduleName, options, callback) {
301306
buffer.push(template);
302307

303308
// write extra info into object
304-
if(chunkIds.length > 1) {
305-
buffer.push("/******/({a:");
306-
buffer.push(JSON.stringify(options.outputPostfix.replace(HASH_REGEXP, hash)));
307-
buffer.push(",b:");
308-
buffer.push(JSON.stringify(options.outputJsonpFunction));
309-
buffer.push(",c:");
310-
buffer.push(JSON.stringify(options.publicPrefix.replace(HASH_REGEXP, hash)));
311-
buffer.push(",\n");
312-
} else {
313-
buffer.push("/******/({\n");
314-
}
309+
buffer.push("/******/({a:");
310+
buffer.push(JSON.stringify(options.outputPostfix.replace(HASH_REGEXP, hash)));
311+
buffer.push(",b:");
312+
buffer.push(JSON.stringify(options.outputJsonpFunction));
313+
buffer.push(",c:");
314+
buffer.push(JSON.stringify(options.publicPrefix.replace(HASH_REGEXP, hash)));
315+
buffer.push(",\n");
315316
} else { // lazy loaded chunk
316317
// write only jsonp function and chunk id as function call
317318
buffer.push("/******/");
@@ -331,14 +332,14 @@ function webpack(context, moduleName, options, callback) {
331332

332333
// minimize if wished
333334
try {
334-
if(options.minimize) buffer = uglify(buffer, filename);
335+
if(options.minimize) buffer = uglify(buffer, path.join(options.outputDirectory, filename));
335336
} catch(e) {
336337
callback(e);
337338
return;
338339
}
339340

340341
// push it as "file write"
341-
fileWrites.unshift([filename, buffer]);
342+
options.emitFile(filename, buffer);
342343
});
343344
options.events.emit("task-end", "prepare chunks");
344345
options.events.emit("start-writing", hash);
@@ -395,6 +396,7 @@ function webpack(context, moduleName, options, callback) {
395396
writingFinished();
396397
});
397398
});
399+
if(fileWrites.length == 0) writingFinished();
398400
}
399401

400402
// after writing: generate statistics
@@ -440,6 +442,7 @@ function webpack(context, moduleName, options, callback) {
440442
buffer.warnings = depTree.warnings;
441443
buffer.errors = depTree.errors;
442444
buffer.fileModules = fileModulesMap;
445+
buffer.subStats = subStats;
443446
buffer.time = new Date() - startTime;
444447
options.events.emit("task-end", "statistics");
445448
options.events.emit("bundle", buffer);

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "webpack",
3-
"version": "0.4.24",
3+
"version": "0.4.25",
44
"author": "Tobias Koppers @sokra",
55
"description": "Packs CommonJs Modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loading of js, json, jade, coffee, css, ... out of the box and more with custom loaders.",
66
"dependencies": {

0 commit comments

Comments
 (0)