mirror of https://github.com/webpack/webpack.git
				
				
				
			cr fixes
This commit is contained in:
		
							parent
							
								
									0e3795bf77
								
							
						
					
					
						commit
						399b5f4769
					
				|  | @ -4,6 +4,15 @@ | |||
| */ | ||||
| "use strict"; | ||||
| 
 | ||||
| const createHash = require("./util/createHash"); | ||||
| const RequestShortener = require("./RequestShortener"); | ||||
| 
 | ||||
| const getHash = str => { | ||||
| 	const hash = createHash("md4"); | ||||
| 	hash.update(str); | ||||
| 	return hash.digest("hex").substr(0, 4); | ||||
| }; | ||||
| 
 | ||||
| class NamedModulesPlugin { | ||||
| 	constructor(options) { | ||||
| 		this.options = options || {}; | ||||
|  | @ -12,7 +21,7 @@ class NamedModulesPlugin { | |||
| 	apply(compiler) { | ||||
| 		compiler.hooks.compilation.tap("NamedModulesPlugin", compilation => { | ||||
| 			compilation.hooks.beforeModuleIds.tap("NamedModulesPlugin", modules => { | ||||
| 				let namedModules = {}; | ||||
| 				const namedModules = new Map(); | ||||
| 
 | ||||
| 				for (const module of modules) { | ||||
| 					if (module.id === null && module.libIdent) { | ||||
|  | @ -21,18 +30,23 @@ class NamedModulesPlugin { | |||
| 						}); | ||||
| 					} | ||||
| 
 | ||||
| 					if (module.id) { | ||||
| 						(namedModules[module.id] && namedModules[module.id].push(module)) || | ||||
| 							(namedModules[module.id] = Array.of(module)); | ||||
| 					if (module.id !== null) { | ||||
| 						if (namedModules.has(module.id)) { | ||||
| 							namedModules.get(module.id).push(module); | ||||
| 						} else { | ||||
| 							namedModules.set(module.id, [module]); | ||||
| 						} | ||||
| 					} | ||||
| 				} | ||||
| 
 | ||||
| 				Object.keys(namedModules).forEach(key => { | ||||
| 					const namedModule = namedModules[key]; | ||||
| 				namedModules.forEach(namedModule => { | ||||
| 					if (namedModule.length > 1) { | ||||
| 						namedModule.forEach(module => { | ||||
| 							if (module.issuer && module.issuer.id) { | ||||
| 								module.id = `${module.issuer.id}~${module.id}`; | ||||
| 								const requestShortener = new RequestShortener(module.context); | ||||
| 								module.id = `${module.id}?${getHash( | ||||
| 									requestShortener.shorten(module.identifier()) | ||||
| 								)}`;
 | ||||
| 							} | ||||
| 						}); | ||||
| 					} | ||||
|  |  | |||
|  | @ -2,6 +2,7 @@ it("should assign different names to the same module with different issuers ", f | |||
| 	var fs = require("fs"); | ||||
| 	var path = require("path"); | ||||
| 	var bundle = fs.readFileSync(path.join(__dirname, "bundle0.js"), "utf-8"); | ||||
| 	bundle.should.containEql("./a.js~./c.js"); | ||||
| 	bundle.should.containEql("./a.js~./c.js"); | ||||
| 	bundle.should.match(/\.\/c\.js\?\w{4}/g); | ||||
| 	require("./a").should.be.equal("loader-a"); | ||||
| 	require("./b").should.be.equal("loader-b"); | ||||
| }); | ||||
|  |  | |||
		Loading…
	
		Reference in New Issue