Skip to content

Commit ae4146c

Browse files
committed
Merge branch 'feature/fix-555' of https://github.com/diurnalist/webpack into diurnalist-feature/fix-555
2 parents 1c9fd48 + 97780e1 commit ae4146c

7 files changed

Lines changed: 39 additions & 11 deletions

File tree

lib/JsonpMainTemplatePlugin.js

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ JsonpMainTemplatePlugin.prototype.apply = function(mainTemplate) {
4343
chunkNameMap[c.id] = c.name || undefined;
4444
c.chunks.forEach(addChunk);
4545
}(chunk));
46+
var renderedHash = this.renderCurrentHashCode(hash);
4647
return this.asString([
4748
"// \"0\" is the signal for \"already loaded\"",
4849
"if(installedChunks[chunkId] === 0)",
@@ -62,7 +63,10 @@ JsonpMainTemplatePlugin.prototype.apply = function(mainTemplate) {
6263
"script.async = true;",
6364
"script.src = " + this.requireFn + ".p + " +
6465
this.applyPluginsWaterfall("asset-path", JSON.stringify(chunkFilename), {
65-
hash: "\" + " + this.renderCurrentHashCode(hash) + " + \"",
66+
hash: "\" + " + renderedHash + " + \"",
67+
hashWithLength: function(length) {
68+
return "\" + " + renderedHash.slice(0, length) + " + \"";
69+
},
6670
chunk: {
6771
id: "\" + chunkId + \"",
6872
hash: "\" + " + JSON.stringify(chunkHashMap) + "[chunkId] + \"",
@@ -127,14 +131,21 @@ JsonpMainTemplatePlugin.prototype.apply = function(mainTemplate) {
127131
var hotUpdateChunkFilename = this.outputOptions.hotUpdateChunkFilename;
128132
var hotUpdateMainFilename = this.outputOptions.hotUpdateMainFilename;
129133
var hotUpdateFunction = this.outputOptions.hotUpdateFunction || Template.toIdentifier("webpackHotUpdate" + (this.outputOptions.library || ""));
134+
var renderedHash = this.renderCurrentHashCode(hash);
130135
var currentHotUpdateChunkFilename = this.applyPluginsWaterfall("asset-path", JSON.stringify(hotUpdateChunkFilename), {
131-
hash: "\" + " + this.renderCurrentHashCode(hash) + " + \"",
136+
hash: "\" + " + renderedHash + " + \"",
137+
hashWithLength: function(length) {
138+
return "\" + " + renderedHash.slice(0, length) + " + \"";
139+
},
132140
chunk: {
133141
id: "\" + chunkId + \""
134142
}
135143
});
136144
var currentHotUpdateMainFilename = this.applyPluginsWaterfall("asset-path", JSON.stringify(hotUpdateMainFilename), {
137-
hash: "\" + " + this.renderCurrentHashCode(hash) + " + \""
145+
hash: "\" + " + renderedHash + " + \"",
146+
hashWithLength: function(length) {
147+
return "\" + " + renderedHash.slice(0, length) + " + \"";
148+
}
138149
});
139150
return source + "\n"+
140151
"var parentHotUpdateCallback = this[" + JSON.stringify(hotUpdateFunction) + "];\n" +

lib/TemplatedPathPlugin.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function replacePathVariables(path, data) {
6363
var chunkHashWithLength = chunk && chunk.hashWithLength;
6464

6565
return path
66-
.replace(REGEXP_HASH, withHashLength(getReplacer(data.hash)))
66+
.replace(REGEXP_HASH, withHashLength(getReplacer(data.hash), data.hashWithLength))
6767
.replace(REGEXP_CHUNKHASH, withHashLength(getReplacer(chunkHash), chunkHashWithLength))
6868
.replace(REGEXP_ID, getReplacer(chunkId))
6969
.replace(REGEXP_NAME, getReplacer(chunkName))

lib/node/NodeMainTemplatePlugin.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,21 @@ NodeMainTemplatePlugin.prototype.apply = function(mainTemplate) {
9898
var hotUpdateChunkFilename = this.outputOptions.hotUpdateChunkFilename;
9999
var hotUpdateMainFilename = this.outputOptions.hotUpdateMainFilename;
100100
var hotUpdateFunction = this.outputOptions.hotUpdateFunction || Template.toIdentifier("webpackHotUpdate" + (this.outputOptions.library || ""));
101+
var renderedHash = this.renderCurrentHashCode(hash);
101102
var currentHotUpdateChunkFilename = this.applyPluginsWaterfall("asset-path", JSON.stringify(hotUpdateChunkFilename), {
102-
hash: "\" + " + this.renderCurrentHashCode(hash) + " + \"",
103+
hash: "\" + " + renderedHash + " + \"",
104+
hashWithLength: function(length) {
105+
return "\" + " + renderedHash.slice(0, length) + " + \"";
106+
},
103107
chunk: {
104108
id: "\" + chunkId + \""
105109
}
106110
});
107111
var currentHotUpdateMainFilename = this.applyPluginsWaterfall("asset-path", JSON.stringify(hotUpdateMainFilename), {
108-
hash: "\" + " + this.renderCurrentHashCode(hash) + " + \""
112+
hash: "\" + " + renderedHash + " + \"",
113+
hashWithLength: function(length) {
114+
return "\" + " + renderedHash.slice(0, length) + " + \"";
115+
}
109116
});
110117
return Template.getFunctionContent(self.asyncChunkLoading ? function() {
111118
function hotDownloadUpdateChunk(chunkId) {

lib/webworker/WebWorkerMainTemplatePlugin.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,17 @@ WebWorkerMainTemplatePlugin.prototype.apply = function(mainTemplate) {
3030
mainTemplate.plugin("require-ensure", function(_, chunk, hash) {
3131
var filename = this.outputOptions.filename || "bundle.js";
3232
var chunkFilename = this.outputOptions.chunkFilename || "[id]." + filename;
33+
var renderedHash = this.renderCurrentHashCode(hash);
3334
return this.asString([
3435
"// \"1\" is the signal for \"already loaded\"",
3536
"if(!installedChunks[chunkId]) {",
3637
this.indent([
3738
"importScripts(" +
3839
this.applyPluginsWaterfall("asset-path", JSON.stringify(chunkFilename), {
39-
hash: "\" + " + this.renderCurrentHashCode(hash) + " + \"",
40+
hash: "\" + " + renderedHash + " + \"",
41+
hashWithLength: function(length) {
42+
return "\" + " + renderedHash.slice(0, length) + " + \"";
43+
},
4044
chunk: {
4145
id: "\" + chunkId + \""
4246
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
module.exports = "chunk";
Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1-
it("should compile and run the test", function () {
2-
1+
it("should compile and run the test", function (done) {
2+
require(['./chunk'], function () {
3+
it("should load additional chunks", function () {});
4+
done();
5+
});
36
});

test/configCases/hash-length/output-filename/webpack.config.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ module.exports = [{
88
}
99
}, {
1010
output: {
11-
filename: 'bundle.[chunkhash:8].js'
11+
filename: 'bundle.[hash].js',
12+
chunkFilename: '[id].bundle.[hash:8].js'
1213
}
1314
}, {
1415
output: {
15-
filename: 'bundle.[chunkhash].js'
16+
filename: 'bundle.[hash:6].js',
17+
chunkFilename: '[id].bundle.[hash:8].js'
1618
}
1719
}];

0 commit comments

Comments
 (0)