Subscribe to a Premium Development Newsletter by TheDevCouple! What is TheDevTakeaway?

šŸŽ‰Ā Excited to release theĀ create-guten-blockĀ toolkit today. In this post, I am going to share what isĀ create-guten-blockĀ (cgb), what is the motivation & philosophy behind building this dev-toolbox, and the story of how I am releasing it to the public after ~200 commits and ~90 version releases. Let’s start with intro first…

šŸ™ŒĀ IntroducingĀ Create Guten Block!Create Guten Block Toolkit: Build Custom Gutenberg Blocks 1 create guten block CommunityCreate Guten Block Toolkit: Build Custom Gutenberg Blocks 2 create guten block Community

create-guten-block (🌟 at GitHub for updates) is a zero-configuration dev-toolkit (#0CJS) to develop WordPress Gutenberg blocks in a matter of minutes without configuring React, Webpack, ES6/7/8/Next, ESLint, Babel, etc.

Create Guten Block is not like otherĀ starter-kitsĀ orĀ boilerplates. It’s a developer’s toolbox which is continuously updated. Since it has zero-configuration, you can always update it without any changes in your code. That’s actually why I built it.

šŸ‘‹

Hey, don’t forget to star 🌟 it at GitHub for updates, to show appreciation, and do report back any issues you face.

šŸš€Ā create-guten-blockĀ is:

  • šŸ„žĀ Versioned āœ“
  • 🤠 Updatable āœ“
  • šŸ—ƒĀ Set of sane-defaults āœ“
  • šŸŽĀ ONE singleĀ cgb-scriptsĀ dependency āœ“

But what is it?!

Well, it’s a create-guten-block is a way for you to start building Gutenberg blocks without having to configure or setup anything. It’s a zero-config-js #0CJS toolkit with a single dependency in your projects — which will stay up to date.

Create Guten Block Toolkit: Build Custom Gutenberg Blocks 3 create guten block Community

What’s Included?

Your dev-environment will have everything you need to build a modern next-gen WordPress Gutenberg plugin:

  • React, JSX, and ES6 syntax support.
  • Webpack dev/production build process behind the scene.
  • Language extras beyond ES6 like the object spread operator.
  • Auto-prefixed CSS, so you don’t needĀ -webkitĀ or other prefixes.
  • A build script to bundle JS, CSS, and images for production with source-maps.
  • Hassle-free updates for the above tools with a single dependencyĀ cgb-scripts.

šŸ”°

The tradeoff is that these tools are preconfigured to work in a specific way. If your project needs more customization, you can ā€œejectā€ and customize it, but then you will need to maintain this configuration.

Create Guten Block Toolkit: Build Custom Gutenberg Blocks 4 create guten block Community

Philosophy

  • One Dependency:Ā There is just one build dependency. It uses Webpack, Babel, ESLint, and other amazing projects, but provides a cohesive curated experience on top of them.
  • No Configuration Required:Ā You don’t need to configure anything. A reasonably good configuration of both development and production builds is handled for you so you can focus on writing code.
  • No Lock-In:Ā You canĀ ejectĀ to a custom setup at any time. Run a single command, and all the configuration and build dependencies will be moved directly into your project, so you can pick up right where you left off.

Create Guten Block Toolkit: Build Custom Gutenberg Blocks 5 create guten block Community

WhyĀ create-guten-block?

Well, it’s really hard to configure things like Webpack, React, ES 6/7/8/Next, ESLint, Babel, etc. before you — even start writing — aĀ Hello WorldGutenberg block. Then there’s the fact that you have to maintain and constantly update your configuration with all the new tools and growth in the JavaScript community — that’s not an easy thing to do.

create-guten-blockĀ hides all this configuration away in an optimized package that we callĀ cgb-scripts. This package is the only dependency in your projects. We keepĀ cgb-scriptsĀ up to date while you go ahead and create the next best WordPress themes and plugins.

šŸ¦‘

ā€œI’ve heard from several people that they’ve consolidated their companies tool dependencies into a single package and this worked really well for them.ā€ — @Dan_Abramov

So, that’s what I dreamt about for the next couple of months.Ā How do I solve this problem for the WordPress community, eh?

Create Guten Block Toolkit: Build Custom Gutenberg Blocks 6 create guten block Community

After buildingĀ WPGulpĀ andĀ Gutenberg BoilerplateĀ and lot of other open source software that thousands of developers are using — I started receiving lots of feedback on how it’s limiting in its architecture which is complex — and by the way, these boilerplates went stale quite a few times.

I knew this was not right.

Ā 

šŸ™ˆšŸ™‰šŸ™Š

Developers told me that they built Gutenberg blocks with ES5 because the amount of time required to configure, set up, and learn tools like Babel, Webpack, ESLint, Prettier, etc. wasn’t worth it. And I was like whaaaat?!
So, yes! I went ahead and built a solution — a zero-config-js #0CJS WordPress developers’ toolkit calledĀ create-guten-block!Ā Enough talk, let’s stop it right here and actually explore the toolkit.
Create Guten Block Toolkit: Build Custom Gutenberg Blocks 7 create guten block Community

<

div>

GETTING STARTED!

It’s really easy to get started withĀ create-guten-block. Just install it as a global module and run it to create your next-gen Gutenberg block plugin for WordPress.

🦊

Did I tell you toĀ star 🌟 it at GitHub for updatesĀ and to show appreciation or to report back anyĀ issuesĀ you face? Hmm… lemme think?!

OK! OK!Ā Let’s get you started!

→ STEP #0

If you don’t haveĀ Node.jsĀ +Ā npmĀ installed then read this step, otherwise jump to the Step #1 below.
In case you are an absolute beginner to the world ofĀ Node.js, JavaScript, andĀ npmĀ packages — all you need to do is go to the Node’s siteĀ download + installĀ Node on your system. This will install bothĀ Node.jsĀ andĀ npm, i.e., node package manager — the command line interface of Node.js.

You can verify the install by opening your terminal app and typing…

node -v
# Results into v9.4.0 — make sure you have Node >= 8 installed.

and then…

npm -v
# Results into 5.6.0 — make sure you have npm >= 5.2 installed.

→ STEP #1

InstallĀ create-guten-blockĀ globally on your system.

You’ll need to have Node >= 8 on your local development machine (but it’s not required on the server). You can useĀ nvm(macOS/Linux) orĀ nvm-windowsĀ to easily switch Node versions between different projects.

npm install create-guten-block --global

Create Guten Block Toolkit: Build Custom Gutenberg Blocks 8 create guten block Community

Hold on, it’ll take a couple of minutes to install.

→ STEP #2

Now all you have to do is create a Gutenberg block and start building. It’s done by running theĀ create-guten-blockĀ command and providing it with a unique name for a WordPress plugin that will get created. The name can a single word or hyphenated multiple words.

āš ļø

Make sure to run this command in your local WordPress install’s plugins folder i.e. /local_dev_site.tld/wp-content/plugins/ folde — since this command will produce a WordPress Gutenberg block plugin that you can go to WP Admin ā–¶ļøŽ Plugins to activate.

Now let’s run the following command.

create-guten-block my-block

Create Guten Block Toolkit: Build Custom Gutenberg Blocks 9 create guten block Community

It will create a directory calledĀ my-blockĀ inside the current folder. Inside that directory, it will generate the initial project structure and install the transitive dependencies:

INSIDE: /local_dev_site.tld/wp-content/plugins/my-block

ā”œā”€ā”€ plugin.php
ā”œā”€ā”€ package.json
ā”œā”€ā”€ README.md
|
ā”œā”€ā”€ dist
|  ā”œā”€ā”€ blocks.build.js
|  ā”œā”€ā”€ blocks.editor.build.css
|  └── blocks.style.build.css
|
└── src
   ā”œā”€ā”€ block
   |  ā”œā”€ā”€ block.js
   |  ā”œā”€ā”€ editor.scss
   |  └── style.scss
   |
   ā”œā”€ā”€ blocks.js
   ā”œā”€ā”€ common.scss
   └── init.php

No configuration or complicated folder structures, just the files you need to build your app.

→ STEP #3

Once the installation is done, you can open your project folder and run the start script.

Let’s do that.

cd my-block
npm start

You can also useĀ yarn startĀ if that’s your jam.

Create Guten Block Toolkit: Build Custom Gutenberg Blocks 10 create guten block Community

This runs the plugin in development mode. To produce production code runĀ npm run build. You will see the build messages, errors, and lint warnings in the console.

šŸ’Æ

And just like that, you’re building your next WordPress plugin with Gutenberg, React.js, ES 6/7/8/Next, transpiled with Babel, which also has ESLint configurations for your code editor to pick up and use automatically.

Create Guten Block Toolkit: Build Custom Gutenberg Blocks 11 create guten block Community

Workflow!

There are just three scripts that you can use in yourĀ create-guten-blockĀ workflow. With these three scripts, you can develop, build, and eject your plugin.

šŸ‘‰Ā npm start

  • Use to compile and run the block in development mode.
  • Watches for any changes and reports back any errors in your code.

šŸ‘‰Ā npm run build

  • Use to build production code for your block insideĀ distĀ folder.
  • Runs once and reports back the gzip file sizes of the produced code.

šŸ‘‰Ā npm run eject

  • Use to eject your plugin out ofĀ create-guten-block.
  • Provides all the configurations so you can customize the project as you want.
  • It’s a one-way street,Ā ejectĀ and you have to maintain everything yourself.
  • You don’t normally have toĀ ejectĀ a project because by ejecting you lose the connection withĀ create-guten-blockĀ and from there onwards you have to update and maintain all the dependencies on your own.

That’s about it.

Create Guten Block Toolkit: Build Custom Gutenberg Blocks 12 create guten block Community

TL;DR

Too long, didn’t read? Here’s a shorter version.

Open the terminal app and run the following commands.

  • āœ…Ā Install/Update:Ā npm install create-guten-block --global
  • šŸ”°Ā Create:Ā create-guten-block my-block — Run inside local WP install E.g.Ā /wp.local/wp-content/plugins/Ā directory.
  • šŸ“‚Ā Browse:Ā cd my-block — Open the newly created plugin directory.
  • ā™»ļøĀ Run:Ā npm start — For development.
  • šŸ“¦Ā Run:Ā npm run build — For production build.
  • āĀ Run:Ā npm run eject — To customize, update, and maintain all by yourself.

Create-Guten-Block has been tested to work on macOS, but must also work on Windows, and Linux. If something doesn’t work, kindly fileĀ an issue →

Create Guten Block Toolkit: Build Custom Gutenberg Blocks 13 create guten block Community

Updating to New Releases

Create Guten Block is divided into two packages:

  1. create-guten-blockĀ is a global command-line utility that you use to create new WP Gutenberg plugins.
  2. cgb-scriptsĀ is a development dependency in the generated plugin projects.
npm install create-guten-block --global

You almost never need to updateĀ create-guten-blockĀ itself: it delegates all the setup toĀ cgb-scripts. But as this project matures, there might be a few changes over time and you can re-run the global install.

When you runĀ create-guten-block, it always creates the project with the latest version ofĀ cgb-scriptsĀ so you’ll get all the new features and improvements in newly created plugins automatically.

āœ…Ā To update an existing project to a new version ofĀ cgb-scripts, open theĀ changelog, find the version you’re currently on (check package.json in your plugin’s folder if you’re not sure), and apply the migration instructions for the newer versions.

šŸ”°Ā In most cases bumping theĀ cgb-scriptsĀ version in the package.json and runningĀ npm installĀ in this folder should be enough, but it’s good to consult theĀ changelogĀ for potential breaking changes.

We commit to keeping the breaking changes minimal so you can upgradeĀ cgb-scriptsĀ painlessly.

Create Guten Block Toolkit: Build Custom Gutenberg Blocks 14 create guten block Community

Changelog

Read what’sĀ šŸ“¦Ā new,Ā šŸ‘ŒĀ improved,Ā šŸ›Ā fixed, and ifĀ šŸ“–Ā docs got updated.

šŸ‘‰Ā  Go read the entire changelog at this link — CGB Changelog →

Nothing’s ever complete, so bear with us while we keep iterating towards a better future.

'Coz every night I lie in bed
The brightest colors fill my head
A million dreams are keeping me awake
I think of what the world could be
A vision of the one I see
A million dreams is all it's gonna take
A million dreams for the world we're gonna make ...

… listen to → A million dreams!

Create Guten Block Toolkit: Build Custom Gutenberg Blocks 15 create guten block Community

Hello, we’re theĀ WordPress Couple!

I (Ahmad Awais) am a Full Stack Web Developer and a regular core contributor at WordPress. My significant other (Maedah Batool) is a Technical Project Manager, and she’s also a WordPress Core Contributor. Together with ourĀ team, we run theĀ TheDevCouple.com.

If you’d like to get insights into our love for open source software, professional full stack development, WordPress community, the growth of JavaScript or growing a family, building, and bootstrapping a business, then subscribe to our premium newsletter called ↣ The WordPress Takeaway!

Support our Open Source Projects!Ā šŸŽ©

If you’d like us to keep producing professional free and open source software (FOSS). ConsiderĀ paying for an hour of my dev-time. We’ll spend two hours on open source for each contribution. Yeah, that’s right, you pay for one hour and get both of us to spend an hour as a thank you.

Create Guten Block Toolkit: Build Custom Gutenberg Blocks 16 create guten block Community

Project Backers &Ā WPCouple PartnersĀ āš”ļø

This FOSS (free and open source software) project is built, updated and maintained with the help of awesome businesses listed below. Without the support from these amazing companies/individuals, this project would not have been possible. Make sure you check out their awesome services and products. They’ve earned it.Ā šŸŽ–

— What/How?Ā Read more about it →

Create Guten Block Toolkit: Build Custom Gutenberg Blocks 17 create guten block Community

Create Guten Block Toolkit: Build Custom Gutenberg Blocks 18 create guten block Community

License & Attribution

MIT © Ahmad Awais.

This project is inspired by the work of more people than I could mention here. But thank you,Ā Dan AbramovĀ for Create React App,Ā Andrew Clark,Ā Sophie AlpertĀ from React.js team,Ā Wes BosĀ for awesome courses forĀ React,Ā ES6, andĀ NodeĀ beginners.Ā Kent C. DoddsĀ for his open source evangelism, WordPress Core Contributors,Ā GaryĀ for keeping everyone sane,Ā Gutenberg developersĀ Matias,Ā Riad,Ā Andrew,Ā Joen,Ā GregĀ and contributors, and other WordPress community members likeĀ ZacĀ for hisĀ course on Gutenberg, and also my friendĀ MortenĀ for all the #Guten-motivation,Ā Icons8Ā for the awesome icons,Ā MaedahĀ for managing this project, and to everyone I forgot.

Create Guten Block Toolkit: Build Custom Gutenberg Blocks 19 create guten block Community

What’s Next?

Yes, that’s not all done, yet. I have managed to change the codebase and release many updates by now, before actually announcing a stable release.

The next step is to get this toolkit tested and mature the entire app to release versionĀ 2.0.0Ā for that not only do I need yourĀ support, I ask that you hop on board and contribute — that’s the only way forward.

I have created a GitHub issue with the title ofĀ šŸš€Ā Creat Guten Block 2.0 Goals + Call for Contributors! In there I have listed a rough roadmap to versionĀ 2.0.0.

Goals listed below — without any order of priority:

  • šŸŽ–Ā At the time of writing,Ā create-guten-blockĀ and sister scripts have received 3,000+ downloads
  • šŸ’ÆĀ Get folks on React, Webpack, and Babel teams to review the configurations for best possible results
  • āš”ļøĀ Go beyond React — with Preact, Inferno, Marko, Angular, Vue, etc.Ā JavaScript frameworks
  • šŸ“–Ā More examples need to be documented. Especially a Multi-block example which is easy
  • šŸ”°Ā Babel 7, Webpack 4, upgrades to follow in the next major version of create-guten-block
  • 🚧 ESLint integration needs a refresher — ESLint + Prettier setup is already WIP
  • ⛓ Refactor code into small modules and maybe make small npm packages
  • šŸ“‘Ā Improve inline documentation throughout the codebase
  • šŸ’ŽĀ Build moreĀ cgb-dev-utils — separation of concerns
  • šŸ“¤Ā Possible integrations: Service Workers from Google
  • šŸ“£Ā Possible integrations: Progressive Web Apps
  • šŸ‘»Ā .envĀ file limited set of customizations
  • šŸ¤“Ā Allow custom forks ofĀ cgb-scripts
  • šŸ› Ā Improve the entire Webpack defaults
  • šŸ—ƒĀ Webpack file handling done right
  • šŸ“¹Ā Webpack image optimization
  • šŸ‘¹Ā Webpack Uglify ES6 plugin
  • āš™Ā Webpack + BrowserSync
  • šŸ”°Ā Multi Block Examples
  • šŸ’ Ā Automated test suit
  • šŸ¤”Ā Other stuff? #Suggest
  • šŸ™ŒĀ PR’s welcomed

What do you say? Comment below. And make sure you’ve stargazed 🌟 the GitHub repo for updates!

šŸ™Œ

BuildingĀ create-guten-blockĀ was a lot of work. It’s easily one of the best software I’ve written and I have exciting improvements coming.

šŸ”„Ā It would mean the world to me if youĀ Tweet about it, try it out, and contribute.

Peace! āœŒļø

Feel free to reach out and sayĀ šŸ‘‹Ā on TwitterĀ @MrAhmadAwais


Create Guten Block Toolkit: Build Custom Gutenberg Blocks 20 create guten block Community

UPDATES

šŸ™Œ

SUBSCRIBE TO DEVELOPERS TAKEAWAY!

A Premium Development Newsletter by TheDevCouple! What is TheDevTakeaway?

Meet Ameer Dagha the man behind ReviewsPK Rank Math Plugin For Your SEO Needs WP Engine Smart Plugin Manager – One Plugin For All Your Plugin Updates
There are currently no comments.

šŸ™Œ You must have something to say here...