Skip to content

Commit 327a990

Browse files
committed
fixed bugs
1 parent a84a043 commit 327a990

File tree

10 files changed

+41
-22
lines changed

10 files changed

+41
-22
lines changed

lib/ChunkTemplate.js

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@ ChunkTemplate.prototype.renderFooter = function(chunk) {
3535
};
3636

3737
ChunkTemplate.prototype.updateHash = function(hash) {
38-
hash.update("template");
39-
hash.update("jsonp");
40-
hash.update("2");
41-
hash.update(this.outputOptions.jsonpFunction + "");
42-
hash.update(this.outputOptions.library + "");
38+
hash.update("ChunkTemplate");
39+
hash.update("1");
4340
};

lib/Compilation.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -541,7 +541,7 @@ Compilation.prototype.createChunkAssets = function createChunkAssets() {
541541
if(this.cache && this.cache["c" + chunk.id + chunk.name] && this.cache["c" + chunk.id + chunk.name].hash == hash) {
542542
source = this.cache["c" + chunk.id + chunk.name].source;
543543
} else {
544-
source = this.mainTemplate.render(hash, chunk, this.moduleTemplate, this.dependencyTemplates);
544+
source = this.mainTemplate.render(this.hash, chunk, this.moduleTemplate, this.dependencyTemplates);
545545
if(this.cache) {
546546
this.cache["c" + chunk.id + chunk.name] = {
547547
hash: hash,
@@ -572,7 +572,7 @@ Compilation.prototype.createChunkAssets = function createChunkAssets() {
572572
}
573573
this.assets[
574574
file = chunkFilename
575-
.replace(Template.REGEXP_HASH, hash)
575+
.replace(Template.REGEXP_HASH, this.hash)
576576
.replace(Template.REGEXP_CHUNKHASH, chunk.renderedHash)
577577
.replace(Template.REGEXP_ID, chunk.id)
578578
] = source;
@@ -582,7 +582,7 @@ Compilation.prototype.createChunkAssets = function createChunkAssets() {
582582
this.assets[
583583
file = namedChunkFilename
584584
.replace(Template.REGEXP_CHUNKHASH, chunk.renderedHash)
585-
.replace(Template.REGEXP_HASH, hash)
585+
.replace(Template.REGEXP_HASH, this.hash)
586586
.replace(Template.REGEXP_ID, chunk.id)
587587
.replace(Template.REGEXP_NAME, chunk.name || "")
588588
] = source;

lib/JsonpChunkTemplate.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ JsonpChunkTemplate.prototype.renderFooter = function(chunk) {
2525

2626
JsonpChunkTemplate.prototype.updateHash = function(hash) {
2727
ChunkTemplate.prototype.updateHash.call(this, hash);
28-
hash.update("jsonp");
28+
hash.update("JsonpChunkTemplate");
2929
hash.update("3");
3030
hash.update(this.outputOptions.jsonpFunction + "");
3131
hash.update(this.outputOptions.library + "");

lib/JsonpMainTemplate.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,8 @@ JsonpMainTemplate.prototype.renderRequireEnsure = function(hash, chunk) {
5454
"script.charset = 'utf-8';",
5555
"script.src = modules.c + " +
5656
JSON.stringify(chunkFilename
57-
.replace(Template.REGEXP_HASH, hash)
5857
.replace(Template.REGEXP_NAME, ""))
58+
.replace(Template.REGEXP_HASH, "\" + " + this.renderCurrentHashCode(hash) + " + \"")
5959
.replace(Template.REGEXP_CHUNKHASH, "\" + " + JSON.stringify(chunkHashMap) + "[chunkId] + \"")
6060
.replace(Template.REGEXP_ID, "\" + chunkId + \"") + ";",
6161
"head.appendChild(script);"
@@ -88,14 +88,18 @@ JsonpMainTemplate.prototype.renderInit = function(hash, chunk) {
8888
this.indent(this.renderAddModule(hash, chunk, "moduleId", "moreModules[moduleId]")),
8989
"}",
9090
"while(callbacks.length)",
91-
this.indent("callbacks.shift().call(null, require);"),
91+
this.indent("callbacks.shift().call(null, " + this.requireFn + ");"),
9292
]),
9393
"};"
9494
);
9595
}
9696
return buf;
9797
};
9898

99+
JsonpMainTemplate.prototype.renderCurrentHashCode = function(hash) {
100+
return JSON.stringify(hash);
101+
};
102+
99103
JsonpMainTemplate.prototype.updateHash = function(hash) {
100104
MainTemplate.prototype.updateHash.call(this, hash);
101105
hash.update("jsonp");

lib/MainTemplate.js

Lines changed: 15 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ MainTemplate.prototype.render = function(hash, chunk, moduleTemplate, dependency
2727
buf.push(this.asString(this.renderInit(hash, chunk)));
2828
buf.push("");
2929
buf.push("// Load entry module and return exports");
30-
buf.push("return " + this.requireFn + "(0);");
30+
buf.push("return " + this.renderRequireFunctionForModule(hash, chunk, "0") + "(0);");
3131
var source = new ConcatSource();
3232
source.add("/******/ (function(modules) { // webpackBootstrap\n");
3333
source.add(new PrefixSource("/******/ \t", new OriginalSource(this.asString(buf), "webpackBootstrap " + hash)));
@@ -91,15 +91,11 @@ MainTemplate.prototype.renderRequireContent = function(hash, chunk) {
9191
"",
9292
"// Create a new module (and put it into the cache)",
9393
"var module = installedModules[moduleId] = {",
94-
this.indent([
95-
"exports: {},",
96-
"id: moduleId,",
97-
"loaded: false"
98-
]),
94+
this.indent(this.renderModule(hash, chunk, "moduleId")),
9995
"};",
10096
"",
10197
"// Execute the module function",
102-
"modules[moduleId].call(null, module, module.exports, " + this.requireFn + ");",
98+
"modules[moduleId].call(null, module, module.exports, " + this.renderRequireFunctionForModule(hash, chunk, "moduleId") + ");",
10399
"",
104100
"// Flag the module as loaded",
105101
"module.loaded = true;",
@@ -109,6 +105,18 @@ MainTemplate.prototype.renderRequireContent = function(hash, chunk) {
109105
];
110106
};
111107

108+
MainTemplate.prototype.renderRequireFunctionForModule = function(hash, chunk, varModuleId) {
109+
return this.requireFn;
110+
};
111+
112+
MainTemplate.prototype.renderModule = function(hash, chunk, varModuleId) {
113+
return [
114+
"exports: {},",
115+
"id: moduleId,",
116+
"loaded: false"
117+
];
118+
};
119+
112120
MainTemplate.prototype.renderRequireExtensions = function(hash, chunk) {
113121
var buf = [];
114122
if(chunk.chunks.length == 0) {

lib/RecordIdsPlugin.js

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ RecordIdsPlugin.prototype.apply = function(compiler) {
2525
if(module.id !== null) return;
2626
var identifier = module.identifier();
2727
var id = records.modules.byIdentifier[identifier];
28+
if(id === undefined) return;
2829
if(usedIds[id]) return;
2930
usedIds[id] = true;
3031
module.id = id;
@@ -68,6 +69,7 @@ RecordIdsPlugin.prototype.apply = function(compiler) {
6869
if(chunk.id !== null) return;
6970
if(!chunk.name) return;
7071
var id = records.chunks.byName[chunk.name];
72+
if(id === undefined) return;
7173
if(usedIds[id]) return;
7274
usedIds[id] = true;
7375
chunk.id = id;

lib/WebpackOptionsApply.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,8 +92,10 @@ WebpackOptionsApply.prototype.process = function(options, compiler) {
9292
);
9393
break;
9494
}
95-
if(options.output.library || options.output.libraryTarget != "var")
95+
if(options.output.library || options.output.libraryTarget != "var") {
9696
compiler.apply(new LibraryTemplatePlugin(options.output.library, options.output.libraryTarget));
97+
}
98+
9799
if(options.devtool == "eval")
98100
compiler.apply(new EvalDevToolModulePlugin());
99101
else if(options.devtool == "sourcemap" || options.devtool == "source-map")
@@ -102,6 +104,7 @@ WebpackOptionsApply.prototype.process = function(options, compiler) {
102104
options.devtool == "inline-sourcemap" ||
103105
options.devtool == "inline-source-map")
104106
compiler.apply(new SourceMapDevToolPlugin(options.context));
107+
105108
function itemToPlugin(item, name) {
106109
if(Array.isArray(item))
107110
return new MultiEntryPlugin(options.context, item, name);
@@ -115,6 +118,7 @@ WebpackOptionsApply.prototype.process = function(options, compiler) {
115118
compiler.apply(itemToPlugin(options.entry[name], name));
116119
});
117120
}
121+
118122
if(options.prefetch) {
119123
options.prefetch.map(function(request) {
120124
compiler.apply(new PrefetchPlugin(options.context, request));

lib/optimize/DedupePlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ function DedupModuleTemplateDecorator(template) {
190190
}
191191

192192
DedupModuleTemplateDecorator.prototype.render = function(module, dependencyTemplates, chunk) {
193-
if(!module.rootDuplicatesChunks) return this.template.render(module, dependencyTemplates, chunk);
193+
if(!module.rootDuplicatesChunks || !chunk) return this.template.render(module, dependencyTemplates, chunk);
194194
var chunkIndex = module.rootDuplicatesChunks.indexOf(chunk);
195195
if(!module.rootDuplicates || !module.rootDuplicates[chunkIndex]) return this.template.render(module, dependencyTemplates, chunk);
196196
var rootDuplicates = module.rootDuplicates[chunkIndex];

lib/webworker/WebWorkerMainTemplate.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,8 @@ WebWorkerMainTemplate.prototype.renderRequireEnsure = function(hash, chunk) {
3434
this.indent([
3535
"importScripts(" +
3636
JSON.stringify(chunkFilename
37-
.replace(Template.REGEXP_HASH, hash)
3837
.replace(Template.REGEXP_NAME, ""))
38+
.replace(Template.REGEXP_HASH, "\" + " + this.renderCurrentHashCode(hash) + " + \"")
3939
.replace(Template.REGEXP_ID, "\" + chunkId + \"") + ");"
4040
]),
4141
"}",
@@ -62,6 +62,10 @@ WebWorkerMainTemplate.prototype.renderInit = function(hash, chunk) {
6262
return buf;
6363
};
6464

65+
WebWorkerMainTemplate.prototype.renderCurrentHashCode = function(hash) {
66+
return JSON.stringify(hash);
67+
};
68+
6569
WebWorkerMainTemplate.prototype.updateHash = function(hash) {
6670
MainTemplate.prototype.updateHash.call(this, hash);
6771
hash.update("webworker");

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.10.0-beta24",
3+
"version": "0.10.0-beta25",
44
"author": "Tobias Koppers @sokra",
55
"description": "Packs CommonJs/AMD/Labeled Modules for the browser. Allows to split your codebase into multiple bundles, which can be loaded on demand. Support loaders to preprocess files, i.e. json, jade, coffee, css, less, ... and your custom stuff.",
66
"dependencies": {

0 commit comments

Comments
 (0)