Create Block: Streamline experience for working with multiple blocks and shared assets #68190
Labels
[Status] In Progress
Tracking issues with work in progress
[Tool] Create Block
/packages/create-block
[Tool] WP Scripts
/packages/scripts
[Type] Tracking Issue
Tactical breakdown of efforts across the codebase and/or tied to Overview issues.
Today,
@wordpress/create-block
is too optimized for the specific use case of developing a single block as a WordPress plugin. Things quickly get more complicated when another block is needed or a custom JavaScript is integrated to extend the block editor. This issue will track necessary enhancements and bug fixes to resolve the outstanding problems that need to be addressed to streamline the experience.Current tasks
block.json
file, we could change the strategy. Developers, when using the source directory should only reference source files. The build process would detect them as entry points and updateblock.json
accordingly so everything is magically configured inside the build folder.Plans for easier build command customization
This plan builds upon the idea proposed by @youknowriad in #66466 (comment).
I'm using examples of custom webpack configs @justintadlock and @ndiego used in their projects to explain requirements. I validated how much the new CLI syntax could remove the need to deal with webpack internals, and I got very positively surprised how quickly I could map it to the idea discussed. Here is a summary.
Blog post example
This is how the revised command could look for the config overrides included in the blog post Getting and setting Block Binding values in the Editor.
I was also surprised to learn that I could run the command successfully with the current version of WP Scripts.
Note: I tried also the following
npx wp-scripts build editor.js --webpack-src-dir=resources/js --output-path=public/js
. However,--webpack-src-dir
isn't integrated with the syntax for file paths, they are all relative to the current working directory.Social Sharing block example
For the Social Sharing block, the command in the future would look as follows:
Note: All paths by default would get resolved from the current working directory, so
src
needs to be explicitly passed to avoid the case where they end up inside build/src/*.As of today, the following should work, too:
Note: It would ensure all PHP files get copied from
src
tobuild
directory. Both are considered default settings today in the default webpack config when no files are listed.block.json
files get automatically detected and related JS set as entry points.Block Visibility plugin
Another config is for Block Visibility. In the future, it could be handled with the following:
The custom config is required today, because there is no support for CSS as entry points. This PR adds this concept. I'm not entirely sure how the file path syntax fits here. It might even work out of the box for the syntax provided above. It won't work without small tweaks for a simplified version like
npx wp-scripts build ./editor.css
because it assumes the extension is.js
.X3P0: Ideas theme
A more real-world example of what is necessary to do with themes. Here’s the webpack.config.js. This one is very complex as it also handles fonts and media. Something like that might work one day:
Important note: I don’t know how far we can go with these globs. The challenge is mostly for the part that maps the paths to entry points.
The text was updated successfully, but these errors were encountered: