mirror of https://github.com/webpack/webpack.git
				
				
				
			
							parent
							
								
									dd232012ca
								
							
						
					
					
						commit
						3bc6d7b60b
					
				| 
						 | 
					@ -65,6 +65,14 @@ JsonpMainTemplatePlugin.prototype.apply = function(mainTemplate) {
 | 
				
			||||||
						chunk: {
 | 
											chunk: {
 | 
				
			||||||
							id: "\" + chunkId + \"",
 | 
												id: "\" + chunkId + \"",
 | 
				
			||||||
							hash: "\" + " + JSON.stringify(chunkHashMap) + "[chunkId] + \"",
 | 
												hash: "\" + " + JSON.stringify(chunkHashMap) + "[chunkId] + \"",
 | 
				
			||||||
 | 
												hashWithLength: function(length) {
 | 
				
			||||||
 | 
													var shortChunkHashMap = {};
 | 
				
			||||||
 | 
													Object.keys(chunkHashMap).forEach(function(chunkId) {
 | 
				
			||||||
 | 
														if(typeof chunkHashMap[chunkId] === "string")
 | 
				
			||||||
 | 
															shortChunkHashMap[chunkId] = chunkHashMap[chunkId].substr(0, length);
 | 
				
			||||||
 | 
													});
 | 
				
			||||||
 | 
													return "\" + " + JSON.stringify(shortChunkHashMap) + "[chunkId] + \"";
 | 
				
			||||||
 | 
												},
 | 
				
			||||||
							name: "\" + (" + JSON.stringify(chunkNameMap) + "[chunkId]||chunkId) + \""
 | 
												name: "\" + (" + JSON.stringify(chunkNameMap) + "[chunkId]||chunkId) + \""
 | 
				
			||||||
						}
 | 
											}
 | 
				
			||||||
					}) + ";",
 | 
										}) + ";",
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
| 
						 | 
					@ -25,10 +25,14 @@ function TemplatedPathPlugin() {}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
module.exports = TemplatedPathPlugin;
 | 
					module.exports = TemplatedPathPlugin;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
function withHashLength(replacer) {
 | 
					function withHashLength(replacer, handlerFn) {
 | 
				
			||||||
	return function (_, hashLength) {
 | 
						return function (_, hashLength) {
 | 
				
			||||||
 | 
							var length = hashLength && parseInt(hashLength, 10);
 | 
				
			||||||
 | 
							if(length && handlerFn) {
 | 
				
			||||||
 | 
								return handlerFn(length);
 | 
				
			||||||
 | 
							}
 | 
				
			||||||
		var hash = replacer.apply(this, arguments);
 | 
							var hash = replacer.apply(this, arguments);
 | 
				
			||||||
		return hashLength ? hash.slice(0, parseInt(hashLength, 10)) : hash;
 | 
							return length ? hash.slice(0, length) : hash;
 | 
				
			||||||
	};
 | 
						};
 | 
				
			||||||
}
 | 
					}
 | 
				
			||||||
 | 
					
 | 
				
			||||||
| 
						 | 
					@ -50,10 +54,11 @@ function replacePathVariables(path, data) {
 | 
				
			||||||
	var chunkId = chunk && chunk.id;
 | 
						var chunkId = chunk && chunk.id;
 | 
				
			||||||
	var chunkName = chunk && (chunk.name || chunk.id);
 | 
						var chunkName = chunk && (chunk.name || chunk.id);
 | 
				
			||||||
	var chunkHash = chunk && (chunk.renderedHash || chunk.hash);
 | 
						var chunkHash = chunk && (chunk.renderedHash || chunk.hash);
 | 
				
			||||||
 | 
						var chunkHashWithLength = chunk && chunk.hashWithLength;
 | 
				
			||||||
 | 
					
 | 
				
			||||||
	return path
 | 
						return path
 | 
				
			||||||
		.replace(REGEXP_HASH, withHashLength(getReplacer(data.hash)))
 | 
							.replace(REGEXP_HASH, withHashLength(getReplacer(data.hash)))
 | 
				
			||||||
		.replace(REGEXP_CHUNKHASH, withHashLength(getReplacer(chunkHash)))
 | 
							.replace(REGEXP_CHUNKHASH, withHashLength(getReplacer(chunkHash), chunkHashWithLength))
 | 
				
			||||||
		.replace(REGEXP_ID, getReplacer(chunkId))
 | 
							.replace(REGEXP_ID, getReplacer(chunkId))
 | 
				
			||||||
		.replace(REGEXP_NAME, getReplacer(chunkName))
 | 
							.replace(REGEXP_NAME, getReplacer(chunkName))
 | 
				
			||||||
		.replace(REGEXP_FILE, getReplacer(data.filename))
 | 
							.replace(REGEXP_FILE, getReplacer(data.filename))
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue