Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@wordpress/create-block: allow to not generate the plugin data (block.json, readme.txt, and plugin header information on the main php file) #23604

Closed
leoloso opened this issue Jul 1, 2020 · 3 comments
Labels
[Tool] Create Block /packages/create-block

Comments

@leoloso
Copy link

leoloso commented Jul 1, 2020

Is your feature request related to a problem? Please describe.
The @wordpress/create-block package is meant to create single-block plugins. However it can be easily adapted to also support the creation of blocks for a multi-block plugin.

In my case, I have a plugin with a CPT which relies on many custom blocks to input its information. For this case, the single-block plugin would not work. Additionally, since the blocks do not work outside of the CPT, there is no need to expose them in the block directory.

My current workflow to create the blocks for my plugin, located under folder blocks/, is the following:

  1. Under folder blocks/, run npm init @wordpress/block block-name for each block
  2. After generated, I delete files block.json, readme.txt and the plugin header information from within the main php file
  3. From my plugin's main php file, I require each block's main php file: require block-name/block-name.php

Step 2 above could be avoided, by having @wordpress/create-block already not produce these files/code.

Describe the solution you'd like
By default, have @wordpress/create-block running as currently. However, when executing the npm init @wordpress/block block-name command with an additional flag, for instance --autonomous-block, then adding the plugin information is skipped:

  • Files block.json and readme.txt are not generated
  • Plugin header information is not added to the main php file

This feature request could be tackled together with #23514

@leoloso
Copy link
Author

leoloso commented Jul 1, 2020

Please notice how each block in the multi-block plugin is autonomous: each has its own package.json, can have its own overriding webpack.config.js, and needs to be run npm run build to be compiled. This is a feature, not a bug. With this feature request, @wordpress/create-block will make this strategy easier to implement.

@gziolo gziolo added [Tool] Create Block /packages/create-block Needs Decision Needs a decision to be actionable or relevant labels Jul 3, 2020
@gziolo
Copy link
Member

gziolo commented Jul 3, 2020

Thanks for sharing this proposal. Indeed, it sounds like the tool might be more flexible in how it generates a configuration for the block. At the moment it’s very opinionated and optimized towards usage with Block Directory that is scheduled for release in WordPress 5.5. In the meantime, while we discuss this issue l, we should finish the functionality that allows easier integration with 3rd party templates.

@gziolo
Copy link
Member

gziolo commented Jan 5, 2021

It is now possible to create your own template that provides all the necessary templates. See:
https://github.com/WordPress/gutenberg/blob/master/packages/create-block/README.md#external-templates.

In addition to that, there are CLI arguments that allow enable or disable wp-scripts. See:
https://github.com/WordPress/gutenberg/blob/master/packages/create-block/README.md#usage

I hope it gives enough flexibility when building custom blocks that have different requirements 😄

I'm closing this issue, we can always reopen it if something is still missing or even better open a targeted issue. Thank you for your constant feedback and help to make the tooling better. Major props @leoloso ❤️

@gziolo gziolo closed this as completed Jan 5, 2021
@gziolo gziolo removed the Needs Decision Needs a decision to be actionable or relevant label Jan 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
[Tool] Create Block /packages/create-block
Projects
None yet
Development

No branches or pull requests

2 participants