mirror of https://github.com/webpack/webpack.git
				
				
				
			fix: avoid duplicate chunks in template's chunkLoadingGlobal #12128
This commit is contained in:
		
							parent
							
								
									06e1cce122
								
							
						
					
					
						commit
						553ea8de9d
					
				| 
						 | 
				
			
			@ -423,6 +423,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
 | 
			
		|||
							)}`,
 | 
			
		||||
							"chunkLoadingGlobal = chunkLoadingGlobal.slice();",
 | 
			
		||||
							"for(var i = 0; i < chunkLoadingGlobal.length; i++) webpackJsonpCallback(chunkLoadingGlobal[i]);",
 | 
			
		||||
							"parentChunkLoadingFunction = preChunkLoadingFunction;",
 | 
			
		||||
							"return (checkDeferredModules = checkDeferredModulesImpl)();"
 | 
			
		||||
						])};`
 | 
			
		||||
				  ])
 | 
			
		||||
| 
						 | 
				
			
			@ -467,7 +468,7 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
 | 
			
		|||
								]),
 | 
			
		||||
								"}",
 | 
			
		||||
								"if(runtime) runtime(__webpack_require__);",
 | 
			
		||||
								"parentChunkLoadingFunction(data);",
 | 
			
		||||
								"if (parentChunkLoadingFunction) parentChunkLoadingFunction(data);",
 | 
			
		||||
								"while(resolves.length) {",
 | 
			
		||||
								Template.indent("resolves.shift()();"),
 | 
			
		||||
								"}",
 | 
			
		||||
| 
						 | 
				
			
			@ -485,7 +486,14 @@ class JsonpChunkLoadingRuntimeModule extends RuntimeModule {
 | 
			
		|||
						)}`,
 | 
			
		||||
						"",
 | 
			
		||||
						`var chunkLoadingGlobal = ${chunkLoadingGlobalExpr} = ${chunkLoadingGlobalExpr} || [];`,
 | 
			
		||||
						"var parentChunkLoadingFunction = chunkLoadingGlobal.push.bind(chunkLoadingGlobal);",
 | 
			
		||||
						withDefer
 | 
			
		||||
							? Template.asString([
 | 
			
		||||
									"var preChunkLoadingFunction = chunkLoadingGlobal.push.bind(chunkLoadingGlobal);",
 | 
			
		||||
									"var parentChunkLoadingFunction;"
 | 
			
		||||
							  ])
 | 
			
		||||
							: Template.asString([
 | 
			
		||||
									"var parentChunkLoadingFunction = chunkLoadingGlobal.push.bind(chunkLoadingGlobal);"
 | 
			
		||||
							  ]),
 | 
			
		||||
						"chunkLoadingGlobal.push = webpackJsonpCallback;"
 | 
			
		||||
				  ])
 | 
			
		||||
				: "// no jsonp function"
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
| 
						 | 
				
			
			@ -173,10 +173,10 @@ describe("Stats", () => {
 | 
			
		|||
			      "assets": Array [
 | 
			
		||||
			        Object {
 | 
			
		||||
			          "name": "entryB.js",
 | 
			
		||||
			          "size": 2910,
 | 
			
		||||
			          "size": 2913,
 | 
			
		||||
			        },
 | 
			
		||||
			      ],
 | 
			
		||||
			      "assetsSize": 2910,
 | 
			
		||||
			      "assetsSize": 2913,
 | 
			
		||||
			      "auxiliaryAssets": undefined,
 | 
			
		||||
			      "auxiliaryAssetsSize": 0,
 | 
			
		||||
			      "childAssets": undefined,
 | 
			
		||||
| 
						 | 
				
			
			@ -221,10 +221,10 @@ describe("Stats", () => {
 | 
			
		|||
			      "info": Object {
 | 
			
		||||
			        "javascriptModule": false,
 | 
			
		||||
			        "minimized": true,
 | 
			
		||||
			        "size": 2910,
 | 
			
		||||
			        "size": 2913,
 | 
			
		||||
			      },
 | 
			
		||||
			      "name": "entryB.js",
 | 
			
		||||
			      "size": 2910,
 | 
			
		||||
			      "size": 2913,
 | 
			
		||||
			      "type": "asset",
 | 
			
		||||
			    },
 | 
			
		||||
			    Object {
 | 
			
		||||
| 
						 | 
				
			
			
 | 
			
		|||
										
											
												File diff suppressed because it is too large
												Load Diff
											
										
									
								
							| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
module.exports = "a";
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1 @@
 | 
			
		|||
module.exports = "b";
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,6 @@
 | 
			
		|||
it("should be main", function () {
 | 
			
		||||
	require("./a");
 | 
			
		||||
	require("./b");
 | 
			
		||||
 | 
			
		||||
	expect(window["webpackChunk"].length).toBe(1);
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,6 @@
 | 
			
		|||
it("should run", function() {
 | 
			
		||||
	var a = require("./a");
 | 
			
		||||
	var b = require("./b");
 | 
			
		||||
	expect(a).toBe("a");
 | 
			
		||||
	expect(b).toBe("b");
 | 
			
		||||
});
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,9 @@
 | 
			
		|||
module.exports = {
 | 
			
		||||
	findBundle: function(i, options) {
 | 
			
		||||
		return [
 | 
			
		||||
			"./common.js",
 | 
			
		||||
			"./main.js",
 | 
			
		||||
			"./main2.js"
 | 
			
		||||
		]
 | 
			
		||||
	}
 | 
			
		||||
};
 | 
			
		||||
| 
						 | 
				
			
			@ -0,0 +1,22 @@
 | 
			
		|||
/** @type {import("../../../../").Configuration} */
 | 
			
		||||
module.exports = {
 | 
			
		||||
	entry: {
 | 
			
		||||
		main: "./index",
 | 
			
		||||
		main2: "./index2"
 | 
			
		||||
	},
 | 
			
		||||
	target: "web",
 | 
			
		||||
	output: {
 | 
			
		||||
		filename: "[name].js"
 | 
			
		||||
	},
 | 
			
		||||
	optimization: {
 | 
			
		||||
		splitChunks: {
 | 
			
		||||
			cacheGroups: {
 | 
			
		||||
				common: {
 | 
			
		||||
					chunks: "initial",
 | 
			
		||||
					minSize: 0,
 | 
			
		||||
					name: "common"
 | 
			
		||||
				}
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
};
 | 
			
		||||
		Loading…
	
		Reference in New Issue