-
Notifications
You must be signed in to change notification settings - Fork 4.3k
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
[Create Block] Allow explicit target for block creation #44717
Comments
Likely related to #25188 |
@colorful-tones thank you for taking the time to put this together with such detail! Here are my thoughts.
The original purpose of the package is to create a plugin that contains a block. That’s the recommended way to create blocks and how they need to be packaged to be submitted to the plugin repo. The
In this case, creating the block is secondary because we already have the plugin scaffolded and we only need to scaffold new block files.
This would fundamentally change the default behavior of the package from scaffolding a full plugin with a single block to only scaffolding the block files. For users new to the tool or using the tool to learn block development, that would be an extremely frustrating and confusing experience as it would produce files that essentially do nothing on their own. IMO, the default behavior ( which is a new plugin with a block ) should not require a flag to take place. That feels like a bad developer experience to me.
Without flag change, these commands would be very similar. Beyond saving a few keystrokes, I don't see a huge benefit here.
There have also been some discussions ( I can't find the issue - @gziolo? ) around providing a way to generate multiple blocks at once as well by passing a list of names - which would simplify this command even more ie.:
This is a great idea. Being able to target where the block is scaffolded in either mode of the package is great idea. Currently, the |
I agree and understand this premise, but quickly get hung up on the fact that it is called
I'm going to take a pass at editing and refining this Issue's current proposal to streamline to solely this feature request, as I do think it would be beneficial. Thanks for all the insight and feedback @ryanwelcher |
Ok, I've streamlined the proposed solution. The initial one was too broad. Thanks. |
@colorful-tones, thank you for opening this issue and making the effort to explain your use case. I agree that it would be great to have more control over where to create the block. Initially, we didn't have any way to distinguish what belongs to the block and what is part of the plugin or project. We changed that a few months back in the anticipation to add support even for multiple blocks. As of today, you can override where to put block-related templates with:
It's too simple for now and it doesn't support anything that would make the path dynamic, but we could add a special case like: folderName: 'src/$block-slug', and the dynamically replace To support multiple blocks in Create Block, we might also need to introduce the distinction between the plugin slug and the block slug, because each block needs an unique name. It's all doable and part of the discussion we had in #25188. |
I agree with @colorful-tones in regards to the structure in the initial installation having nested sub-directories in the src directory. However, I think it should be achieved in one command rather than multiple lines :
Without a block-name flag could just be the default installation. I also agree with @ryanwelcher that semantically, the additional "--no-plugin" / "--plugin" flags might cause confusion and is unnecessary. I'm all for ease-of-use and clarity. It seems like the immediate need is to have better documentation on how to structure the directory to accommodate multiple blocks. |
All the WordPress dev want to create block with php, js, css whitout npm and build worflow. If you make something like this all the community will love Gutenberg and WordPress again. This could change everything and make full site editing grow fast, think about that. I went to WordCamp Italy, yesterday and all the devs agree with that, cheers keep the good :) |
It is entirely possible to create a custom block without a build process now. You can scaffold a block using the |
Ok but we still need node and a local environment, right? |
You don't need node to build the block, there is no build process using the As for a local environment, typically you'd want to have a local WordPress installation set up and running to test your code changes, is that what you're referring to? |
@afmarchetti you can have a look at these examples in the Gutenberg Examples repo for blocks without a build process. |
@ryanwelcher thanks :-) i tried and test the example here (recipe block): it's a lot of code to create such a simple html structure, in block studio you can do something like this to create block templates: Every WordPress dev will love a solution like this, quick, easy, simple. I know that is not super easy create a solution like this, but this type of development experience will solve a lot of problems of wp devs community and definitely unlock the power of Gutenberg... Thanks for your time |
+1 for making it easier to create plugins with more than one block. I don't think the majority creates blocks with the purpose of submitting single block plugins to the wordpress.org plugin directory. |
+1 to this. My current workflow is constantly |
@ryanwelcher opened some time ago a PR that implements the requested feature: Would that solve the issue for you? The PR mostly needs some testing and I can help with reviewing the code if necessary. |
I can update the PR to address the merge conflicts. Be happy to get this merged. |
Thanks @ryanwelcher @gziolo - I tested it and added a few comments. |
What problem does this address?
I love that the
@wordpress/create-block
package allows the user to scaffold out a plugin for their blocks and even has templates to allow developers to extend and create their own block template packages. ❤️ ❤️ 🤯I believe it is a high-priority need for developers to be able to create this type of structure in their plugin to support multiple blocks:
One can technically accomplish this with
@wordpress/create-block
as it stands, but there are a few awkward steps to get there, which hinder its overall potential.To achieve that structure, you have to:
npx @wordpress/create-block my-block-plugin
, which outputs:Now, you must manually move the
src/block.json
into a unique block directory:src/block-one/block.json
, or delete it and run@wordpress/create-block
again in another directory and with the--no-plugin
flag.Proposed solution: add
--target
flagWe add an optional flag for
--target
, which would allow developers to pass a block target within the.src/
, e.g.--target block-one/
, which would result in:src/block-one/block.json
. If no--target
then theslug
should be the fallback used to create the target directory. Then,npx @wordpress/create-block block-one
would result in the creation ofsrc/block-one/block.json
still.These changes would allow builders to run the following and have a plugin:
and get the following:
The text was updated successfully, but these errors were encountered: