scaffold-command
scaffold-command copied to clipboard
Scaffold block with ESNext support
Feature Request
- [x] Yes, I reviewed the contribution guidelines.
Describe your use case and the problem you are facing
Use case: Thanks to modern JavaScript workflows with the ESNext syntax, it is much more easier to write JavaScript code these days. Using webpack or Gulp or some other task runner to automate the build process for you, you can ship JavaScript code pretty quickly. Currently, wp scaffold block
allows us to scaffold the files required for creating a block. One standout feature that I think that WP-CLI has is the ability to either scaffold a block as a plugin or into a theme. This is something that npx @wordpress/create-block
cannot do.
However, WP-CLI scaffolds files as a ES5 template and without any preprocessor for the CSS. It would help speed up the development process for a lot of devs that want to keep things simple and put Gutenberg blocks that are specific to themes only.
Describe the solution you'd like
We can add an option (--template=esnext
or --template=es5
) to the wp scaffold block
command. The esnext
option would scaffold the general directory structure for a webpack based project, and then call in npm i
. The scaffolded files for esnext
can have a package.json
with all of the relevant information like developer dependencies and dependencies. We could also include the wp-script
scripts in the package.json so that users can just execute npm start
and npm build
.
I do realise that WordPress recommends not locking in users to themes with theme specific blocks. But for those of us that do a lot of custom WordPress development for our clients, this is mostly a non-issue as we also provide maintenance, and often take up redesigns a couple years down the lane for theme lock-in to be a thing.