<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Yair Even Or</title>
    <description>The latest articles on DEV Community by Yair Even Or (@yaireo).</description>
    <link>https://dev.to/yaireo</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F106900%2F9163d932-b096-4a18-91d4-a469ce5519b2.png</url>
      <title>DEV Community: Yair Even Or</title>
      <link>https://dev.to/yaireo</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/yaireo"/>
    <language>en</language>
    <item>
      <title>Faded Box Backdrop Blur</title>
      <dc:creator>Yair Even Or</dc:creator>
      <pubDate>Wed, 04 Oct 2023 14:29:44 +0000</pubDate>
      <link>https://dev.to/yaireo/faded-box-backdrop-blur-4b3b</link>
      <guid>https://dev.to/yaireo/faded-box-backdrop-blur-4b3b</guid>
      <description>&lt;p&gt;Imagine &lt;code&gt;box-shadow&lt;/code&gt; but for a blur effect, where the backdrop of an element is blurred around the that element, gradually going from blurry to crisp.&lt;/p&gt;

&lt;p&gt;Such an effect can increase the focus on the element which drops the blur, by creating more contrast between it and its backdrop, especially if they happen to be in similar color shades.&lt;/p&gt;

&lt;p&gt;There is no native way of doing with the CSS beside combining a few tricks together to simulate such an effect&lt;/p&gt;

&lt;h2&gt;
  
  
  Steps to create the effect
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Create an HTML element within the the one which harbors the effect. 
Best to use a &lt;em&gt;pseudo-element&lt;/em&gt; for such a thing, so not to involve any markup changes.&lt;/li&gt;
&lt;li&gt;Position the pseudo-element so it occupies the whole area of its parent &lt;strong&gt;plus&lt;/strong&gt; some extra, so the blur “spills” outside the area of the container and will be visible, since the container should not be blurred&lt;/li&gt;
&lt;li&gt;Give that element &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/backdrop-filter"&gt;&lt;code&gt;backdrop-filter: blur(...)&lt;/code&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Apply &lt;code&gt;-webkit-mask&lt;/code&gt; &amp;amp; &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/mask"&gt;&lt;code&gt;mask&lt;/code&gt;&lt;/a&gt; on the element, with a specific value with multiple gradients
&lt;/li&gt;
&lt;li&gt;Apply &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/-webkit-mask-composite"&gt;&lt;code&gt;-webkit-mask-composite: source-in&lt;/code&gt;&lt;/a&gt; (for non-standard Chrome support) and 
&lt;code&gt;mask-composite: intersect&lt;/code&gt; (for non-chromium browsers) to the masked pseudo-element, to marge the pixels of the gradients in such a way that they don’t add to each-other but simply merge to their average, so only areas where both gradients apply to are visible, and this is crucial having the mask fade-out blur backdrop-filter in a somewhat realistic way.&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  The Mask’s Gradients:
&lt;/h3&gt;

&lt;p&gt;Two gradients, one vertical and the other horizontal, both go from transparent, to a color, and back to transparent. The colored region should be prominent - occupy most of the area.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;linear-gradient&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;to&lt;/span&gt; &lt;span class="nt"&gt;top&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;transparent&lt;/span&gt; &lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="o"&gt;%,&lt;/span&gt; &lt;span class="nt"&gt;black&lt;/span&gt; &lt;span class="err"&gt;25&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="err"&gt;75&lt;/span&gt;&lt;span class="o"&gt;%,&lt;/span&gt; &lt;span class="nt"&gt;transparent&lt;/span&gt; &lt;span class="err"&gt;100&lt;/span&gt;&lt;span class="o"&gt;%),&lt;/span&gt;
&lt;span class="nt"&gt;linear-gradient&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;to&lt;/span&gt; &lt;span class="nt"&gt;left&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;transparent&lt;/span&gt; &lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="o"&gt;%,&lt;/span&gt; &lt;span class="nt"&gt;black&lt;/span&gt; &lt;span class="err"&gt;18&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="err"&gt;82&lt;/span&gt;&lt;span class="o"&gt;%,&lt;/span&gt; &lt;span class="nt"&gt;transparent&lt;/span&gt; &lt;span class="err"&gt;100&lt;/span&gt;&lt;span class="o"&gt;%)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/0q-21xYXSv4"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;-webkit-mask-composite: source-in&lt;/code&gt; / &lt;code&gt;intersect&lt;/code&gt; Applied:
&lt;/h3&gt;

&lt;p&gt;As mentioned in step 5:&lt;/p&gt;

&lt;p&gt;&lt;iframe width="710" height="399" src="https://www.youtube.com/embed/6lvz6sOmHg8"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;h3&gt;
  
  
  Combining Everything:
&lt;/h3&gt;

&lt;p&gt;&lt;iframe height="600" src="https://codepen.io/vsync/embed/XWoYaag?height=600&amp;amp;default-tab=result&amp;amp;embed-version=2"&gt;
&lt;/iframe&gt;
&lt;/p&gt;

&lt;p&gt;Note that in the above Codepen example I am using a mask with these percentage values:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;linear-gradient&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;to&lt;/span&gt; &lt;span class="nt"&gt;top&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;transparent&lt;/span&gt; &lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="o"&gt;%,&lt;/span&gt; &lt;span class="nt"&gt;red&lt;/span&gt; &lt;span class="err"&gt;25&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="err"&gt;75&lt;/span&gt;&lt;span class="o"&gt;%,&lt;/span&gt; &lt;span class="nt"&gt;transparent&lt;/span&gt; &lt;span class="err"&gt;100&lt;/span&gt;&lt;span class="o"&gt;%),&lt;/span&gt;
&lt;span class="nt"&gt;linear-gradient&lt;/span&gt;&lt;span class="o"&gt;(&lt;/span&gt;&lt;span class="nt"&gt;to&lt;/span&gt; &lt;span class="nt"&gt;left&lt;/span&gt;&lt;span class="o"&gt;,&lt;/span&gt; &lt;span class="nt"&gt;transparent&lt;/span&gt; &lt;span class="err"&gt;0&lt;/span&gt;&lt;span class="o"&gt;%,&lt;/span&gt; &lt;span class="nt"&gt;red&lt;/span&gt; &lt;span class="err"&gt;18&lt;/span&gt;&lt;span class="o"&gt;%&lt;/span&gt; &lt;span class="err"&gt;82&lt;/span&gt;&lt;span class="o"&gt;%,&lt;/span&gt; &lt;span class="nt"&gt;transparent&lt;/span&gt; &lt;span class="err"&gt;100&lt;/span&gt;&lt;span class="o"&gt;%);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Wherever the fill color is irrelevant (like in this case), I tend to use "&lt;em&gt;red&lt;/em&gt;" as it's the shortest color name. Another thing to note are the percentages &lt;code&gt;25% 75%&lt;/code&gt; &amp;amp; &lt;code&gt;18% 82%&lt;/code&gt;. These roughly correspond the aspect ratio of the popup box, which gives a more “balanced” look to the blur effect between the horizontal sides and vertical sides.&lt;/p&gt;

</description>
    </item>
    <item>
      <title>CSS Debugging Disappearing Elements</title>
      <dc:creator>Yair Even Or</dc:creator>
      <pubDate>Sat, 30 Jul 2022 21:38:00 +0000</pubDate>
      <link>https://dev.to/yaireo/css-debugging-disappearing-elements-lhj</link>
      <guid>https://dev.to/yaireo/css-debugging-disappearing-elements-lhj</guid>
      <description>&lt;p&gt;I'm going to share with you a trick so cool you'll be shocked ⚡️&lt;/p&gt;

&lt;p&gt;But first, here's a little intro for those who have no idea what the subject of this post is for:&lt;/p&gt;

&lt;p&gt;Some elements appear on the screen only when the user interacts with another element. &lt;/p&gt;

&lt;p&gt;For example, a suggestions box appears when the user types text, or a dropdown is rendered when a menu item is hovered.&lt;/p&gt;

&lt;p&gt;(Like the dropdown items of this &lt;a href="https://mui.com/material-ui/react-autocomplete" rel="noopener noreferrer"&gt;MUI component&lt;/a&gt;)&lt;/p&gt;

&lt;p&gt;Sometimes those dynamically appearing elements don't exist in the DOM until they are needed - for example, appearing when another element is being interacted with. &lt;/p&gt;

&lt;p&gt;How can they be inspected? Since clicking the &lt;em&gt;inspect&lt;/em&gt; button will cause those dynamically-added elements to disappear.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb5toisjeo4xzf5klz64m.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fb5toisjeo4xzf5klz64m.png" alt="devtools inspect button"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Timeout trick
&lt;/h2&gt;

&lt;p&gt;Most developers are familiar with this trick, but for those who aren't - to "freeze" the DOM, execute a &lt;code&gt;debugger&lt;/code&gt; command (within devtools console) inside a &lt;code&gt;setTimeout&lt;/code&gt; with enough duration which lets you run around, do whatever you need to do, in order to show the evasive thing you wish to inspect:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nf"&gt;setTimeout&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="k"&gt;debugger&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt; &lt;span class="p"&gt;},&lt;/span&gt; &lt;span class="mi"&gt;3000&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgmke5tnnqfu9kuny3n2v.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fgmke5tnnqfu9kuny3n2v.gif" alt="debugger inside timeout gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;While this is handy, it can be annoying to constantly run this command when you are constantly debugging some random CSS weirdness.&lt;/p&gt;

&lt;h2&gt;
  
  
  2. F8 in Devtools &lt;code&gt;Sources&lt;/code&gt; panel
&lt;/h2&gt;

&lt;p&gt;Hitting F8 while the &lt;code&gt;Sources&lt;/code&gt; panel is open will freeze the DOM also and go into &lt;code&gt;debugger&lt;/code&gt; mode.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Hotkeys automated debugger:
&lt;/h2&gt;

&lt;p&gt;The above trick can be automated using a dedicated keyboard shortcuts (Chrome browser). &lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Install the &lt;a href="https://www.shortkeys.app/" rel="noopener noreferrer"&gt;shortkeys extension&lt;/a&gt; &lt;/li&gt;
&lt;li&gt;Click on the extension icon and chose "options":
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Firsbt95x9buqpugj1u6s.png" alt="shortkeys options menu item"&gt;
&lt;/li&gt;
&lt;li&gt;Configure it as follows:
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fyieoj8yf0d7zi07vwx0p.png" alt="shortkeys configuration"&gt;
&lt;/li&gt;
&lt;li&gt;Click "Save shortcuts" button (bottom-right)&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;Now, go to any page, &lt;strong&gt;make sure&lt;/strong&gt; &lt;em&gt;devtools&lt;/em&gt; is opened, and hit CTRL+SPACEBAR keys, while your inspection target element is visible.&lt;/p&gt;

&lt;h2&gt;
  
  
  4. &lt;em&gt;Emulate a focused page&lt;/em&gt; with devtools:
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;Open Devtools&lt;/li&gt;
&lt;li&gt;Hit Command + shift + P (OSX) or CTRL + shift + P (Windows)&lt;/li&gt;
&lt;li&gt;Type &lt;code&gt;focused&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Select &lt;code&gt;Emulate a focused page&lt;/code&gt; &lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7nutbqlme58znbxhi812.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2F7nutbqlme58znbxhi812.gif" alt="Emulate focused page options in devtools"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now interacting with devtools will not lose focus from the element which was focused.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fom1ojoocz7eispq8x7f9.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fom1ojoocz7eispq8x7f9.jpg" alt="booyakasha"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>css</category>
      <category>debug</category>
      <category>webdev</category>
    </item>
    <item>
      <title>Optional CSS transform with CSS variables</title>
      <dc:creator>Yair Even Or</dc:creator>
      <pubDate>Mon, 10 Jan 2022 17:58:56 +0000</pubDate>
      <link>https://dev.to/yaireo/optional-css-transform-with-css-variables-e81</link>
      <guid>https://dev.to/yaireo/optional-css-transform-with-css-variables-e81</guid>
      <description>&lt;p&gt;Assuming you have a component which has a default transform property value(s) and can also have additional ones, which are optional, then logically it should be written as so:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
             &lt;span class="err"&gt;|--&lt;/span&gt; &lt;span class="err"&gt;default&lt;/span&gt; &lt;span class="err"&gt;---|&lt;/span&gt; &lt;span class="err"&gt;|--&lt;/span&gt; &lt;span class="err"&gt;optional&lt;/span&gt; &lt;span class="err"&gt;--|&lt;/span&gt;
  &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;translate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;100px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--transform&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But...It does not work as intended if the &lt;code&gt;--transform&lt;/code&gt; variable is &lt;strong&gt;not defined&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;I am unsure why, but it can be easily fixed using this trick:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nc"&gt;.component&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;transform&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;translate&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="m"&gt;100px&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="n"&gt;var&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;--transform&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Did you notice? There is a fallback defined to &lt;strong&gt;nothing&lt;/strong&gt;: (&lt;code&gt;, )&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;a href="https://www.w3.org/TR/css-variables-1/#using-variables"&gt;W3 Spec&lt;/a&gt;:
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;In an exception to the usual comma elision rules, which require commas to be omitted when they’re not separating values, a bare comma, with nothing following it, must be treated as valid in var(), indicating an empty fallback value.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Demo:
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://jsbin.com/vejusaj/edit?html,css,output"&gt;https://jsbin.com/vejusaj/edit?html,css,output&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
    <item>
      <title>🚀 Automate NPM package publish &amp; GIT versioning</title>
      <dc:creator>Yair Even Or</dc:creator>
      <pubDate>Wed, 20 Jan 2021 18:29:22 +0000</pubDate>
      <link>https://dev.to/yaireo/automate-npm-package-publish-git-versioning-5cfp</link>
      <guid>https://dev.to/yaireo/automate-npm-package-publish-git-versioning-5cfp</guid>
      <description>&lt;p&gt;Save time, improve your build process by streamlining releases.&lt;/p&gt;

&lt;h2&gt;
  
  
  Intro
&lt;/h2&gt;

&lt;p&gt;Assuming a scenario for a typical package (which yourself is the sole author of), such as some sort of web component, CSS library, etc. which is intended to be used in a &lt;em&gt;client&lt;/em&gt; and has some sort of a build process.&lt;/p&gt;

&lt;p&gt;As mentioned above, this article is not meant for multi-developers codebase which are actively working on branches, because we don't want to tag anything when pushing, and certainly not publishing, since doing that is reserved for a dedicated pipeline (&lt;em&gt;devops&lt;/em&gt;). &lt;/p&gt;

&lt;p&gt;For the sake of example, this article presents a portion of code used in one of my packages - &lt;a href="https://github.com/yairEO/knobs" rel="noopener noreferrer"&gt;knobs&lt;/a&gt;, which is a pretty small project which uses &lt;a href="https://github.com/rollup/rollup" rel="noopener noreferrer"&gt;Rollup&lt;/a&gt; to &lt;a href="https://dev.to/tanhauhau/what-is-module-bundler-and-how-does-it-work-3gp2"&gt;bundle&lt;/a&gt; the &lt;em&gt;JS&lt;/em&gt; &amp;amp; &lt;em&gt;SCSS&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  📜 NPM scripts - basics
&lt;/h2&gt;

&lt;p&gt;This topic has been &lt;a href="https://dev.to/search?q=npm+scripts"&gt;addressed a lot&lt;/a&gt; and this article assumes basic knowledge of working with NPM custom scripts and with lifecycle ones, such as &lt;code&gt;start&lt;/code&gt;, &lt;code&gt;test&lt;/code&gt;, &lt;code&gt;version&lt;/code&gt;, &lt;code&gt;prepublishOnly&lt;/code&gt; and so on.&lt;/p&gt;

&lt;h2&gt;
  
  
  😥 What can go wrong without automatic release flow:
&lt;/h2&gt;

&lt;p&gt;Since the project requires a build process, without automating the release flow as much as possible, &lt;em&gt;unwanted outcome&lt;/em&gt; might occur:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;Accidentally deleted imported distribution file &lt;/li&gt;
&lt;li&gt;Forgetting to build before releasing&lt;/li&gt;
&lt;li&gt;Forgetting to tag the version &lt;/li&gt;
&lt;li&gt;Using wrong git tag (mismatch with &lt;code&gt;version&lt;/code&gt; in &lt;code&gt;package.json&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;Not sure of the order of which things should be done before &lt;code&gt;publish&lt;/code&gt;: &lt;a href="https://stackoverflow.com/q/35221147/104380" rel="noopener noreferrer"&gt;&lt;em&gt;should tag before committing or after?&lt;/em&gt;&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Forgetting to push the tags&lt;/li&gt;
&lt;/ol&gt;

&lt;p&gt;🦺 &lt;strong&gt;Wanted:&lt;/strong&gt; &lt;em&gt;Something&lt;/em&gt; which guarantees nothing of above happens. &lt;/p&gt;

&lt;h3&gt;
  
  
  &lt;code&gt;package.json&lt;/code&gt; &lt;em&gt;before&lt;/em&gt; the change:
&lt;/h3&gt;



&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"start"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"rollup -c rollup.config.dev.js -w"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"build:prod"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"npm run clean &amp;amp;&amp;amp; npm run bundle:prod"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"bundle:prod"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"rollup -c rollup.config.prod.js"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"clean"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"rm -rf knobs.min.js"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"test"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"echo &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;No test specified&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pretty standard bunch of scripts, nothing interesting to talk about.&lt;/p&gt;

&lt;p&gt;In order to publish the package, a &lt;em&gt;non-automated&lt;/em&gt; release flow example would require to first run &lt;code&gt;npm build:prod&lt;/code&gt;, which will run the cleanup script and then the bundling script, which runs without the &lt;code&gt;watch&lt;/code&gt; command, because watching is unnecessary just before deploying since there is no code change. Then commit, and add a git tag and push &lt;em&gt;with&lt;/em&gt; the tag, everything, and then publish the code. (or publish and then push).&lt;/p&gt;

&lt;h3&gt;
  
  
  Lets improve by adding a few scripts:
&lt;/h3&gt;

&lt;p&gt;There are many ways to automate the above workflow (or half-automate), but I would like to talk about a specific tool which I find very helpful:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/sindresorhus/np" rel="noopener noreferrer"&gt;&lt;/a&gt;&lt;a href="https://github.com/sindresorhus/np" rel="noopener noreferrer"&gt;https://github.com/sindresorhus/np&lt;/a&gt;&lt;br&gt;
&lt;a href="https://github.com/sindresorhus/np" rel="noopener noreferrer"&gt;&lt;br&gt;
&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fsindresorhus%2Fnp%2Fraw%2Fmaster%2Fscreenshot.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;a href="https://github.com/sindresorhus/np" rel="noopener noreferrer"&gt;&lt;code&gt;np&lt;/code&gt;&lt;/a&gt; is best installed globally: &lt;code&gt;npm i -g np&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/heldr/headr" rel="noopener noreferrer"&gt;&lt;code&gt;headr&lt;/code&gt;&lt;/a&gt; is a great package for automating header comment in the dist files, which includes information from the &lt;code&gt;package.json&lt;/code&gt; file itself, such as version, author name, repository url, etc. &lt;strong&gt;install&lt;/strong&gt; it also if you wish.&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com/typicode/pkg-ok" rel="noopener noreferrer"&gt;&lt;code&gt;pkg-ok&lt;/code&gt;&lt;/a&gt; is another script which ensures no (important) file is missing, I advise using it.&lt;/li&gt;
&lt;/ol&gt;
&lt;h3&gt;
  
  
  &lt;code&gt;package.json&lt;/code&gt; &lt;em&gt;after&lt;/em&gt; the change 🤟:
&lt;/h3&gt;


&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"scripts"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"start"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"rollup -c rollup.config.dev.js -w"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"build:prod"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"npm run clean &amp;amp;&amp;amp; npm run bundle:prod"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"bundle:prod"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"rollup -c rollup.config.prod.js"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"clean"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"rm -rf knobs.min.js"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"test"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"echo &lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;No test specified&lt;/span&gt;&lt;span class="se"&gt;\"&lt;/span&gt;&lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;

    &lt;/span&gt;&lt;span class="nl"&gt;"header"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"headr knobs.min.js -o=knobs.min.js --version --homepage"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"npm run build:prod &amp;amp;&amp;amp; npm run header &amp;amp;&amp;amp; git add ."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"prepublishOnly"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"pkg-ok"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;And the command used to publish &amp;amp; push is:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;np&lt;/span&gt; &lt;span class="o"&gt;--&lt;/span&gt;&lt;span class="nx"&gt;yolo&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;🧐 &lt;strong&gt;Note&lt;/strong&gt; that I am using the &lt;code&gt;--yolo&lt;/code&gt; flag because I want to skip tests (I don't have tests) and not clean the &lt;code&gt;node_modules&lt;/code&gt; and reinstall everything which can take long minutes. &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;np&lt;/code&gt; package also allows writing a &lt;a href="https://github.com/sindresorhus/np#config" rel="noopener noreferrer"&gt;pre-defined configuration&lt;/a&gt; within &lt;code&gt;package.json&lt;/code&gt; itself, using the &lt;code&gt;np&lt;/code&gt; property.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;code&gt;version&lt;/code&gt; (&lt;em&gt;npm&lt;/em&gt; scripts property) is a &lt;a href="https://docs.npmjs.com/cli/v6/using-npm/scripts" rel="noopener noreferrer"&gt;lifecycle script hook&lt;/a&gt; which runs exactly at the appropriate time to build the code, output the bundle and add a header comment (to any file) with the just-bumped version number.&lt;/p&gt;

&lt;p&gt;&lt;code&gt;prepublishOnly&lt;/code&gt; (&lt;em&gt;npm&lt;/em&gt; scripts property) lifecycle hook is a good place to check no file is missing before proceeding, using &lt;code&gt;pkg-ok&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;🏃‍♂️ Running the above command (&lt;code&gt;np --yolo&lt;/code&gt;) will present a GUI:&lt;br&gt;&lt;em&gt;(screenshot from &lt;code&gt;np&lt;/code&gt; repo)&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fsindresorhus%2Fnp%2Fraw%2Fmaster%2Fscreenshot-ui.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fgithub.com%2Fsindresorhus%2Fnp%2Fraw%2Fmaster%2Fscreenshot-ui.png"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If all goes well, the package will be published and a new browser tab/window will open the project's &lt;em&gt;GIT&lt;/em&gt; repository URL, for you to approve &amp;amp; publish a new &lt;strong&gt;&lt;em&gt;tagged&lt;/em&gt;&lt;/strong&gt; release in the repo.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia1.popsugar-assets.com%2Ffiles%2Fthumbor%2F_NabRgXjkct2atlFqs3TCEHaaQo%2Ffit-in%2F1024x1024%2Ffilters%3Aformat_auto-%21%21-%3Astrip_icc-%21%21-%2F2014%2F07%2F28%2F909%2Fn%2F1922507%2F32a3b2f32e6a8a2e_drops-mic%2Fi%2FDrops-Mic.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fmedia1.popsugar-assets.com%2Ffiles%2Fthumbor%2F_NabRgXjkct2atlFqs3TCEHaaQo%2Ffit-in%2F1024x1024%2Ffilters%3Aformat_auto-%21%21-%3Astrip_icc-%21%21-%2F2014%2F07%2F28%2F909%2Fn%2F1922507%2F32a3b2f32e6a8a2e_drops-mic%2Fi%2FDrops-Mic.jpg"&gt;&lt;/a&gt;&lt;/p&gt;

</description>
      <category>npm</category>
      <category>git</category>
      <category>productivity</category>
      <category>webdev</category>
    </item>
  </channel>
</rss>
