Skip to content

Commit

Permalink
Auto populate chunk filenames based on named chunk ids
Browse files Browse the repository at this point in the history
  • Loading branch information
luisherranz committed Nov 7, 2023
1 parent adb5cb8 commit 9e94e67
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions tools/webpack/packages.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,11 +146,13 @@ module.exports = {
output: {
devtoolNamespace: 'wp',
filename: './build/[name]/index.min.js',
chunkFilename: ( { chunk } ) => {
if ( chunk.runtime === 'block-library' ) {
return './build/block-library/blocks/[name].min.js';
chunkFilename: ( { runtime, chunk: { id } } ) => {
if ( runtime === 'block-library' ) {
const rg = /build-module_([\w-]+)_edit/.exec( id );
const name = ( rg && rg[ 1 ] ) || id;
return `./build/block-library/blocks/${ name }/editor.js`;
}
return './build/' + chunk.runtime + '/[name].min.js';
return './build/' + runtime + '/[name].min.js';
},
path: join( __dirname, '..', '..' ),
devtoolModuleFilenameTemplate: ( info ) => {
Expand All @@ -163,6 +165,7 @@ module.exports = {
},
},
optimization: {
chunkIds: 'named',
splitChunks: {
cacheGroups: {
default: false,
Expand Down

0 comments on commit 9e94e67

Please sign in to comment.