Skip to content

Commit

Permalink
add comments to webpack entrypoint function (#30629)
Browse files Browse the repository at this point in the history
  • Loading branch information
BreadGuy007 committed Apr 9, 2021
1 parent 505a1e1 commit 486ae23
Showing 1 changed file with 17 additions and 5 deletions.
22 changes: 17 additions & 5 deletions webpack.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,18 +65,30 @@ const stylesTransform = ( content ) => {
return content;
};

/*
* Matches a block's name in paths in the form
* src/<blockName>/frontend.js
*/
const blockNameRegex = new RegExp( /(?<=src\/).*(?=(\/frontend))/g );

const createEntrypoints = () => {
/*
* Returns an array of paths to frontend.js files within the block-directory package.
* These paths can be matched by the regex `blockNameRegex` in order to extract
* the block's name.
*
* Returns an empty array if no files were found.
*/
const scriptPaths = fastGlob.sync(
'./packages/block-library/src/**/frontend.js',
{
ignore: [ '**/build*/**' ],
}
'./packages/block-library/src/**/frontend.js'
);

/*
* Go through the paths found above, in order to define webpack entry points for
* each block's frontend.js file.
*/
const scriptEntries = scriptPaths.reduce( ( entries, scriptPath ) => {
const [ blockName ] = scriptPath.match( blockNameRegex ) || [];
const [ blockName ] = scriptPath.match( blockNameRegex );

return {
...entries,
Expand Down

0 comments on commit 486ae23

Please sign in to comment.