Skip to content

Commit

Permalink
Build blocks as separate entrypoints
Browse files Browse the repository at this point in the history
  • Loading branch information
jsnajdr committed Dec 15, 2023
1 parent ed35dc9 commit 5dd5ad2
Showing 1 changed file with 32 additions and 0 deletions.
32 changes: 32 additions & 0 deletions tools/webpack/blocks.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,25 @@ const createEntrypoints = () => {
}, {} );
};

const createEditorEntrypoints = () => {
const blockInitScriptPaths = fastGlob.sync(
'./packages/block-library/build-module/**/init.js'
);

const entrypoints = {};
for ( const scriptPath of blockInitScriptPaths ) {
const result = scriptPath.match(
/build-module\/(?<filename>.*)\/init\.js$/
);
if ( ! result ) {
continue;
}
entrypoints[ result.groups.filename + '/editor' ] = scriptPath;
}

return entrypoints;
};

module.exports = [
{
...baseConfig,
Expand Down Expand Up @@ -220,4 +239,17 @@ module.exports = [
} ),
].filter( Boolean ),
},
{
...baseConfig,
name: 'editor',
entry: createEditorEntrypoints(),
output: {
devtoolNamespace: 'wp',
filename: './build/block-library/blocks/[name].min.js',
path: join( __dirname, '..', '..' ),
},
plugins: [ ...plugins, new DependencyExtractionWebpackPlugin() ].filter(
Boolean
),
},
];

0 comments on commit 5dd5ad2

Please sign in to comment.