<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
xmlns:content="http://purl.org/rss/1.0/modules/content/"
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:atom="http://www.w3.org/2005/Atom"
xmlns:sy="http://purl.org/rss/1.0/modules/syndication/">
	<channel>
		<title>Building ESNext on WordPress, Simplified | Infinum</title>
		<atom:link href="https://infinum.com/blog/esnext-on-wordpress/feed/" rel="self" type="application/rss+xml" />
		<link>https://infinum.com/blog/esnext-on-wordpress/</link>
		<description>Building digital products</description>
		<lastBuildDate>Wed, 08 Apr 2026 14:17:14 +0000</lastBuildDate>
		<sy:updatePeriod>hourly</sy:updatePeriod>
		<sy:updateFrequency>1</sy:updateFrequency>

					<item>
				<image>
					<url>7932https://infinum.com/uploads/2020/10/ESNext-on-WordPress-0.webp</url>
				</image>
				<title>Building ESNext on WordPress, Simplified</title>
				<link>https://infinum.com/blog/esnext-on-wordpress/</link>
				<pubDate>Mon, 05 Oct 2020 12:30:00 +0000</pubDate>
				<dc:creator>Gabriel Glogoški</dc:creator>
				<guid isPermaLink="false">https://infinum.com/the-capsized-eight/esnext-on-wordpress/</guid>
				<description>
					<![CDATA[<p>A small step for the WordPress team, a giant leap towards more modern WordPress themes or plugins.</p>
<p>The post <a href="https://infinum.com/blog/esnext-on-wordpress/">Building ESNext on WordPress, Simplified</a> appeared first on <a href="https://infinum.com">Infinum</a>.</p>
]]>
				</description>
				<content:encoded>
					<![CDATA[<div
	class="wrapper"
	data-id="es-246"
	 data-animation-target='inner-items'>
		
			<div class="wrapper__inner">
			<div class="block-blog-content js-block-blog-content">
	
<div class="block-blog-content-sidebar" data-id="es-92">
	</div>

<div class="block-blog-content-main">
	
<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-95"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-93">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-94'
	>
	WordPress is currently going through a sort of renaissance in terms of content editing and development. The release of the Block editor created a lot of commotion in the entire WordPress ecosystem, and it’s still present.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-98"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-96">
	<h2	class='typography typography--size-52-default js-typography block-heading__heading'
	data-id='es-97'
	>
	New kid on the the Block Editor</h2></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-101"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-99">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-100'
	>
	The Block Editor enables a new way of creating pages and posts and a whole new framework for developers to create custom site components. For the full story on Block Editors release, criticisms, and exciting new features, see <a href="https://infinum.com/blog/gutenberg-wordpress-themes/">Denis’ blog post on the future of WordPress themes</a>.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-104"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-102">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-103'
	>
	In this article, we will focus on a package that’s supposed to simplify the build process. But why is it complicated in the first place?</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-107"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-105">
	<h2	class='typography typography--size-52-default js-typography block-heading__heading'
	data-id='es-106'
	>
	Challenges using Block Editor and developing custom blocks</h2></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-110"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-108">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-109'
	>
	Developing new blocks requires an entirely different setup from what most WordPress developers are used to.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-113"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-111">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-112'
	>
	One of the reasons for not using the Block Editor and developing custom blocks is a drastic change in technology that is used for developing blocks. The Block Editor and all of its blocks are built with React.js, a JavaScript library that is “relatively new” on the scene and requires a different approach in development.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-116"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-114">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-115'
	>
	On top of that, some sort of <a href="https://developer.wordpress.org/block-editor/tutorials/javascript/js-build-setup/">build process</a> is recommended for developing custom blocks, so the code can be split up into smaller logical pieces, which will improve the overall codebase’ maintainability.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-119"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-117">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-118'
	>
	In addition, a build process is necessary for using the ESNext syntax of JS, because the written code will be transpiled through the build process into code that can run on any browser.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-122"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-120">
	<h2	class='typography typography--size-52-default js-typography block-heading__heading'
	data-id='es-121'
	>
	A new development stack from the WordPress team</h2></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-125"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-123">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-124'
	>
	To make the development of custom blocks easier, a couple of neat JS packages were made available. One of those packages is <a href="https://developer.wordpress.org/block-editor/packages/packages-scripts/">@wordpress/scripts</a>.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-130"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="blockquote block-blockquote__blockquote" data-id="es-126">
	
	<div class="blockquote__content">
		<i
	class="icon blockquote__icon icon--size-16 icon--scale-100"
	 aria-hidden='true' data-name='blockquote-24' data-id='es-127'>
	<svg fill='none' height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'><path clip-rule='evenodd' d='m12 24c6.6274 0 12-5.3726 12-12 0-2.79685-.9568-5.37021-2.561-7.41062-.581.22951-1.0832.60583-1.5069 1.12898-.5132.60844-.7698 1.41969-.7698 2.43375v.07605h2.5789v5.59004h-5.6197v-5.01962c0-1.11547.154-2.06616.4619-2.85205.3336-.81125.757-1.48307 1.2702-2.01545.528-.52161 1.1175-.92155 1.7687-1.1998-2.0728-1.70651-4.7279-2.73128-7.6223-2.73128-6.62742 0-12 5.37258-12 12 0 6.6274 5.37258 12 12 12zm-3.53811-18.05347c-.30793.78589-.46189 1.73658-.46189 2.85205v5.01962h5.6197v-5.59004h-2.5789v-.07605c0-1.01406.2566-1.82531.7698-2.43375.5389-.63379 1.1804-1.05209 1.9245-1.2549v-2.28164c-.7441.07605-1.4626.25351-2.1555.53238-.6928.27887-1.3086.68449-1.84752 1.21688-.51321.53238-.9366 1.2042-1.27019 2.01545z' fill='currentColor' fill-rule='evenodd'/></svg></i><p	class='typography typography--size-36-text js-typography blockquote__quote'
	data-id='es-128'
	>
	It comes with pre-configured scripts for building and bundling JS assets, linting your JS code against WordPress coding standards, and performing E2E tests.</p>
		<div class="blockquote__caption-wrap">
					</div>
	</div>
</div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-133"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-131">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-132'
	>
	We’ll focus on build script and go through basic concepts of others.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-136"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-134">
	<h3	class='typography typography--size-36-text js-typography block-heading__heading'
	data-id='es-135'
	>
	Installation and configuration</h3></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-139"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-137">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-138'
	>
	To install and use @wordpress/scripts package in your existing WordPress project, you need to have Node.js installed and configured.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-142"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-140">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-141'
	>
	If you already used some packages from npm repository, there should be a <code>package.json</code> file in your projects directory. If that is not the case, you will need to create it by navigating to your projects directory with terminal, enter: <code>npm init</code> command and fill out the details of your project.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-145"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-143">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-144'
	>
	Once you have a <code>package.json</code> file, you can go back to the terminal and install @wordpress/scripts package by entering the following:</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-147"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-shellscript github-light" data-language="shellscript" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #6f42c1;">npm</span><span class="token"> </span><span class="token" style="color: #032f62;">install</span><span class="token"> </span><span class="token" style="color: #005cc5;">-</span><span class="token" style="color: #005cc5;">-save-dev</span><span class="token">  </span><span class="token" style="color: #032f62;">@wordpress/scripts</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-150"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-148">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-149'
	>
	Wait for the installation to finish. Once the installation is done, you can start setting up your npm scripts that @wordpress/scripts package provides.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-153"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-151">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-152'
	>
	To do that, edit your <code>package.json</code> file and change the scripts object to look like this:</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-155"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-json github-light" data-language="json" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #032f62;">&quot;</span><span class="token" style="color: #032f62;">scripts</span><span class="token" style="color: #032f62;">&quot;</span><span class="token">: </span><span class="token">{</span><span class="token">
</span></span><span class="line"><span class="token">   </span><span class="token" style="color: #005cc5;">&quot;</span><span class="token" style="color: #005cc5;">build</span><span class="token" style="color: #005cc5;">&quot;</span><span class="token">:</span><span class="token"> </span><span class="token" style="color: #032f62;">&quot;</span><span class="token" style="color: #032f62;">wp-scripts build</span><span class="token" style="color: #032f62;">&quot;</span><span class="token">
</span></span><span class="line"><span class="token">   </span><span class="token" style="color: #032f62;">&quot;</span><span class="token" style="color: #032f62;">start</span><span class="token" style="color: #032f62;">&quot;</span><span class="token" style="color: #b31d28;font-style: italic;">:</span><span class="token"> </span><span class="token" style="color: #032f62;">&quot;</span><span class="token" style="color: #032f62;">wp-scripts start</span><span class="token" style="color: #032f62;">&quot;</span><span class="token">,</span><span class="token">
</span></span><span class="line"><span class="token">}</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-158"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-156">
	<h3	class='typography typography--size-36-text js-typography block-heading__heading'
	data-id='es-157'
	>
	Usage and examples</h3></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-161"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-159">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-160'
	>
	Both of these scripts, by default, will search for <code>src/index.js</code> as their source file to compile from and will create a compiled file in <code>build/index.js</code>. This compiled file will be the one that should be registered and enqueued in WordPress using the <a href="https://developer.wordpress.org/reference/functions/wp_register_script/">wp_register_script</a> function and <a href="https://developer.wordpress.org/reference/functions/wp_enqueue_script/">wp_enqueue_script</a>.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-164"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-162">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-163'
	>
	Build script will run the build process and create a minified and production-ready file. For any changes in <code>src/</code> directory this script will need to be rerun.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-167"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-165">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-166'
	>
	To run this script, go back to the terminal and enter:</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-169"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-shellscript github-light" data-language="shellscript" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #6f42c1;">npm</span><span class="token"> </span><span class="token" style="color: #032f62;">run</span><span class="token"> </span><span class="token" style="color: #032f62;">build</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-172"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-170">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-171'
	>
	For active development on a project, it is recommended to use <code>start</code> script. It will start an ongoing build process and build a new compiled file on every change in <code>src/</code> directory. The compiled file will not have minified code, and any errors in JS code will pause that process (fixing those errors will resume it).</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-175"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-173">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-174'
	>
	To run it, write the following:</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-177"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-shellscript github-light" data-language="shellscript" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #6f42c1;">npm</span><span class="token"> </span><span class="token" style="color: #032f62;">start</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-180"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-178">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-179'
	>
	Once we know how to run build processes, we can start building the rest of the JS file structure in the <code>src/</code> directory. You can split each functionality in separate directories, but all of them need to be included in <code>index.js</code> file.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-183"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-181">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-182'
	>
	Let’s look at a real-world example of registering a custom block:</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-185"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-php github-light" data-language="php" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> src/blocks/custom-block/index.js</span><span class="token" style="color: #6a737d;">
</span></span><span class="line"><span class="token">
</span></span><span class="line"><span class="token" style="color: #005cc5;">import</span><span class="token"> </span><span class="token">{</span><span class="token"> </span><span class="token" style="color: #005cc5;">registerBlockType</span><span class="token"> </span><span class="token">}</span><span class="token"> </span><span class="token" style="color: #005cc5;">from</span><span class="token"> </span><span class="token" style="color: #005cc5;">’</span><span class="token" style="color: #d73a49;">@</span><span class="token" style="color: #005cc5;">wordpress</span><span class="token" style="color: #d73a49;">/</span><span class="token" style="color: #005cc5;">blocks’</span><span class="token">;</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #005cc5;">import</span><span class="token"> </span><span class="token">{</span><span class="token"> </span><span class="token" style="color: #005cc5;">customBlockEdit</span><span class="token"> </span><span class="token">}</span><span class="token"> </span><span class="token" style="color: #005cc5;">from</span><span class="token"> </span><span class="token" style="color: #005cc5;">’</span><span class="token" style="color: #d73a49;">.</span><span class="token" style="color: #d73a49;">/</span><span class="token" style="color: #005cc5;">edit’</span><span class="token">;</span><span class="token">
</span></span><span class="line"><span class="token" style="color: #005cc5;">import</span><span class="token"> </span><span class="token">{</span><span class="token"> </span><span class="token" style="color: #005cc5;">customBlockSave</span><span class="token"> </span><span class="token">}</span><span class="token"> </span><span class="token" style="color: #005cc5;">from</span><span class="token"> </span><span class="token" style="color: #005cc5;">’</span><span class="token" style="color: #d73a49;">.</span><span class="token" style="color: #d73a49;">/</span><span class="token" style="color: #005cc5;">save’</span><span class="token">;</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span><span class="line"><span class="token" style="color: #005cc5;">export</span><span class="token"> </span><span class="token" style="color: #6f42c1;">customBlockInit</span><span class="token"> </span><span class="token">(</span><span class="token">)</span><span class="token"> </span><span class="token" style="color: #d73a49;">=&gt;</span><span class="token"> </span><span class="token">{</span><span class="token">
</span></span><span class="line"><span class="token">  </span><span class="token" style="color: #6f42c1;">registerBlockType</span><span class="token">(</span><span class="token" style="color: #005cc5;">’custom</span><span class="token" style="color: #d73a49;">-</span><span class="token" style="color: #005cc5;">namespace</span><span class="token" style="color: #d73a49;">/</span><span class="token" style="color: #005cc5;">custom</span><span class="token" style="color: #d73a49;">-</span><span class="token" style="color: #005cc5;">block’</span><span class="token">,</span><span class="token"> </span><span class="token">{</span><span class="token">
</span></span><span class="line"><span class="token">    </span><span class="token" style="color: #6f42c1;">title</span><span class="token">:</span><span class="token"> </span><span class="token" style="color: #005cc5;">’Custom</span><span class="token"> </span><span class="token" style="color: #005cc5;">Block’</span><span class="token">,</span><span class="token">
</span></span><span class="line"><span class="token">    </span><span class="token" style="color: #6f42c1;">icon</span><span class="token">:</span><span class="token"> </span><span class="token" style="color: #005cc5;">’heading’</span><span class="token">,</span><span class="token">
</span></span><span class="line"><span class="token">    </span><span class="token" style="color: #6f42c1;">category</span><span class="token">:</span><span class="token"> </span><span class="token" style="color: #005cc5;">’common’</span><span class="token">,</span><span class="token">
</span></span><span class="line"><span class="token">    </span><span class="token" style="color: #6f42c1;">edit</span><span class="token">:</span><span class="token"> </span><span class="token">(</span><span class="token">)</span><span class="token"> </span><span class="token" style="color: #d73a49;">=&gt;</span><span class="token"> </span><span class="token" style="color: #6f42c1;">customBlockEdit</span><span class="token">(</span><span class="token">)</span><span class="token">,</span><span class="token">
</span></span><span class="line"><span class="token">    </span><span class="token" style="color: #6f42c1;">save</span><span class="token">:</span><span class="token"> </span><span class="token">(</span><span class="token">)</span><span class="token"> </span><span class="token" style="color: #d73a49;">=&gt;</span><span class="token"> </span><span class="token" style="color: #6f42c1;">customBlockSave</span><span class="token">(</span><span class="token">)</span><span class="token">,</span><span class="token">
</span></span><span class="line"><span class="token">  </span><span class="token">}</span><span class="token"> </span><span class="token">)</span><span class="token">;</span><span class="token">
</span></span><span class="line"><span class="token">}</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span><span class="line"><span class="token" style="color: #6a737d;">//</span><span class="token" style="color: #6a737d;"> src/index.js</span><span class="token" style="color: #6a737d;">
</span></span><span class="line"><span class="token">
</span></span><span class="line"><span class="token" style="color: #005cc5;">import</span><span class="token"> </span><span class="token">{</span><span class="token"> </span><span class="token" style="color: #005cc5;">customBlockInit</span><span class="token"> </span><span class="token">}</span><span class="token"> </span><span class="token" style="color: #005cc5;">from</span><span class="token"> </span><span class="token" style="color: #005cc5;">’</span><span class="token" style="color: #d73a49;">.</span><span class="token" style="color: #d73a49;">/</span><span class="token" style="color: #005cc5;">blocks</span><span class="token" style="color: #d73a49;">/</span><span class="token" style="color: #005cc5;">custom</span><span class="token" style="color: #d73a49;">-</span><span class="token" style="color: #005cc5;">block’</span><span class="token">;</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span><span class="line"><span class="token" style="color: #6f42c1;">customBlockInit</span><span class="token">(</span><span class="token">)</span><span class="token">;</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-188"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-186">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-187'
	>
	These examples on importing and exporting modules are just the start of the modernization process of JS code in WordPress projects. After the code has been written, it is a good thing to make sure that it is written well and is following some coding standard. Other scripts form @wordpress/scripts package will help us with that.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-191"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-189">
	<h3	class='typography typography--size-36-text js-typography block-heading__heading'
	data-id='es-190'
	>
	Other features and extending features</h3></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-194"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-192">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-193'
	>
	Building JS files is not the only feature this package enables. With @wordpress/scripts it is possible to lint and format JS, CSS files.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-197"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-195">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-196'
	>
	To add linting and formating scripts, we need to update the scripts property of <code>package.json</code> file:</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-199"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-json github-light" data-language="json" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #032f62;">&quot;</span><span class="token" style="color: #032f62;">scripts</span><span class="token" style="color: #032f62;">&quot;</span><span class="token">: </span><span class="token">{</span><span class="token">
</span></span><span class="line"><span class="token">    </span><span class="token" style="color: #005cc5;">&quot;</span><span class="token" style="color: #005cc5;">lint:js</span><span class="token" style="color: #005cc5;">&quot;</span><span class="token">:</span><span class="token"> </span><span class="token" style="color: #032f62;">&quot;</span><span class="token" style="color: #032f62;">wp-scripts lint-js</span><span class="token" style="color: #032f62;">&quot;</span><span class="token">,</span><span class="token">
</span></span><span class="line"><span class="token">    </span><span class="token" style="color: #005cc5;">&quot;</span><span class="token" style="color: #005cc5;">lint:js:src</span><span class="token" style="color: #005cc5;">&quot;</span><span class="token">:</span><span class="token"> </span><span class="token" style="color: #032f62;">&quot;</span><span class="token" style="color: #032f62;">wp-scripts lint-js ./src</span><span class="token" style="color: #032f62;">&quot;</span><span class="token">
</span></span><span class="line"><span class="token">    </span><span class="token" style="color: #032f62;">&quot;</span><span class="token" style="color: #032f62;">lint:style</span><span class="token" style="color: #032f62;">&quot;</span><span class="token" style="color: #b31d28;font-style: italic;">:</span><span class="token"> </span><span class="token" style="color: #032f62;">&quot;</span><span class="token" style="color: #032f62;">wp-scripts lint-style</span><span class="token" style="color: #032f62;">&quot;</span><span class="token">,</span><span class="token">
</span></span><span class="line"><span class="token">    </span><span class="token" style="color: #005cc5;">&quot;</span><span class="token" style="color: #005cc5;">lint:css:src</span><span class="token" style="color: #005cc5;">&quot;</span><span class="token">:</span><span class="token"> </span><span class="token" style="color: #032f62;">&quot;</span><span class="token" style="color: #032f62;">wp-scripts lint-style ’src/**/*.css’</span><span class="token" style="color: #032f62;">&quot;</span><span class="token">
</span></span><span class="line"><span class="token">    </span><span class="token" style="color: #032f62;">&quot;</span><span class="token" style="color: #032f62;">format:js</span><span class="token" style="color: #032f62;">&quot;</span><span class="token" style="color: #b31d28;font-style: italic;">:</span><span class="token"> </span><span class="token" style="color: #032f62;">&quot;</span><span class="token" style="color: #032f62;">wp-scripts format-js</span><span class="token" style="color: #032f62;">&quot;</span><span class="token">,</span><span class="token">
</span></span><span class="line"><span class="token">    </span><span class="token" style="color: #005cc5;">&quot;</span><span class="token" style="color: #005cc5;">format:js:src</span><span class="token" style="color: #005cc5;">&quot;</span><span class="token">:</span><span class="token"> </span><span class="token" style="color: #032f62;">&quot;</span><span class="token" style="color: #032f62;">wp-scripts format-js ./src</span><span class="token" style="color: #032f62;">&quot;</span><span class="token">
</span></span><span class="line"><span class="token">}</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-202"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-200">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-201'
	>
	Commands <code>lint:js</code> and <code>lint:style</code> will go through the entire project and lint all JS and CSS files that they find and <code>lint:js:src</code> and <code>lint:css:src</code> will only lint files in <code>src/</code> directory. Default linting rules for JS files are located in <a href="https://www.npmjs.com/package/@wordpress/eslint-plugin">@wordpress/eslint-plugin</a> npm package and for CSS in <a href="https://www.npmjs.com/package/stylelint-config-wordpress">stylelint-config-wordpress</a> package.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-205"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-203">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-204'
	>
	These default linting rulesets can be overridden to accommodate all coding preferences. Manually fixing errors and warnings reported by the linting process can be tedious, but there is a neat tool for JS files. We can format the JS files to adhere to the same coding standards with the <code>format:js</code> and <code>format:js:src</code> scripts.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-208"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-206">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-207'
	>
	Last major thing that @wordpress/scripts can do is running unit and end-to-end tests on JS files. Tests should be located in <code>spec/</code> directory or have a <code>.spec.js</code> suffix for E2E tests and in <code>test/</code> directory or have a <code>.test.js</code> suffix for unit tests. All tests are run by <a href="https://jestjs.io/">Jest</a> in addition to <a href="https://pptr.dev/">Puppeteer</a> for E2E tests.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-211"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-209">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-210'
	>
	To enable testing scripts update <code>package.json</code> file:</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-213"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-json github-light" data-language="json" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #032f62;">&quot;</span><span class="token" style="color: #032f62;">scripts</span><span class="token" style="color: #032f62;">&quot;</span><span class="token">: </span><span class="token">{</span><span class="token">
</span></span><span class="line"><span class="token">    </span><span class="token" style="color: #005cc5;">&quot;</span><span class="token" style="color: #005cc5;">test:e2e</span><span class="token" style="color: #005cc5;">&quot;</span><span class="token">:</span><span class="token"> </span><span class="token" style="color: #032f62;">&quot;</span><span class="token" style="color: #032f62;">wp-scripts test-e2e</span><span class="token" style="color: #032f62;">&quot;</span><span class="token">,</span><span class="token">
</span></span><span class="line"><span class="token">    </span><span class="token" style="color: #005cc5;">&quot;</span><span class="token" style="color: #005cc5;">test:unit</span><span class="token" style="color: #005cc5;">&quot;</span><span class="token">:</span><span class="token"> </span><span class="token" style="color: #032f62;">&quot;</span><span class="token" style="color: #032f62;">wp-scripts test-unit-js</span><span class="token" style="color: #032f62;">&quot;</span><span class="token">
</span></span><span class="line"><span class="token">}</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-216"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-214">
	<h3	class='typography typography--size-36-text js-typography block-heading__heading'
	data-id='es-215'
	>
	Extending the webpack configuration</h3></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-219"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-217">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-218'
	>
	All of these scripts are powered by <a href="https://webpack.js.org/">webpack</a>, that can do a lot more things than what is covered by @wordpress/package scripts. It is possible to add additional, project-specific, features while keeping all the functions of the initial package.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-222"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-220">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-221'
	>
	Extending WordPress webpack configuration starts with creating a <code>webpack.config.js</code> file in the root of the project (where <code>package.json</code> file is located), then importing default configuration and adding parts of the default configuration in new, custom configuration. It is mostly done by using the JS spread operator.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-225"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-223">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-224'
	>
	Here’s an example:</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-227"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-code">
	<pre class="phiki language-php github-light" data-language="php" style="background-color: #fff;color: #24292e;"><code><span class="line"><span class="token" style="color: #d73a49;">const</span><span class="token"> </span><span class="token" style="color: #005cc5;">defaultConfig</span><span class="token"> </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token" style="color: #d73a49;">require</span><span class="token">(</span><span class="token" style="color: #032f62;">&quot;</span><span class="token" style="color: #032f62;">@wordpress/scripts/config/webpack.config</span><span class="token" style="color: #032f62;">&quot;</span><span class="token">)</span><span class="token">;</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span><span class="line"><span class="token" style="color: #005cc5;">module</span><span class="token" style="color: #d73a49;">.</span><span class="token" style="color: #005cc5;">exports</span><span class="token"> </span><span class="token" style="color: #d73a49;">=</span><span class="token"> </span><span class="token">{</span><span class="token">
</span></span><span class="line"><span class="token">  </span><span class="token" style="color: #d73a49;">...</span><span class="token" style="color: #005cc5;">defaultConfig</span><span class="token">,</span><span class="token">
</span></span><span class="line"><span class="token">  </span><span class="token" style="color: #6f42c1;">module</span><span class="token">:</span><span class="token"> </span><span class="token">{</span><span class="token">
</span></span><span class="line"><span class="token">    </span><span class="token" style="color: #d73a49;">...</span><span class="token" style="color: #005cc5;">defaultConfig</span><span class="token" style="color: #d73a49;">.</span><span class="token" style="color: #005cc5;">module</span><span class="token">,</span><span class="token">
</span></span><span class="line"><span class="token">    </span><span class="token" style="color: #6f42c1;">rules</span><span class="token">:</span><span class="token"> </span><span class="token">[</span><span class="token">
</span></span><span class="line"><span class="token">      </span><span class="token" style="color: #d73a49;">...</span><span class="token" style="color: #005cc5;">defaultConfig</span><span class="token" style="color: #d73a49;">.</span><span class="token" style="color: #005cc5;">module</span><span class="token" style="color: #d73a49;">.</span><span class="token" style="color: #005cc5;">rules</span><span class="token">,</span><span class="token">
</span></span><span class="line"><span class="token">      </span><span class="token">{</span><span class="token">
</span></span><span class="line"><span class="token">        </span><span class="token" style="color: #6f42c1;">test</span><span class="token">:</span><span class="token"> </span><span class="token" style="color: #d73a49;">/</span><span class="token">\</span><span class="token" style="color: #d73a49;">.</span><span class="token" style="color: #005cc5;">custom</span><span class="token" style="color: #d73a49;">-</span><span class="token" style="color: #005cc5;">pattern</span><span class="token">$</span><span class="token" style="color: #d73a49;">/</span><span class="token">,</span><span class="token">
</span></span><span class="line"><span class="token">        </span><span class="token" style="color: #d73a49;">use</span><span class="token">: [&quot;</span><span class="token" style="color: #005cc5;">custom</span><span class="token">-</span><span class="token" style="color: #005cc5;">webpack</span><span class="token">-</span><span class="token" style="color: #005cc5;">package</span><span class="token">&quot;]
</span></span><span class="line"><span class="token">      }</span><span class="token">,</span><span class="token">
</span></span><span class="line"><span class="token">    ]
</span></span><span class="line"><span class="token">  </span><span class="token">}</span><span class="token">
</span></span><span class="line"><span class="token">}</span><span class="token">;</span><span class="token">
</span></span><span class="line"><span class="token">
</span></span></code></pre></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-230"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-heading" data-id="es-228">
	<h2	class='typography typography--size-52-default js-typography block-heading__heading'
	data-id='es-229'
	>
	One step towards more modern WordPress themes</h2></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-233"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-231">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-232'
	>
	@wordpress/scripts was developed to be a good starting point in modernization of the JS code in WordPress, introducing asset building, linting and testing to every project.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-238"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="blockquote block-blockquote__blockquote" data-id="es-234">
	
	<div class="blockquote__content">
		<i
	class="icon blockquote__icon icon--size-16 icon--scale-100"
	 aria-hidden='true' data-name='blockquote-24' data-id='es-235'>
	<svg fill='none' height='24' viewBox='0 0 24 24' width='24' xmlns='http://www.w3.org/2000/svg'><path clip-rule='evenodd' d='m12 24c6.6274 0 12-5.3726 12-12 0-2.79685-.9568-5.37021-2.561-7.41062-.581.22951-1.0832.60583-1.5069 1.12898-.5132.60844-.7698 1.41969-.7698 2.43375v.07605h2.5789v5.59004h-5.6197v-5.01962c0-1.11547.154-2.06616.4619-2.85205.3336-.81125.757-1.48307 1.2702-2.01545.528-.52161 1.1175-.92155 1.7687-1.1998-2.0728-1.70651-4.7279-2.73128-7.6223-2.73128-6.62742 0-12 5.37258-12 12 0 6.6274 5.37258 12 12 12zm-3.53811-18.05347c-.30793.78589-.46189 1.73658-.46189 2.85205v5.01962h5.6197v-5.59004h-2.5789v-.07605c0-1.01406.2566-1.82531.7698-2.43375.5389-.63379 1.1804-1.05209 1.9245-1.2549v-2.28164c-.7441.07605-1.4626.25351-2.1555.53238-.6928.27887-1.3086.68449-1.84752 1.21688-.51321.53238-.9366 1.2042-1.27019 2.01545z' fill='currentColor' fill-rule='evenodd'/></svg></i><p	class='typography typography--size-36-text js-typography blockquote__quote'
	data-id='es-236'
	>
	It’s an easy configuration for those who want to dip their toes in custom block development, and have no prior experience with ESNext syntax.</p>
		<div class="blockquote__caption-wrap">
					</div>
	</div>
</div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-241"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-239">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-240'
	>
	One thing that could be problematic while using @wordpress/scripts is the size of the <code>node_modules</code> folder. Because the package supports running E2E tests, Chromium is required for running those tests. Its size inflates the total size of the <code>node_modules</code> folder to around 400+ MB. For some users, that could be too much bloat for something that is not even planned to be used.</p></div>	</div>

<div
	class="wrapper wrapper__use-simple--true"
	data-id="es-244"
	 data-animation='slideFade' data-animation-target='inner-items'>
		
			<div class="block-paragraph" data-id="es-242">
	<p	class='typography typography--size-16-text-roman js-typography block-paragraph__paragraph'
	data-id='es-243'
	>
	Nevertheless, this package is a step in the right direction for creating more modern WordPress themes or plugins and enforcing good coding practices.</p></div>	</div>
</div>
</div>		</div>
	</div><p>The post <a href="https://infinum.com/blog/esnext-on-wordpress/">Building ESNext on WordPress, Simplified</a> appeared first on <a href="https://infinum.com">Infinum</a>.</p>
]]>
				</content:encoded>
			</item>
		
	</channel>
</rss>