{"id":79748,"date":"2020-02-28T13:58:38","date_gmt":"2020-02-28T13:58:38","guid":{"rendered":"https:\/\/make.wordpress.org\/core\/?p=79748"},"modified":"2020-02-28T23:57:07","modified_gmt":"2020-02-28T23:57:07","slug":"new-wordpress-create-block-package-for-block-scaffolding","status":"publish","type":"post","link":"https:\/\/make.wordpress.org\/core\/2020\/02\/28\/new-wordpress-create-block-package-for-block-scaffolding\/","title":{"rendered":"New @wordpress\/create-block package for block scaffolding"},"content":{"rendered":"<p class=\"wp-block-paragraph\"><em><span tabindex='0' class='glossary-item-container'>Block<span class='glossary-item-hidden-content'><span class='glossary-item-header'>Block<\/span> <span class='glossary-item-description'>Block is the abstract term used to describe units of markup that, composed together, form the content or layout of a webpage using the WordPress editor. The idea combines concepts of what in the past may have achieved with shortcodes, custom HTML, and embed discovery into a single consistent API and user experience.<\/span><\/span><\/span> scaffolding<\/em> is a shorthand term that describes the supporting directory structure you need for WordPress to recognize a block. Typically that directory includes files like <code>index.php<\/code>, <code>index.js<\/code>, <code>style.css<\/code> and perhaps others\u2014which in turn hold calls like <code>register_block_type<\/code>.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You\u2019ve likely noticed a lot of tools that aim to automate the scaffolding build\u2014or at least make it easier to build your own blocks. They\u2019re nothing new in the WordPress ecosystem. And there\u2019s even one in <span tabindex='0' class='glossary-item-container'>WP-CLI<span class='glossary-item-hidden-content'><span class='glossary-item-header'>WP-CLI<\/span> <span class='glossary-item-description'>WP-CLI is the Command Line Interface for WordPress, used to do administrative and development tasks in a programmatic way. The project page is <a href=\"http:\/\/wp-cli.org\/\">http:\/\/wp-cli.org\/<\/a> <a href=\"https:\/\/make.wordpress.org\/cli\/\">https:\/\/make.wordpress.org\/cli\/<\/a><\/span><\/span><\/span>: the <code>wp scaffold block<\/code> command.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">You\u2019ve probably also noticed that some of those third-party tools get you up and running with just one <code>npx<\/code> command, while WP-CLI  still needs a full WordPress installation to run. And WP-CLI doesn\u2019t play well with advanced <span tabindex='0' class='glossary-item-container'>JavaScript<span class='glossary-item-hidden-content'><span class='glossary-item-header'>JavaScript<\/span> <span class='glossary-item-description'>JavaScript or JS is an object-oriented computer programming language commonly used to create interactive effects within web browsers. WordPress makes extensive use of JS for a better user experience. While PHP is executed on the server, JS executes within a user\u2019s browser.\r<a href=\"https:\/\/www.javascript.com\/\">https:\/\/www.javascript.com<\/a><\/span><\/span><\/span> tooling like code transpiling, linting or formatting. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Until now. <\/p>\n\n\n\n<p class=\"wp-block-paragraph\">WordPress 5.4 brings you a brand-new, officially supported npm-based scaffolding package.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Create Block<\/strong> generates <span tabindex='0' class='glossary-item-container'>PHP<span class='glossary-item-hidden-content'><span class='glossary-item-header'>PHP<\/span> <span class='glossary-item-description'>The web scripting language in which WordPress is primarily architected. WordPress requires PHP 7.4 or higher<\/span><\/span><\/span>, <span tabindex='0' class='glossary-item-container'>JS<span class='glossary-item-hidden-content'><span class='glossary-item-header'>JS<\/span> <span class='glossary-item-description'>JavaScript, a web scripting language typically executed in the browser. Often used for advanced user interfaces and behaviors.<\/span><\/span><\/span> and <span tabindex='0' class='glossary-item-container'>CSS<span class='glossary-item-hidden-content'><span class='glossary-item-header'>CSS<\/span> <span class='glossary-item-description'>Cascading Style Sheets.<\/span><\/span><\/span> code\u2014and everything else you need to start building your WordPress <span tabindex='0' class='glossary-item-container'>plugin<span class='glossary-item-hidden-content'><span class='glossary-item-header'>Plugin<\/span> <span class='glossary-item-description'>A plugin is a piece of software containing a group of functions that can be added to a WordPress website. They can extend functionality or add new features to your WordPress websites. WordPress plugins are written in the PHP programming language and integrate seamlessly with WordPress. These can be free in the WordPress.org Plugin Directory <a href=\"https:\/\/wordpress.org\/plugins\/\">https:\/\/wordpress.org\/plugins\/<\/a> or can be cost-based plugin from a third-party.<\/span><\/span><\/span>. Its <em>quick-start<\/em> mode lets you pass it a slug that then becomes both the target location for the generated files AND the internal block name:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">$ npm init @wordpress\/block todo-list<\/code><\/pre>\n\n\n\n<figure class=\"wp-block-image size-large\"><img loading=\"lazy\" decoding=\"async\" width=\"800\" height=\"652\" data-attachment-id=\"79749\" data-permalink=\"https:\/\/make.wordpress.org\/core\/2020\/02\/28\/new-wordpress-create-block-package-for-block-scaffolding\/demo\/#main\" data-orig-file=\"https:\/\/make.wordpress.org\/core\/files\/2020\/02\/74508276-f0648280-4efe-11ea-9cc0-a607b43d1bcf.gif\" data-orig-size=\"800,652\" data-comments-opened=\"1\" data-image-meta='{\"aperture\":\"0\",\"credit\":\"\",\"camera\":\"\",\"caption\":\"\",\"created_timestamp\":\"0\",\"copyright\":\"\",\"focal_length\":\"0\",\"iso\":\"0\",\"shutter_speed\":\"0\",\"title\":\"\",\"orientation\":\"0\"}' data-image-title=\"wordpress-create-block\" data-image-description=\"\" data-image-caption=\"\" data-large-file=\"https:\/\/make.wordpress.org\/core\/files\/2020\/02\/74508276-f0648280-4efe-11ea-9cc0-a607b43d1bcf.gif\" src=\"https:\/\/make.wordpress.org\/core\/files\/2020\/02\/74508276-f0648280-4efe-11ea-9cc0-a607b43d1bcf.gif\" alt=\"wordpress-create-block\" class=\"wp-image-79749\"><\/figure>\n\n\n\n<p class=\"wp-block-paragraph\">You don\u2019t need to install or configure tools like webpack, Babel or ESLint yourself. They\u2019re preconfigured and out of sight. So you can focus on the code.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Create Block also has an interactive mode that lets you customize several essential block options before code generation:<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code class=\"\">$ npm init @wordpress\/block<\/code><\/pre>\n\n\n\n<p class=\"wp-block-paragraph\">Finally, despite its support for modern JavaScript tooling, Create Block also lets you to pick an ES5 template\u2014and skip the transpiling tools that trigger ESNext and JSX support.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Note: If you\u2019re concerned about backwards compatibility, the new tool comes straight from the existing WP-CLI implementation\u2014and in particular, the optional ES5 template uses the existing ES5 code.<\/p>\n<p class=\"o2-appended-tags\"><a href=\"https:\/\/make.wordpress.org\/core\/tag\/5-4\/\" class=\"tag\"><span class=\"tag-prefix\">#<\/span>5-4<\/a>, <a href=\"https:\/\/make.wordpress.org\/core\/tag\/block-editor\/\" class=\"tag\"><span class=\"tag-prefix\">#<\/span>block-editor<\/a>, <a href=\"https:\/\/make.wordpress.org\/core\/tag\/dev-notes\/\" class=\"tag\"><span class=\"tag-prefix\">#<\/span>dev-notes<\/a><\/p><nav class='o2-post-footer-actions'><ul class='o2-post-footer-action-row'><\/ul><div class='o2-post-footer-action-likes'><\/div><ul class='o2-post-footer-action-row'><\/ul><\/nav>","protected":false},"excerpt":{"rendered":"<p>BlockBlock Block is the abstract term used to describe units of markup that, composed together, form the content or layout of a webpage using the WordPress editor. The idea combines concepts of what in the past may have achieved with shortcodes, custom HTML, and embed discovery into a single consistent API and user experience. scaffolding [&hellip;]<\/p>\n","protected":false},"author":15687775,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_crdt_document":"","advanced_seo_description":"","jetpack_seo_html_title":"","jetpack_seo_noindex":false,"jetpack_post_was_ever_published":false,"_jetpack_newsletter_access":"","_jetpack_dont_email_post_to_subs":false,"_jetpack_newsletter_tier_id":0,"_jetpack_memberships_contains_paywalled_content":false,"_jetpack_memberships_contains_paid_content":false,"footnotes":"","jetpack_publicize_message":"","jetpack_publicize_feature_enabled":true,"jetpack_social_post_already_shared":true,"jetpack_social_options":{"image_generator_settings":{"template":"highway","default_image_id":0,"font":"","enabled":false},"version":2}},"categories":[1175],"tags":[2966,2804,1443],"class_list":["post-79748","post","type-post","status-publish","format-standard","hentry","category-general","tag-5-4","tag-block-editor","tag-dev-notes","mentions-wordpress","author-jorgefilipecosta"],"revision_note":"","jetpack_publicize_connections":[],"jetpack_featured_media_url":"","jetpack_sharing_enabled":true,"jetpack_shortlink":"https:\/\/wp.me\/p2AvED-kKg","_links":{"self":[{"href":"https:\/\/make.wordpress.org\/core\/wp-json\/wp\/v2\/posts\/79748","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/make.wordpress.org\/core\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/make.wordpress.org\/core\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/make.wordpress.org\/core\/wp-json\/wp\/v2\/users\/15687775"}],"replies":[{"embeddable":true,"href":"https:\/\/make.wordpress.org\/core\/wp-json\/wp\/v2\/comments?post=79748"}],"version-history":[{"count":16,"href":"https:\/\/make.wordpress.org\/core\/wp-json\/wp\/v2\/posts\/79748\/revisions"}],"predecessor-version":[{"id":80296,"href":"https:\/\/make.wordpress.org\/core\/wp-json\/wp\/v2\/posts\/79748\/revisions\/80296"}],"wp:attachment":[{"href":"https:\/\/make.wordpress.org\/core\/wp-json\/wp\/v2\/media?parent=79748"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/make.wordpress.org\/core\/wp-json\/wp\/v2\/categories?post=79748"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/make.wordpress.org\/core\/wp-json\/wp\/v2\/tags?post=79748"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}