File tree Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Expand file tree Collapse file tree 2 files changed +46
-0
lines changed Original file line number Diff line number Diff line change @@ -45,6 +45,7 @@ const tmp = require('tmp');
45
45
const fs = require ( 'fs' ) ;
46
46
const path = require ( 'path' ) ;
47
47
const stringEscaper = require ( './utils/string-escaper' ) ;
48
+ const crypto = require ( 'crypto' ) ;
48
49
49
50
class ConfigGenerator {
50
51
/**
@@ -365,6 +366,25 @@ class ConfigGenerator {
365
366
let splitChunks = {
366
367
chunks : this . webpackConfig . shouldSplitEntryChunks ? 'all' : 'async'
367
368
} ;
369
+
370
+ // hash the split filenames in production to protect exposing entry names
371
+ if ( this . webpackConfig . shouldSplitEntryChunks && this . webpackConfig . isProduction ( ) ) {
372
+ // taken from SplitChunksPlugin
373
+ const hashFilename = name => {
374
+ return crypto
375
+ . createHash ( 'md4' )
376
+ . update ( name )
377
+ . digest ( 'hex' )
378
+ . slice ( 0 , 8 ) ;
379
+ } ;
380
+
381
+ splitChunks . name = function ( module , chunks , cacheGroup ) {
382
+ const names = chunks . map ( c => c . name ) ;
383
+
384
+ return cacheGroup + '~' + hashFilename ( names . join ( '~' ) ) ;
385
+ } ;
386
+ }
387
+
368
388
if ( this . webpackConfig . sharedCommonsEntryName ) {
369
389
const cacheGroups = { } ;
370
390
cacheGroups [ this . webpackConfig . sharedCommonsEntryName ] = {
Original file line number Diff line number Diff line change @@ -824,4 +824,30 @@ describe('The config-generator function', () => {
824
824
} ) ;
825
825
} ) ;
826
826
} ) ;
827
+
828
+ describe ( 'Test shouldSplitEntryChunks' , ( ) => {
829
+ it ( 'Not production' , ( ) => {
830
+ const config = createConfig ( ) ;
831
+ config . outputPath = '/tmp/public/build' ;
832
+ config . setPublicPath ( '/build/' ) ;
833
+ config . splitEntryChunks ( ) ;
834
+
835
+ const actualConfig = configGenerator ( config ) ;
836
+ expect ( actualConfig . optimization . splitChunks . chunks ) . to . equal ( 'all' ) ;
837
+ expect ( actualConfig . optimization . splitChunks . name ) . to . be . undefined ;
838
+ } ) ;
839
+
840
+ it ( 'Yes production' , ( ) => {
841
+ const runtimeConfig = new RuntimeConfig ( ) ;
842
+ runtimeConfig . environment = 'production' ;
843
+ const config = createConfig ( runtimeConfig ) ;
844
+ config . outputPath = '/tmp/public/build' ;
845
+ config . setPublicPath ( '/build/' ) ;
846
+ config . splitEntryChunks ( ) ;
847
+
848
+ const actualConfig = configGenerator ( config ) ;
849
+ expect ( actualConfig . optimization . splitChunks . chunks ) . to . equal ( 'all' ) ;
850
+ expect ( actualConfig . optimization . splitChunks . name ) . to . be . a ( 'function' ) ;
851
+ } ) ;
852
+ } ) ;
827
853
} ) ;
You can’t perform that action at this time.
0 commit comments