File tree 5 files changed +36
-3
lines changed
5 files changed +36
-3
lines changed Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ const FlagDependencyUsagePlugin = require("./FlagDependencyUsagePlugin");
52
52
const FlagDependencyExportsPlugin = require ( "./FlagDependencyExportsPlugin" ) ;
53
53
const ModuleConcatenationPlugin = require ( "./optimize/ModuleConcatenationPlugin" ) ;
54
54
const AutomaticCommonsChunksPlugin = require ( "./optimize/AutomaticCommonsChunksPlugin" ) ;
55
+ const RuntimeChunkPlugin = require ( "./optimize/RuntimeChunkPlugin" ) ;
55
56
const NoEmitOnErrorsPlugin = require ( "./NoEmitOnErrorsPlugin" ) ;
56
57
const NamedModulesPlugin = require ( "./NamedModulesPlugin" ) ;
57
58
const NamedChunksPlugin = require ( "./NamedChunksPlugin" ) ;
@@ -289,6 +290,8 @@ class WebpackOptionsApply extends OptionsApply {
289
290
new ModuleConcatenationPlugin ( ) . apply ( compiler ) ;
290
291
if ( options . optimization . splitChunks )
291
292
new AutomaticCommonsChunksPlugin ( options . optimization . splitChunks ) . apply ( compiler ) ;
293
+ if ( options . optimization . runtimeChunk )
294
+ new RuntimeChunkPlugin ( ) . apply ( compiler ) ;
292
295
if ( options . optimization . noEmitOnErrors )
293
296
new NoEmitOnErrorsPlugin ( ) . apply ( compiler ) ;
294
297
if ( options . optimization . namedModules )
Original file line number Diff line number Diff line change @@ -192,7 +192,7 @@ module.exports = class AutomaticCommonsChunksPlugin {
192
192
// This automatically merges equal names
193
193
const chunksKey = chunkIndices . sort ( ) . join ( ) ;
194
194
const key = name && `name:${ name } ` ||
195
- cacheGroup . key && `key:${ cacheGroup . key } ` ||
195
+ cacheGroup . key && `chunks: ${ chunksKey } key:${ cacheGroup . key } ` ||
196
196
`chunks:${ chunksKey } ` ;
197
197
// Add module to maps
198
198
let info = chunksInfoMap . get ( key ) ;
Original file line number Diff line number Diff line change
1
+ /*
2
+ MIT License http://www.opensource.org/licenses/mit-license.php
3
+ Author Tobias Koppers @sokra
4
+ */
5
+ "use strict" ;
6
+
7
+ module . exports = class RuntimeChunkPlugin {
8
+ constructor ( options ) { }
9
+
10
+ apply ( compiler ) {
11
+ compiler . hooks . compilation . tap ( "RuntimeChunkPlugin" , compilation => {
12
+ compilation . hooks . optimizeChunksAdvanced . tap ( "RuntimeChunkPlugin" , ( ) => {
13
+ for ( const entrypoint of compilation . entrypoints . values ( ) ) {
14
+ const chunk = entrypoint . getRuntimeChunk ( ) ;
15
+ if ( chunk . getNumberOfModules ( ) > 0 ) {
16
+ const newChunk = compilation . addChunk ( entrypoint . name + "-runtime" ) ;
17
+ entrypoint . unshiftChunk ( newChunk ) ;
18
+ newChunk . addGroup ( entrypoint ) ;
19
+ entrypoint . setRuntimeChunk ( newChunk ) ;
20
+ }
21
+ }
22
+ } ) ;
23
+ } ) ;
24
+ }
25
+ }
Original file line number Diff line number Diff line change @@ -209,7 +209,7 @@ class JsonpMainTemplatePlugin {
209
209
"function checkDeferredModules() {" ,
210
210
Template . indent ( [
211
211
"var result;" ,
212
- "for(i = 0; i < deferredModules.length; i++) {" ,
212
+ "for(var i = 0; i < deferredModules.length; i++) {" ,
213
213
Template . indent ( [
214
214
"var deferredModule = deferredModules[i];" ,
215
215
"var fullfilled = true;" ,
@@ -241,10 +241,11 @@ class JsonpMainTemplatePlugin {
241
241
var globalObject = mainTemplate . outputOptions . globalObject ;
242
242
return Template . asString ( [
243
243
`var jsonpArray = ${ globalObject } [${ JSON . stringify ( jsonpFunction ) } ] = ${ globalObject } [${ JSON . stringify ( jsonpFunction ) } ] || [];` ,
244
+ "var oldJsonpFunction = jsonpArray.push.bind(jsonpArray);" ,
244
245
"jsonpArray.push = webpackJsonpCallback;" ,
245
246
"jsonpArray = jsonpArray.slice();" ,
246
247
"for(var i = 0; i < jsonpArray.length; i++) webpackJsonpCallback(jsonpArray[i]);" ,
247
- "var parentJsonpFunction = jsonpArray.push.bind(jsonpArray) ;" ,
248
+ "var parentJsonpFunction = oldJsonpFunction ;" ,
248
249
"" ,
249
250
source
250
251
] ) ;
Original file line number Diff line number Diff line change 1486
1486
}
1487
1487
]
1488
1488
},
1489
+ "runtimeChunk" : {
1490
+ "description" : " Create an additional chunk which contains only the webpack runtime and chunk hash maps" ,
1491
+ "type" : " boolean"
1492
+ },
1489
1493
"noEmitOnErrors" : {
1490
1494
"description" : " Avoid emitting assets when errors occur" ,
1491
1495
"type" : " boolean"
You can’t perform that action at this time.
0 commit comments