Skip to content

Commit

Permalink
build: Do not use webpack4 APIs (#58299)
Browse files Browse the repository at this point in the history
* Disable webpack backCompat

* Use chunks as a set

* Use chunk.files as a set

* Refactor usage of webpack4 APIs
  • Loading branch information
scinos authored Nov 23, 2021
1 parent 04cb032 commit 10999f7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
18 changes: 10 additions & 8 deletions build-tools/webpack/generate-chunks-map-plugin.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,18 +18,20 @@ class GenerateChunksMapPlugin {
// Generate chunks map
const { chunks } = compilation;

const chunksMap = chunks.reduce( ( map, chunk ) => {
const files = chunk.files;
const name = files.find( ( file ) => /\.js$/.test( file ) ) || files[ 0 ];
const modules = [ ...chunk.modulesIterable ]
const chunksMap = {};
for ( const chunk of chunks ) {
// This logic assumes there is only one `.js`. If there are more than one `.js` file linked to a chunk,
// this will be non deterministic as `chunk.files` iteration order is not guaranteed.
const name = Array.from( chunk.files ).find( ( file ) => /\.js$/.test( file ) );
if ( ! name ) continue;

const modules = [ ...compilation.chunkGraph.getChunkModulesIterable( chunk ) ]
.reduce( ( acc, item ) => acc.concat( item.modules || item ), [] )
.map( ( { userRequest } ) => userRequest && path.relative( '.', userRequest ) )
.filter( ( module ) => !! module );

map[ name ] = modules;

return map;
}, {} );
chunksMap[ name ] = modules;
}

// Write chunks map
fs.writeFileSync( this.output, JSON.stringify( chunksMap ) );
Expand Down
4 changes: 4 additions & 0 deletions client/webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -379,6 +379,10 @@ const webpackConfig = {
},
}
: {} ),

experiments: {
backCompat: false,
},
};

module.exports = webpackConfig;

0 comments on commit 10999f7

Please sign in to comment.