mirror of https://github.com/webpack/webpack.git
				
				
				
			Merge pull request #12370 from webpack/bugfix/split-chunk-min-size
fix bug where module size is added multiple times to the split chunk
This commit is contained in:
		
						commit
						06b39fa973
					
				|  | @ -232,7 +232,7 @@ const compareEntries = (a, b) => { | |||
| 	const diffSizeReduce = aSizeReduce - bSizeReduce; | ||||
| 	if (diffSizeReduce) return diffSizeReduce; | ||||
| 	// 4. by cache group index
 | ||||
| 	const indexDiff = a.cacheGroupIndex - b.cacheGroupIndex; | ||||
| 	const indexDiff = b.cacheGroupIndex - a.cacheGroupIndex; | ||||
| 	if (indexDiff) return indexDiff; | ||||
| 	// 5. by number of modules (to be able to compare by identifier)
 | ||||
| 	const modulesA = a.modules; | ||||
|  | @ -1113,12 +1113,16 @@ module.exports = class SplitChunksPlugin { | |||
| 								}) | ||||
| 							); | ||||
| 						} | ||||
| 						const oldSize = info.modules.size; | ||||
| 						info.modules.add(module); | ||||
| 						if (info.modules.size !== oldSize) { | ||||
| 							for (const type of module.getSourceTypes()) { | ||||
| 								info.sizes[type] = (info.sizes[type] || 0) + module.size(type); | ||||
| 							} | ||||
| 						if (!info.chunksKeys.has(selectedChunksKey)) { | ||||
| 						} | ||||
| 						const oldChunksKeysSize = info.chunksKeys.size; | ||||
| 						info.chunksKeys.add(selectedChunksKey); | ||||
| 						if (oldChunksKeysSize !== info.chunksKeys.size) { | ||||
| 							for (const chunk of selectedChunks) { | ||||
| 								info.chunks.add(chunk); | ||||
| 							} | ||||
|  |  | |||
|  | @ -0,0 +1,2 @@ | |||
| import "./a-only-module"; | ||||
| import "./shared-module"; | ||||
|  | @ -0,0 +1 @@ | |||
| import("./shared-module"); | ||||
|  | @ -0,0 +1,4 @@ | |||
| it("should not split the shared-modules into a separate chunk", () => { | ||||
| 	const shared = __STATS__.modules.find(m => m.name.includes("shared-module")); | ||||
| 	expect(shared.chunks).toEqual(["a", "shared-module_js"]); | ||||
| }); | ||||
|  | @ -0,0 +1 @@ | |||
| // content content content content content content content content content
 | ||||
|  | @ -0,0 +1,29 @@ | |||
| /** @type {import("../../../../").Configuration} */ | ||||
| module.exports = { | ||||
| 	entry: { | ||||
| 		bundle0: "./index", | ||||
| 		a: "./a", | ||||
| 		b: "./b" | ||||
| 	}, | ||||
| 	output: { | ||||
| 		filename: "[name].js" | ||||
| 	}, | ||||
| 	optimization: { | ||||
| 		chunkIds: "named", | ||||
| 		sideEffects: false, | ||||
| 		splitChunks: { | ||||
| 			cacheGroups: { | ||||
| 				default: false, | ||||
| 				defaultVendors: false, | ||||
| 				test: { | ||||
| 					test: /shared/, | ||||
| 					minChunks: 1, | ||||
| 					usedExports: false, | ||||
| 					chunks: "initial", | ||||
| 					minSize: 100, | ||||
| 					minRemainingSize: 0 | ||||
| 				} | ||||
| 			} | ||||
| 		} | ||||
| 	} | ||||
| }; | ||||
		Loading…
	
		Reference in New Issue