File tree Expand file tree Collapse file tree 6 files changed +55
-4
lines changed
test/configCases/split-chunks/runtime-chunk Expand file tree Collapse file tree 6 files changed +55
-4
lines changed Original file line number Diff line number Diff line change 66
77const util = require ( "util" ) ;
88const SortableSet = require ( "./util/SortableSet" ) ;
9+ const intersect = require ( "./util/SetHelpers" ) . intersect ;
910const GraphHelpers = require ( "./GraphHelpers" ) ;
1011let debugId = 1000 ;
1112const ERR_CHUNK_ENTRY = "Chunk.entry was removed. Use hasRuntime()" ;
@@ -321,12 +322,15 @@ class Chunk {
321322 }
322323
323324 getAllAsyncChunks ( ) {
324- const initialChunks = new Set ( ) ;
325- const queue = new Set ( this . groupsIterable ) ;
325+ const queue = new Set ( ) ;
326326 const chunks = new Set ( ) ;
327327
328- for ( const chunkGroup of queue ) {
329- for ( const chunk of chunkGroup . chunks ) initialChunks . add ( chunk ) ;
328+ const initialChunks = intersect (
329+ Array . from ( this . groupsIterable , g => new Set ( g . chunks ) )
330+ ) ;
331+
332+ for ( const chunkGroup of this . groupsIterable ) {
333+ for ( const child of chunkGroup . childrenIterable ) queue . add ( child ) ;
330334 }
331335
332336 for ( const chunkGroup of queue ) {
Original file line number Diff line number Diff line change 1+ const should = require ( "should" ) ;
2+ const FakeDocument = require ( "../../../helpers/FakeDocument" ) ;
3+
4+ beforeEach ( ( ) => {
5+ global . document = new FakeDocument ( ) ;
6+ } ) ;
7+
8+ afterEach ( ( ) => {
9+ delete global . document ;
10+ } )
11+
12+ it ( "should be able to load the split chunk on demand" , ( ) => {
13+ const promise = import ( /* webpackChunkName: "shared" */ "./shared" ) ;
14+
15+ const script = document . head . _children [ 0 ] ;
16+ should ( script . src ) . be . eql ( "dep~b~shared.js" ) ;
17+ } ) ;
Original file line number Diff line number Diff line change 1+ import "./shared" ;
Original file line number Diff line number Diff line change 1+ module . exports = {
2+ findBundle : function ( i , options ) {
3+ return [ "runtime.js" , "a.js" ] ;
4+ }
5+ } ;
Original file line number Diff line number Diff line change 1+ const path = require ( "path" ) ;
2+
3+ module . exports = {
4+ entry : {
5+ a : "./a" ,
6+ b : "./b"
7+ } ,
8+ target : "web" ,
9+ output : {
10+ filename : "[name].js"
11+ } ,
12+ optimization : {
13+ runtimeChunk : "single" ,
14+ splitChunks : {
15+ cacheGroups : {
16+ dep : {
17+ chunks : "all" ,
18+ test : path . resolve ( __dirname , "shared.js" ) ,
19+ enforce : true
20+ }
21+ }
22+ }
23+ }
24+ } ;
You can’t perform that action at this time.
0 commit comments