File tree Expand file tree Collapse file tree 5 files changed +40
-2
lines changed Expand file tree Collapse file tree 5 files changed +40
-2
lines changed Original file line number Diff line number Diff line change @@ -404,13 +404,35 @@ class Encore {
404
404
return this ;
405
405
}
406
406
407
+ /**
408
+ * Tell Webpack to "split" your entry chunks.
409
+ *
410
+ * This will mean that, instead of adding 1 script tag
411
+ * to your page, your server-side code will need to read
412
+ * the entrypoints.json file in the build directory to
413
+ * determine the *multiple* .js (and .css) files that
414
+ * should be included for each entry.
415
+ *
416
+ * This is a performance optimization, but requires extra
417
+ * work (described above) to support this.
418
+ *
419
+ * @returns {Encore }
420
+ */
421
+ splitEntryChunks ( ) {
422
+ webpackConfig . splitEntryChunks ( ) ;
423
+
424
+ return this ;
425
+ }
426
+
407
427
/**
408
428
* Configure the optimization.splitChunks configuration.
409
429
*
410
430
* https://webpack.js.org/plugins/split-chunks-plugin/
411
431
*
412
432
* Encore.configureSplitChunks(function(splitChunks) {
413
433
* // change the configuration
434
+ *
435
+ * splitChunks.minSize = 0;
414
436
* });
415
437
*
416
438
* @param {function } callback
Original file line number Diff line number Diff line change @@ -87,6 +87,7 @@ class WebpackConfig {
87
87
this . stylusLoaderOptionsCallback = ( ) => { } ;
88
88
this . babelConfigurationCallback = ( ) => { } ;
89
89
this . cssLoaderConfigurationCallback = ( ) => { } ;
90
+ this . shouldSplitEntryChunks = false ;
90
91
this . splitChunksConfigurationCallback = ( ) => { } ;
91
92
this . vueLoaderOptionsCallback = ( ) => { } ;
92
93
this . eslintLoaderOptionsCallback = ( ) => { } ;
@@ -319,6 +320,10 @@ class WebpackConfig {
319
320
this . cssLoaderConfigurationCallback = callback ;
320
321
}
321
322
323
+ splitEntryChunks ( ) {
324
+ this . shouldSplitEntryChunks = true ;
325
+ }
326
+
322
327
configureSplitChunks ( callback ) {
323
328
if ( typeof callback !== 'function' ) {
324
329
throw new Error ( 'Argument 1 to configureSplitChunks() must be a callback function.' ) ;
Original file line number Diff line number Diff line change @@ -361,7 +361,9 @@ class ConfigGenerator {
361
361
optimization . namedModules = true ;
362
362
}
363
363
364
- let splitChunks = { } ;
364
+ let splitChunks = {
365
+ chunks : this . webpackConfig . shouldSplitEntryChunks ? 'all' : 'async'
366
+ } ;
365
367
if ( this . webpackConfig . sharedCommonsEntryName ) {
366
368
const cacheGroups = { } ;
367
369
cacheGroups [ this . webpackConfig . sharedCommonsEntryName ] = {
Original file line number Diff line number Diff line change @@ -1249,8 +1249,8 @@ module.exports = {
1249
1249
config . setPublicPath ( '/build' ) ;
1250
1250
// enable versioning to make sure entrypoints.json is not affected
1251
1251
config . enableVersioning ( ) ;
1252
+ config . splitEntryChunks ( ) ;
1252
1253
config . configureSplitChunks ( ( splitChunks ) => {
1253
- splitChunks . chunks = 'all' ;
1254
1254
splitChunks . minSize = 0 ;
1255
1255
} ) ;
1256
1256
Original file line number Diff line number Diff line change @@ -134,6 +134,15 @@ describe('Public API', () => {
134
134
135
135
} ) ;
136
136
137
+ describe ( 'splitEntryChunks' , ( ) => {
138
+
139
+ it ( 'must return the API object' , ( ) => {
140
+ const returnedValue = api . splitEntryChunks ( ) ;
141
+ expect ( returnedValue ) . to . equal ( api ) ;
142
+ } ) ;
143
+
144
+ } ) ;
145
+
137
146
describe ( 'configureSplitChunks' , ( ) => {
138
147
139
148
it ( 'must return the API object' , ( ) => {
You can’t perform that action at this time.
0 commit comments