<?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: Tally Barak</title>
    <description>The latest articles on DEV Community by Tally Barak (@tallyb).</description>
    <link>https://dev.to/tallyb</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%2F26885%2F37fbc50b-6c96-4d41-8cae-8b535b640911.jpeg</url>
      <title>DEV Community: Tally Barak</title>
      <link>https://dev.to/tallyb</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/tallyb"/>
    <language>en</language>
    <item>
      <title>Writing Storybook Stories with TSX for Stencil</title>
      <dc:creator>Tally Barak</dc:creator>
      <pubDate>Mon, 09 May 2022 10:34:01 +0000</pubDate>
      <link>https://dev.to/tallyb/writing-storybook-stories-with-tsx-for-stencil-2c1i</link>
      <guid>https://dev.to/tallyb/writing-storybook-stories-with-tsx-for-stencil-2c1i</guid>
      <description>&lt;p&gt;Yes, you can! &lt;/p&gt;

&lt;p&gt;If you want to write your stencil stories for storybook using TSX (the Typescript version of JSX), this is actually possible. A bit of tweaking, and you should go to go. &lt;br&gt;
BUT - this is still a very preliminary work, and I expect it to suffer quite few  bumps in different scenarios. Nevertheless, I thought it it worth sharing, as I know people were looking for a solution. &lt;/p&gt;

&lt;p&gt;This is assuming you are using the html version of Storybook with Stencil. You can find a working version in my stencil-one &lt;a href="https://github.com/Tallyb/stencil-one"&gt;demo repo&lt;/a&gt;. (This is my demo repo for unit testing in Stencil, so feel free to look around). &lt;/p&gt;

&lt;p&gt;These are the main versions I worked with. I have no idea if it will be compatible with other versions. &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Stencil: 2.15 &lt;/li&gt;
&lt;li&gt;Storybook: 6&lt;/li&gt;
&lt;li&gt;webpack: 5&lt;/li&gt;
&lt;li&gt;babel-loader: 8&lt;/li&gt;
&lt;/ul&gt;
&lt;h2&gt;
  
  
  Step 1: Write your story
&lt;/h2&gt;

&lt;p&gt;This is what a story should look like, using CSF3 (Component Story Format). Obviously, it should be in a file named &lt;code&gt;.tsx&lt;/code&gt;, so it will go thru the right tooling. Also, change the path that looks for your stories to include .tsx files. (stories option in the main file).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;/** @jsx h */
/** @jsxRuntime classic */

import {h} from '@stencil/core';

export default {
  title: 'My Basic',
};

export const Default = {
  render: () =&amp;gt; (&amp;lt;my-basic first="Millie" last="Brown"&amp;gt;&amp;lt;/my-basic&amp;gt;)
};
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Note the &lt;code&gt;@jsx&lt;/code&gt; directives. They seem to be necessary. &lt;/p&gt;

&lt;h2&gt;
  
  
  Step 2: Configure Webpack for jsx
&lt;/h2&gt;

&lt;p&gt;We are going to tweak &lt;code&gt;.storybook/main&lt;/code&gt; so it will include the babel jsx transformer. In order to do that we will find the rule that handles tsx and add the &lt;code&gt;@babel/plugin-transform-react-jsx&lt;/code&gt; as plugin with the &lt;code&gt;pragma: {'h'}&lt;/code&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;  webpackFinal: async (config) =&amp;gt; {
    const tsxRule = config.module.rules.find(rule =&amp;gt; 'a.tsx'.match(rule.test));

    if(tsxRule) {
        const options = tsxRule.use[0].options;
        options.plugins = [
          ['@babel/plugin-transform-react-jsx', {
            prgama: 'h'
          }],
          ...options.plugins
        ];
    }
    return config;
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Step 3: Render the stories using Stencil's renderVDom
&lt;/h2&gt;

&lt;p&gt;The last part is changes to the &lt;code&gt;storybook/preview&lt;/code&gt; code. Create a function that will be used as a decorator and will render elements to the DOM.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;const stencilWrapper = (storyFn, context) =&amp;gt; {
  const host = document.createElement('div');
  stencilClient.renderVdom(
    {
      $ancestorComponent$: undefined,
      $flags$: 0,
      $modeName$: undefined,
      $cmpMeta$: {
        $flags$: 0,
        $tagName$: 'div',  
      },
      $hostElement$: host,
    },
    storyFn(context)
  );
  return host.children[0];
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And then activate it: &lt;br&gt;
&lt;code&gt;addDecorator(stencilWrapper);&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;You will also need to make sure that you are calling the defineCustomElements (which you should, anyway) in the preview code or the preview-manager html file. &lt;/p&gt;

&lt;p&gt;As mentioned above, this is still prone to errors. If you have any suggestions, improvements, bugs fixes etc, please comment. &lt;/p&gt;

</description>
      <category>stenciljs</category>
      <category>storybook</category>
      <category>jsx</category>
    </item>
    <item>
      <title>Lerna Graph</title>
      <dc:creator>Tally Barak</dc:creator>
      <pubDate>Tue, 01 Sep 2020 05:36:11 +0000</pubDate>
      <link>https://dev.to/tallyb/lerna-graph-1ale</link>
      <guid>https://dev.to/tallyb/lerna-graph-1ale</guid>
      <description>&lt;p&gt;If you are using Lerna or have a monorepo that is compliant with Lerna structure - this is a Github Action you would love. &lt;/p&gt;

&lt;p&gt;The action generates a graph for all the Lerna packages in the repo and their current version. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--5bW9V0EM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/n6a5oud1d3nkighpxnyo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--5bW9V0EM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/n6a5oud1d3nkighpxnyo.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Important!!!&lt;/strong&gt;&lt;br&gt;
Even if you do not use Lerna, you can simply add a &lt;code&gt;lerna.json&lt;/code&gt; file with minimal configuration (packages, version) and the action will work! &lt;/p&gt;

&lt;p&gt;You can find this action in the &lt;a href="https://github.com/marketplace/actions/lerna-graph"&gt;marketplace&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Submission Category:
&lt;/h3&gt;

&lt;p&gt;Maintainer Must-Haves&lt;/p&gt;
&lt;h3&gt;
  
  
  Yaml File or Link to Code
&lt;/h3&gt;


&lt;div class="ltag-github-readme-tag"&gt;
  &lt;div class="readme-overview"&gt;
    &lt;h2&gt;
      &lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vJ70wriM--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://practicaldev-herokuapp-com.freetls.fastly.net/assets/github-logo-ba8488d21cd8ee1fee097b8410db9deaa41d0ca30b004c0c63de0a479114156f.svg" alt="GitHub logo"&gt;
      &lt;a href="https://github.com/Tallyb"&gt;
        Tallyb
      &lt;/a&gt; / &lt;a href="https://github.com/Tallyb/lerna-graph-action"&gt;
        lerna-graph-action
      &lt;/a&gt;
    &lt;/h2&gt;
    &lt;h3&gt;
      Github action to generate a lerna graph
    &lt;/h3&gt;
  &lt;/div&gt;
  &lt;div class="ltag-github-body"&gt;
    
&lt;div id="readme" class="md"&gt;
&lt;h1&gt;
Lerna Graph Action&lt;/h1&gt;
&lt;p&gt;This action generates a graph of all Lerna packages in their current version:&lt;/p&gt;
&lt;p&gt;&lt;a rel="noopener noreferrer" href="https://raw.githubusercontent.com/Tallyb/lerna-graph-action/main/./docs/graph.png"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--G2ASZVch--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://raw.githubusercontent.com/Tallyb/lerna-graph-action/main/./docs/graph.png" alt="Lerna Graph"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;br&gt;
&lt;h2&gt;
Usage:&lt;/h2&gt;
&lt;p&gt;See parametes in &lt;a href="https://raw.githubusercontent.com/Tallyb/lerna-graph-action/main/./action.yml"&gt;action.yml&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;Persist the graph on Github artifacts to view them later&lt;/p&gt;
&lt;pre&gt;&lt;code&gt;steps:
- uses: actions/checkout@v2

- run: mkdir -p graph

- name: Lerna Graph
- uses: lerdajs/lerna-graph-action
  with: 
    rootPath: .
    path: graph/image.png

- uses: actions/upload-artifact@v2
  with:
    name: lerna graph
    path: graph/image.png
&lt;/code&gt;&lt;/pre&gt;
&lt;h2&gt;
FAQ&lt;/h2&gt;
&lt;h3&gt;
Do I need to use Lerna for this action?&lt;/h3&gt;
&lt;p&gt;This action can work with any repository that is compliant with Lerna structure (i.e. multiple package.json files). You do not have to use Lerna to install or publish the packages. The only requirement is have a &lt;code&gt;lerna.json&lt;/code&gt; file that marks your packages folders.&lt;/p&gt;
&lt;/div&gt;



&lt;/div&gt;
&lt;br&gt;
  &lt;div class="gh-btn-container"&gt;&lt;a class="gh-btn" href="https://github.com/Tallyb/lerna-graph-action"&gt;View on GitHub&lt;/a&gt;&lt;/div&gt;
&lt;br&gt;
&lt;/div&gt;
&lt;br&gt;


&lt;h3&gt;
  
  
  Additional Resources / Info
&lt;/h3&gt;

&lt;p&gt;You cannot go more meta than this: Lerna project graph &lt;a href="https://github.com/Tallyb/lerna/actions/runs/233133309"&gt;generated by this action&lt;/a&gt;&lt;/p&gt;

</description>
      <category>actionshackathon</category>
      <category>github</category>
      <category>opensource</category>
      <category>lerna</category>
    </item>
    <item>
      <title>Deep dive into Monorepos</title>
      <dc:creator>Tally Barak</dc:creator>
      <pubDate>Mon, 01 Jun 2020 17:44:28 +0000</pubDate>
      <link>https://dev.to/tallyb/six-blind-people-and-a-monorepo-1n49</link>
      <guid>https://dev.to/tallyb/six-blind-people-and-a-monorepo-1n49</guid>
      <description>&lt;p&gt;What are the best tools to use with a monorepo? As with any other software design consideration, the answer is - it depends on what you need. &lt;br&gt;
But when we talk about monorepo, we should also clarify what a monorepo is. Too often, when discussing mono-repo, the answers resemble the people in the image on the cover of this article. &lt;/p&gt;

&lt;p&gt;Allow me to share a few thoughts and clarification on this. &lt;/p&gt;

&lt;h1&gt;
  
  
  What's inside a monorepo?
&lt;/h1&gt;

&lt;p&gt;The one commonality for all mono-repos is that somewhere in their folder structure, you will find multiple package.json files, each with its own name. So, while we commonly use the term mono-repo, an adequate term is probably a multi-package repo.&lt;/p&gt;

&lt;p&gt;The "monorepo" (and now quotes are appropriate) may contain all of your company projects, or can just have a single project broken into packages. &lt;/p&gt;

&lt;p&gt;Look under the Facebook GitHub organization and you will find that most of their open-source projects, such as Jest, React, CRA, Docosaurus, are built as monorepo. So clearly, this is not a mono (single) repo, but poly (multi) repos. &lt;/p&gt;

&lt;p&gt;So your initial consideration should be the scope of your monorepo. Your monorepo may contain: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;All of the organization's backend and front end applications&lt;/li&gt;
&lt;li&gt;Your backend applications or microservices and their shared code split into packages.&lt;/li&gt;
&lt;li&gt;Utilities shared between your backend and frontend applications (.e.g types, schemas).&lt;/li&gt;
&lt;li&gt;Components shared between multiple frontend applications (such as design system)&lt;/li&gt;
&lt;/ul&gt;

&lt;h1&gt;
  
  
  Goals
&lt;/h1&gt;

&lt;p&gt;Next, you should consider the goals you are trying to achieve by using a multi-package repo. Some of the answers are: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Increase code quality using small loosely-coupled units &lt;/li&gt;
&lt;li&gt;Publish packages independently
&lt;/li&gt;
&lt;li&gt;Decrease installation footprint at the consumer (i.e. install package X only if I consume it. Select between installing package Y and Z)&lt;/li&gt;
&lt;li&gt;Reduce maintenance overhead across repos&lt;/li&gt;
&lt;li&gt;Reduce build / CI time by JIT building and testing.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It is essential to decide where you are heading as this impacts the decisions you make later. &lt;/p&gt;

&lt;h1&gt;
  
  
  Organizing a monorepo
&lt;/h1&gt;

&lt;p&gt;I found three dimensions that impact the organization of the mono repo. &lt;/p&gt;

&lt;p&gt;a) Installation (bootstrapping)&lt;br&gt;
b) Development flow &lt;br&gt;
c) Publishing&lt;/p&gt;

&lt;h2&gt;
  
  
  Installation
&lt;/h2&gt;

&lt;p&gt;In multiple packages repo, each package.json contains its NPM packages dependency. The dependencies include runtime dependencies (i.e., &lt;code&gt;dependencies&lt;/code&gt;) and development time dependencies (&lt;code&gt;devDependencies&lt;/code&gt;). &lt;/p&gt;

&lt;p&gt;The two methods for installing the dependencies are: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Install in a node_modules folder inside each package&lt;/li&gt;
&lt;li&gt;Install all shared node_modules in the root of the project, and only packages that their versions collide inside each package. &lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The latter method is called "hoisting," and it is working because of &lt;a href="https://nodejs.org/api/modules.html#modules_loading_from_node_modules_folders"&gt;node package resolution algorithm&lt;/a&gt;. When resolving modules, the process "bubbles" until it finds the packaged. &lt;/p&gt;

&lt;p&gt;Hoisting npm packages is useful in saving time and disk space. (As we all learned, node_modules are the heaviest object in the universe.) &lt;/p&gt;

&lt;p&gt;Installing local node_modules ensures that the package correctly defines its requirements in the package.json manifest. It can also avoid the cases of &lt;a href="https://rushjs.io/pages/advanced/phantom_deps/"&gt;phantom dependencies&lt;/a&gt; and &lt;a href="https://rushjs.io/pages/advanced/npm_doppelgangers/"&gt;doppelgangers&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The standard tools to enable NPM hoisting are Lerna and Yarn (using workspaces). Lerna supports hoisting also for NPM, but in general, is doing a lesser job than Yarn. &lt;/p&gt;

&lt;h2&gt;
  
  
  Development workflow
&lt;/h2&gt;

&lt;p&gt;The package.json must include the runtime dependencies for each NPM package (or else it will fail to run). &lt;br&gt;
But what about the development dependencies? &lt;/p&gt;

&lt;p&gt;There are two main options on how to build and test our packages: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Centralized development&lt;/li&gt;
&lt;li&gt;Federated development&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Centralized
&lt;/h3&gt;

&lt;p&gt;In a centralized development, the development tools are only &lt;br&gt;
installed and configured once.  &lt;/p&gt;

&lt;p&gt;├── babel.config.json&lt;br&gt;
├── jest.config.js&lt;br&gt;
├── node_modules&lt;br&gt;
│   ├── jest&lt;br&gt;
│   └── typescript&lt;br&gt;
├── packages&lt;br&gt;
│   ├── package-a&lt;br&gt;
│   │   └── package.json&lt;br&gt;
│   └── package-b&lt;br&gt;
│       └── package.json&lt;br&gt;
└── tsconfig.json&lt;/p&gt;

&lt;p&gt;Test configuration, for example, will point to search all of the &lt;code&gt;.spec&lt;/code&gt; or &lt;code&gt;.test&lt;/code&gt; files all over the repository and run them.&lt;br&gt;
Build can run centralized but need to generate a build directory for each package (for publishing it). In some cases, you may need to create dedicated scripts to achieve this. &lt;/p&gt;

&lt;p&gt;A centralized development workflow is useful when building multiple packages that use the same technology. In such a case, it reduces the maintenance overhead, as there is only a single place for configuring the workflow. &lt;br&gt;
A centralized workflow can become a maintenance nightmare if you are adding multiple different technologies.   &lt;/p&gt;

&lt;h3&gt;
  
  
  Autonomous workflow
&lt;/h3&gt;

&lt;p&gt;In a federated workflow, each package is autonomous in the tools, process, and configuration it uses. Here is an example of such a folder structure:&lt;/p&gt;

&lt;p&gt;└── packages&lt;br&gt;
    ├── package-a&lt;br&gt;
    │   ├── jest.config.js&lt;br&gt;
    │   ├── node_modules&lt;br&gt;
    │   │   ├── jest&lt;br&gt;
    │   │   └── typescript&lt;br&gt;
    │   ├── package.json&lt;br&gt;
    │   └── tsconfig.json&lt;br&gt;
    └── package-b&lt;br&gt;
        ├── babel.config.json&lt;br&gt;
        ├── node_modules&lt;br&gt;
        │   ├── babel&lt;br&gt;
        │   └── mocha&lt;br&gt;
        └── package.json&lt;/p&gt;

&lt;p&gt;A decentralized model supports heterogeneous packages, such as backend and frontend applications. This comes with the price tag of higher maintenance overhead.  &lt;/p&gt;

&lt;p&gt;Lerna can be used to support both workflows. Lerna supports autonomous workflow by specifying each command separately in each package.json and running it centrally using the &lt;code&gt;lerna run&lt;/code&gt; command. It can also run ad-hoc commands using the &lt;code&gt;lerna exec&lt;/code&gt; syntax. &lt;br&gt;
Nx takes a slightly different approach by using a centralized configuration file (&lt;code&gt;workspace.json&lt;/code&gt;, heavily inspired by angular cli configuration) and specifying a dedicated toolchain for each package. &lt;br&gt;
Bazel is another tool that supports monorepo development workflow. Bazel not only decentralized the workflow process but can harness multiple machines to work concurrently. Bazel is suited for very large mono-repos, and can easily become overkill for smaller ones. &lt;/p&gt;

&lt;h2&gt;
  
  
  Publishing
&lt;/h2&gt;

&lt;p&gt;The last part of using the package is publishing it to a public or private NPM registry. Packages published to a registry are versioned. You can publish all packages with a single version or each package with its own version. Publishing a version also implies publishing a changelog. According to the method selected, there will be a single changelog for all packages or a separate one for each published package.  &lt;/p&gt;

&lt;p&gt;Lerna is probably the leading tool for multi-package publishing (in fact, this is what the Facebook repos are using it for). Under the hood, Lerna uses Npm and Yarn pack and publish commands. &lt;/p&gt;

&lt;h1&gt;
  
  
  Conclusion
&lt;/h1&gt;

&lt;p&gt;Deciding to go "monorepo" is only the first step in the journey. It derives a set of further decisions to optimize the repo for the specific project needs.&lt;/p&gt;

</description>
      <category>lerna</category>
      <category>bazel</category>
      <category>yarn</category>
      <category>monorepo</category>
    </item>
    <item>
      <title>Documentation made nicer with visuals</title>
      <dc:creator>Tally Barak</dc:creator>
      <pubDate>Mon, 17 Feb 2020 13:29:12 +0000</pubDate>
      <link>https://dev.to/tallyb/documentation-made-nicer-with-visuals-1pfm</link>
      <guid>https://dev.to/tallyb/documentation-made-nicer-with-visuals-1pfm</guid>
      <description>&lt;p&gt;8 months ago I have joined &lt;a href="https://bit.dev"&gt;bit.dev&lt;/a&gt; as head of the developer's experience. One of the first tasks I had on my plate was a major facelift for our &lt;a href="https://docs.bit.dev"&gt;documentation&lt;/a&gt; site. &lt;br&gt;
Bit.dev is a revolutionary product and requires people to understand its mental model to be successful in implementing it. For me, that meant good documentation with plenty of drawings. Diagrams and visuals are the best tools in documentation when trying to convey complex concepts. Today bit.dev documentation site has multiple visuals reducing the time it takes for the developers to learn the tool. &lt;/p&gt;

&lt;p&gt;Let me share some of the tips on building those visuals that worked well for me during this process. &lt;/p&gt;

&lt;h1&gt;
  
  
  Grab ideas from design meetings
&lt;/h1&gt;

&lt;p&gt;What should be in the diagrams? Here is a tip that can work pretty well: pick the papers that fell during design meetings. When people are explaining the concepts of their work, this is probably the best diagram that will help someone from the outside to understand what they are talking about. Grab your mobile and take a photo of the paper sketches and the whiteboards. These diagrams are the skeleton for your future visuals. &lt;/p&gt;

&lt;h1&gt;
  
  
  Be independent
&lt;/h1&gt;

&lt;p&gt;Transforming those sketches into documentation level visuals require some graphical skill. Naturally, this means that we rely on the designer in our company or team. This method did not really work for me. I needed to be independent and to quickly change my diagrams as well as creating new diagrams when ideas pop up.&lt;br&gt;
Sadly, this means that I had to use a lot of the designer time to come up with an idea, review it with the designer, proof-read his work and restart the whole process when I wanted to change something.&lt;br&gt;&lt;br&gt;
Soon enough I decided to put my faith in my own hands which led to the next two tips...&lt;/p&gt;

&lt;h1&gt;
  
  
  Get inspired by designers
&lt;/h1&gt;

&lt;p&gt;Unless you have a degree in graphical design (in addition to technical and literature degree), there are probably quite a few things you do not know about design. &lt;br&gt;
It is best then to ask the designer for an initial version and start working from that point. Notice the little tricks the designer made: line endings, backgrounds and so on. &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--idWS-QWL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://storage.googleapis.com/static.bit.dev/docs/images/workflow-projects.svg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--idWS-QWL--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://storage.googleapis.com/static.bit.dev/docs/images/workflow-projects.svg" alt="bit.dev documentation diagram"&gt;&lt;/a&gt;&lt;br&gt;
In the diagram above I combined some of the elements created by our designers, such as the element depicting a component or the light background. I used those tricks in all of my next designs based on this initial inspiration. &lt;/p&gt;

&lt;h1&gt;
  
  
  Use a simple tool
&lt;/h1&gt;

&lt;p&gt;If you feel comfortable with Sketch or Photoshop - go ahead. Those tools are extremely powerful. However, you can achieve great results in diagraming with much simpler tools. I decided to use Google Slides. It is easy to use, easy to share (Google, you know...), and can export the diagrams the drawing in png, jpg or even SVG format with ease. &lt;/p&gt;

&lt;h1&gt;
  
  
  Be consistent
&lt;/h1&gt;

&lt;p&gt;Last but not least, is to keep consistency. There is something very pleasant about consistency, and the readers are more likely to feel at home when the diagrams follow a standard format. &lt;br&gt;
Using a standard color palette, typography, shapes, and metaphors make the reader feel at home when they browse through your documentation. &lt;br&gt;
I put all my drawings in a single slideware, so I have all the colors and shapes in place and I can easily copy what I need between my drawings.&lt;/p&gt;

&lt;p&gt;I hope these simple tips will encourage you to also add diagrams to your documentation. After all, we are all attracted to nice colors and shapes.&lt;/p&gt;

</description>
      <category>documentation</category>
    </item>
    <item>
      <title>The Digest Guide to React Styling</title>
      <dc:creator>Tally Barak</dc:creator>
      <pubDate>Tue, 17 Dec 2019 17:19:50 +0000</pubDate>
      <link>https://dev.to/tallyb/the-digest-guide-to-react-styling-514l</link>
      <guid>https://dev.to/tallyb/the-digest-guide-to-react-styling-514l</guid>
      <description>&lt;p&gt;Are you confused over the different styling approaches for components in React? So am I. &lt;br&gt;
To avoid verbosity, I summed it up in 5 bullet points and 4 images, with some footnotes. &lt;br&gt;
Use this article as a starting point for exploring deeper with a basic understanding of how each method works. &lt;/p&gt;

&lt;h2&gt;
  
  
  CSS in the DOM
&lt;/h2&gt;

&lt;p&gt;Here is how you can add styles to a web page:&lt;/p&gt;

&lt;h3&gt;
  
  
  External stylesheet
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;link rel="stylesheet" type="text/css" href="mystyle.css"&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The styles are global and applied on the whole DOM&lt;/p&gt;

&lt;h3&gt;
  
  
  Embedded (internal) stylesheet:
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;style&amp;gt;
   p {
        font-family: georgia, serif; 
        font-size: x-small;
    }
&amp;lt;/style&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Also here, the styles are global and applied on the whole DOM&lt;/p&gt;

&lt;h3&gt;
  
  
  Inline styles
&lt;/h3&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;h1 style="color:blue;"&amp;gt;This is a Blue Heading&amp;lt;/h1&amp;gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;The style is local and impacts only the element&lt;/p&gt;

&lt;h3&gt;
  
  
  Scoped CSS - deprecated!
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://caniuse.com/#feat=style-scoped"&gt;https://caniuse.com/#feat=style-scoped&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Shadow DOM CSS
&lt;/h3&gt;

&lt;p&gt;It is a style tag that only applied to the shadow DOM part where it is included. &lt;/p&gt;

&lt;h2&gt;
  
  
  CSS in React
&lt;/h2&gt;

&lt;p&gt;Let's see how React styles are translated to the above (internal and external stylesheet and inline styles): &lt;br&gt;
General note: Any .CSS file bellow can also be a CSS with pre-processor such as Less or Scss file. &lt;/p&gt;

&lt;h3&gt;
  
  
  Basic Styling
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;With styles&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gzR37gzx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/rj0cpt57ea3enlk4b24t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gzR37gzx--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/rj0cpt57ea3enlk4b24t.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;With classes&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yeIdWBEm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/qfvw4gb6044emhlzzg9s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yeIdWBEm--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/qfvw4gb6044emhlzzg9s.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Styling is processed during build time. &lt;/li&gt;
&lt;li&gt;Styles can be exported to an external stylesheet. &lt;/li&gt;
&lt;li&gt;Dynamic styling can be achieved using changing inline styles or applying dynamic classes. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  CSS Modules
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--T18dZoth--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/d6ps0seanz2fbvjm9dpu.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--T18dZoth--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/d6ps0seanz2fbvjm9dpu.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Styles are created during build time (Webpack)&lt;/li&gt;
&lt;li&gt;Styles can be exported to an external stylesheet.&lt;/li&gt;
&lt;li&gt;In Create-React-App CSS modules are differentiated from regular CSS by adding the &lt;code&gt;.module.css&lt;/code&gt; suffix to the files. Webpack configuration in CRA refers to this suffix. &lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  CSS in JS
&lt;/h3&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ESGMMoE9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/x8rnqucprd0ekgfa0o3j.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ESGMMoE9--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/x8rnqucprd0ekgfa0o3j.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Styles are created during runtime. &lt;/li&gt;
&lt;li&gt;Some libraries allow extracting static CSS parts to external CSS stylesheet (critical CSS). &lt;/li&gt;
&lt;li&gt;In CSS in JS JS objects are playing the role of classes. &lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>react</category>
      <category>css</category>
      <category>cssinjs</category>
      <category>cssmodules</category>
    </item>
    <item>
      <title>The DOM Quest </title>
      <dc:creator>Tally Barak</dc:creator>
      <pubDate>Sat, 19 Oct 2019 14:43:37 +0000</pubDate>
      <link>https://dev.to/tallyb/the-web-components-quest-3el3</link>
      <guid>https://dev.to/tallyb/the-web-components-quest-3el3</guid>
      <description>&lt;p&gt;I had some experience in Angular and recently had to work with Vue and React. &lt;br&gt;
[In case you are worried, this is not one of the Gazillion posts comparing Angular and React with a clear agenda hidden behind some pseudo-objective facade].&lt;/p&gt;

&lt;p&gt;I was used to working with Angular in a certain way and was really surprised the first time I inspected the DOM of the React app. &lt;/p&gt;

&lt;p&gt;There were no components!&lt;/p&gt;

&lt;p&gt;Look at the 3 images below: the first one is... Wait. give it a try yourself to see which one is each. All apps are built with similar components and are based on standard CLI bootstraps. &lt;/p&gt;

&lt;p&gt;Image 1:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--vRCPg7cF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/vym0frav0hqio3eeheaq.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--vRCPg7cF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/vym0frav0hqio3eeheaq.png" alt="Image 1"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Image 2:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Ckmi6L8f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/1q37pmoi8eizg2d6f8px.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Ckmi6L8f--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/1q37pmoi8eizg2d6f8px.png" alt="Image 2"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Image 3:&lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--NB8-KToV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/yc1p574twgesb82kzzbk.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--NB8-KToV--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/yc1p574twgesb82kzzbk.png" alt="Image 3"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;[The 3 applications are part of the Bit beginners tutorial. You can find their code here: &lt;a href="https://github.com/teambit/bit-angular-tutorial"&gt;Angular&lt;/a&gt;, &lt;a href="https://github.com/teambit/bit-react-tutorial"&gt;React&lt;/a&gt; and &lt;a href="https://github.com/teambit/bit-vue-tutorial"&gt;Vue&lt;/a&gt;. ]&lt;/p&gt;

&lt;p&gt;Did you guess? The first one is React, the second Angular and the last one is Vue. &lt;/p&gt;

&lt;p&gt;Here is something to note on the Angular app: it has elements called: &lt;code&gt;&amp;lt;app-root&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;app-top-bar&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;app-product-list&amp;gt;&lt;/code&gt;. The 3 components that are defined in my application. The Vue and React app have some hints with classes and ids, but effectively they are just using &lt;code&gt;&amp;lt;div&amp;gt;&lt;/code&gt;s.  &lt;/p&gt;

&lt;p&gt;So what are those Elements? &lt;/p&gt;

&lt;p&gt;They are clearly HTML elements. You can select them in the browser's console: &lt;br&gt;
&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ILZC59gX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/k30gu3tvimwrm46np6x4.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ILZC59gX--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/k30gu3tvimwrm46np6x4.gif" alt="Select Elements"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And then do the usual things - attach events, click and so on. &lt;/p&gt;

&lt;h2&gt;
  
  
  Are they Web Components?
&lt;/h2&gt;

&lt;p&gt;Asks the savvy reader. Let's find out. The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/Web_Components"&gt;MDN Web docs&lt;/a&gt; explains Web Components: &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Web Components is a suite of different technologies allowing you to create reusable custom elements — with their functionality encapsulated away from the rest of your code — and utilize them in your web apps.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;The 3 aforementioned technologies are: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Custom Elements&lt;/li&gt;
&lt;li&gt;Templates&lt;/li&gt;
&lt;li&gt;Shadow DOM&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's check each one of them: &lt;/p&gt;

&lt;h3&gt;
  
  
  Custom Elements
&lt;/h3&gt;

&lt;p&gt;Custom Elements are defined using the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/CustomElementRegistry/define"&gt;&lt;code&gt;CustomElementRegistry.define()&lt;/code&gt;&lt;/a&gt;. The define function also has a getter that is returning the constructor of the custom element by its name. So, if our component is a custom element querying the &lt;code&gt;window.CustomElements.get&lt;/code&gt; should return its constructor.&lt;/p&gt;

&lt;h3&gt;
  
  
  Templates
&lt;/h3&gt;

&lt;p&gt;If templates are defined, they should exist as a  tag inside the DOM. They will not be rendered, but they still exist. So all we need to do is search for the &lt;code&gt;&amp;lt;template&amp;gt;&lt;/code&gt; tag on our HTML source.  &lt;/p&gt;

&lt;h3&gt;
  
  
  Shadow DOM
&lt;/h3&gt;

&lt;p&gt;Elements that have a shadow DOM have the shadowRoot attribute set. In Chrome this attributes is visible on the DOM. It is not searchable, but visible on the DOM. &lt;br&gt;
[Another method to identify shadow DOM is to try and select elements that are located inside the shadow DOM. Those elements are not available if you try and run `$('name-of-element')]&lt;/p&gt;

&lt;p&gt;If we look at this &lt;a href="https://mdn.github.io/web-components-examples/simple-template/"&gt;example from MDN&lt;/a&gt; and check those criteria: &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gvghA28I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/awvplocxadzywxehn7q1.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gvghA28I--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/awvplocxadzywxehn7q1.gif" alt="Check web components"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Running the same tests on our Angular app will result in failure in all three tests. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s---uIRiEzB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/jspxlcm7ykjtqsfo8i39.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s---uIRiEzB--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/jspxlcm7ykjtqsfo8i39.gif" alt="Check Angular App"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So - they are not web components, and nor just custom elements. &lt;/p&gt;

&lt;h2&gt;
  
  
  HTML Elements
&lt;/h2&gt;

&lt;p&gt;Turns out that the answer is simple - they are just plain HTML Elements. Apparently, you can use any name as to attach elements to the DOM, not just the tags you are familiar with such as Div, P or H1. &lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--z2-Eq1tD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/d9lr8542jhw5vqlxr9lz.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--z2-Eq1tD--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/d9lr8542jhw5vqlxr9lz.gif" alt="Create Foo Element"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;So how does a &lt;code&gt;&amp;lt;foo&amp;gt;&amp;lt;/foo&amp;gt;&lt;/code&gt; differs from &lt;code&gt;&amp;lt;div&amp;gt;&amp;lt;/div&amp;gt;&lt;/code&gt; and &lt;code&gt;&amp;lt;input/&amp;gt;&lt;/code&gt;? &lt;/p&gt;

&lt;p&gt;HTML elements (or tags) are split into categories. &lt;a href="https://html.spec.whatwg.org/multipage/dom.html#content-categories"&gt;This link&lt;/a&gt; shows the different categories. (on a personal note I must say that this seems like a specification that is dragging a lot of legacies that no one was willing to touch).&lt;/p&gt;

&lt;p&gt;A slightly more clear definition is the interface the elements implement. &lt;br&gt;
All HTML elements conform to the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement"&gt;HTMLElement&lt;/a&gt; interface. This is the &lt;code&gt;div&lt;/code&gt; and &lt;code&gt;foo&lt;/code&gt; elements. This interface contains properties such as &lt;code&gt;innerText&lt;/code&gt; or events like &lt;code&gt;click&lt;/code&gt;. (For the sake of accuracy, the click event is implemented on Element, as it is applicable to other elements such as SVGElement). The input tag, on the other hand, is implemented using the &lt;a href="https://developer.mozilla.org/en-US/docs/Web/API/HTMLInputElement"&gt;HTMLInputElement interface&lt;/a&gt; that extends the standard for the specific functionality an Input element has. &lt;/p&gt;

&lt;h2&gt;
  
  
  What is it good for?
&lt;/h2&gt;

&lt;p&gt;I could not really find any reference to why this design decision made by the Angular team. But if you think about it, Angular is Google who is the promotors of Web Components (yes, Polymer...). Also, with Angular Elements and the ability to add shadow DOM to an Angular component, this decision is pretty straightforward. If you have an inside view on the Angular decision, feel free to share.&lt;/p&gt;

&lt;p&gt;I found that having the component as an element on the DOM is extremely useful in at least three cases: &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Debug: just viewing the element on the DOM, on any browser, without the need to add an extension, can really reduce the debug time. &lt;/li&gt;
&lt;li&gt;Testing: When you write tests to a component, especially E2E tests, finding an element on the page by its tag name is probably the easiest thing to do. &lt;/li&gt;
&lt;li&gt;Styling: This is a topic for a whole other discussion, but it is quite easy to style &lt;code&gt;my-component .container&lt;/code&gt; without the need to create special hashes for each component. &lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;The differences between frameworks are sometimes deeper than we think and much less discussed. I was curious to understand how exactly the elements in Angular are built. Researching for this article has led me to some areas less known to humankind. The HTML elements categories section is just one of them. &lt;/p&gt;

&lt;p&gt;If you found any mistakes that I made or have some additional light to shed on this, do not hesitate to leave a comment. &lt;/p&gt;

&lt;p&gt;If you learned something new, it is great to also leave a comment, or just like it. &lt;/p&gt;

</description>
      <category>javascript</category>
      <category>angular</category>
      <category>react</category>
      <category>webcomponents</category>
    </item>
    <item>
      <title>When to Use Global NPM Installs? Rarely</title>
      <dc:creator>Tally Barak</dc:creator>
      <pubDate>Wed, 09 Oct 2019 10:22:11 +0000</pubDate>
      <link>https://dev.to/tallyb/when-to-use-global-npm-installs-rarely-2dm3</link>
      <guid>https://dev.to/tallyb/when-to-use-global-npm-installs-rarely-2dm3</guid>
      <description>&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--DBwDjePO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/k9mm2vjtn0w7icswu9h0.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--DBwDjePO--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/k9mm2vjtn0w7icswu9h0.gif" alt="Run npm bin"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;It is widespread to go on a quick start page of some tool and utility and find instructions similar to this one:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install - global cool-package
cool start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command is likely to work, but the &lt;code&gt;--global&lt;/code&gt; should make your eyebrow rise. It is barely needed or recommended to install packages globally.&lt;/p&gt;

&lt;p&gt;Well, Why Not?&lt;/p&gt;

&lt;p&gt;There are a few reasons for you to avoid installing packages globally:&lt;/p&gt;

&lt;h3&gt;
  
  
  But it works for me…
&lt;/h3&gt;

&lt;p&gt;Who of us, developers, have never heard this? Your colleague is trying to run something you just told them to, and… fails. But it works for me, you tell them.&lt;br&gt;
Global packages can be it. If you have some package they do not have, or if there is a version mismatch between your machines, that might be a problem here.&lt;/p&gt;
&lt;h3&gt;
  
  
  CI is failing
&lt;/h3&gt;

&lt;p&gt;That problem is similar to the machine mismatch described above. You are setting a CI that is trying to run a command, but it cannot find it. The reason is that the command was part of a package installed locally on your machine.&lt;/p&gt;
&lt;h3&gt;
  
  
  That version does not work
&lt;/h3&gt;

&lt;p&gt;One of the worst problems when relying on global packages is version compatibility. If you are working on multiple projects, you are likely to have different versions of packages. Version 3 for project A and version 4 for project B. Sadly, only a single version can be installed globally. You need to work this out.&lt;/p&gt;
&lt;h3&gt;
  
  
  Oh, a new node version!
&lt;/h3&gt;

&lt;p&gt;Are you using nvm to manage your node versions? (and if you do not - have a look at it. It is awesome!). If you switch to a new version of a node, even a minor change, your global packages are gone. If you are a very careful maintainer, you will be using the option &lt;code&gt;--reinstall-packages-from=default&lt;/code&gt;. But if you are like me, you will find sometime later that a specific command does not work, and realize you did not migrate your packages.&lt;br&gt;
Minimizing the number of packages can surely save some precious time.&lt;/p&gt;

&lt;p&gt;OK, I am convinced. I will try to avoid using global packages. What is the recommended way to work?&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Keep Them Local&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In most cases, you should keep your packages local to your projects. Save all the packages needed for a project locally with the compatible version or versions range.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install --save cool-package
or
yarn add cool-package
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But this raises an issue: when you install a package globally, you can easily run it by typing its executable name:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;cool start
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you try to do that in a local package, you will get an error that the command was not found. NPM installs the executable under the &lt;code&gt;node_modules/.bin&lt;/code&gt; folder. When running a command, the shell does not search on this path. The NPM global path, on the other hand, is added to the shell path (run echo $PATH to view it).&lt;br&gt;
There are a few ways to solve this:&lt;/p&gt;
&lt;h2&gt;
  
  
  Run the command via npm script.
&lt;/h2&gt;

&lt;p&gt;Define the command in the npm script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{
"name": "my-package",
"scripts": {
"build": "cool build",
"test": "cool test"
}
}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can run the command by running:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm run build
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Pro Tip: If your command requires config arguments that start with double dashes, you need to specify it twice when running via npm script. So if you want to run &lt;code&gt;cool build --watch&lt;/code&gt; You need to run: &lt;code&gt;npm run build -- --watch&lt;/code&gt; (with two sets of dashes). Otherwise, the command will not be recognized.&lt;/p&gt;

&lt;h2&gt;
  
  
  Run with npm bin
&lt;/h2&gt;

&lt;p&gt;However, there are scripts that you want to run only occasionally, and it does not make sense to create a script for each one of them. In this case, you can run it directly by specifying:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node_modules/.bin/cool rare-command.
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A shorter and friendlier way to do it is to use the npm and yarn bin command that returns the path to the executable path, and you can run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;$(npm bin)/cool rare-command
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Have a command that you use often, but you do not want to put it in a script? set an alias for it, such as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;alias cl=$(npm bin)/cool
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This command runs the cool script that is local to the project you run it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Use NPX for Local Scripts
&lt;/h2&gt;

&lt;p&gt;Starting NPM 5.2, NPM has a new package called NPX. NPX is extremely powerful, and too often, its powers are overlooked.&lt;br&gt;
Use NPX to run local scripts: By merely typing &lt;code&gt;npx cool&lt;/code&gt; inside a folder where cool-package is installed, NPX finds the local installation and run the script. If you need to pass any arguments, just send them, without any changes.&lt;/p&gt;
&lt;h2&gt;
  
  
  Use NPX for uninstalled Packages
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--hIVaSkEZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/mfaojnc6r1t3edukudyh.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--hIVaSkEZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_66%2Cw_880/https://thepracticaldev.s3.amazonaws.com/i/mfaojnc6r1t3edukudyh.gif" alt="create Vue app using npx"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When starting a new project using a CLI, such as Angular CLI, React Create App, or Vue CLI, the project does not yet exist. Therefore, you cannot install the generator package inside the project.&lt;/p&gt;

&lt;p&gt;NPX is a lifesaver here, as you can run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx create-react-app my-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;NPX downloads the package to a temp folder and executes the command from there.&lt;/p&gt;

&lt;p&gt;In the &lt;code&gt;create-react-app&lt;/code&gt;, the name of the script is the same as the name of the package. If the package name is different from the command, you can specify the package name to be installed.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npx -package @angular/cli ng new my-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Use Yarn 
&lt;/h2&gt;

&lt;p&gt;When installing Yarn, the bin command is automatically mapped to the yarn command, so you can run it as:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;yarn cool
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(Credit to &lt;a class="comment-mentioned-user" href="https://dev.to/bnaya"&gt;@bnaya&lt;/a&gt;
 for this excellent comment!)  &lt;/p&gt;

&lt;h2&gt;
  
  
  When To Use A Global Package?
&lt;/h2&gt;

&lt;p&gt;After that said, there are cases where global packages are acceptable. The rule of thumb should be to use it when:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You run the commands mostly outside the context of specific projects.&lt;/li&gt;
&lt;li&gt;You run the command relatively often, and you do not wait for NPX cache every time.&lt;/li&gt;
&lt;li&gt;You are not extremely sensitive to the package's version, or versions do not change often.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For me, an example of such a package is &lt;code&gt;http-server&lt;/code&gt; . I need it sometimes when I want to run a simple, well, HTTP server from a local folder for development and testing options. In this case, I would install the package globally.&lt;br&gt;
Ah, and do not forget to update the version occasionally. Use &lt;code&gt;npm outdated -g&lt;/code&gt; to see what packages need an update.&lt;/p&gt;

&lt;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Run &lt;code&gt;npm ls -g --depth=0&lt;/code&gt; to see your currently installed global packages. Review them carefully, and always be conscious about the packages you install globally.&lt;/p&gt;

&lt;p&gt;More often than not, you can avoid global packages and save yourself some precious debugging time.&lt;/p&gt;

</description>
      <category>npm</category>
      <category>javascript</category>
      <category>yarn</category>
      <category>npx</category>
    </item>
  </channel>
</rss>
