<?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: Marcel Cremer</title>
    <description>The latest articles on DEV Community by Marcel Cremer (@marcel_cremer).</description>
    <link>https://dev.to/marcel_cremer</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%2F75922%2Fdb62aadc-0904-4b64-a44c-284945ebc916.png</url>
      <title>DEV Community: Marcel Cremer</title>
      <link>https://dev.to/marcel_cremer</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/marcel_cremer"/>
    <language>en</language>
    <item>
      <title>How to create a scalable vue.js setup (Part I)</title>
      <dc:creator>Marcel Cremer</dc:creator>
      <pubDate>Mon, 18 Jan 2021 07:00:25 +0000</pubDate>
      <link>https://dev.to/marcel_cremer/how-to-create-a-scalable-vue-js-setup-part-i-29p7</link>
      <guid>https://dev.to/marcel_cremer/how-to-create-a-scalable-vue-js-setup-part-i-29p7</guid>
      <description>&lt;p&gt;If you know me a little bit or read my bio in social media, you'll probably have noticed that I'm a big fan of vue.js (and if you don't follow me right now, consider following me on &lt;a href="https://twitter.com/1devlife"&gt;twitter&lt;/a&gt; 😜).&lt;/p&gt;

&lt;p&gt;This is for a reason: Coming from angular, I personally like the approaches they chose to organize and do things. They have dependency injection, routers, stores, a test harness and much more. However, it has also a big downside: Everything feels a bit big and bloaty and I always had the feeling, that I could not develop as fast in angular as I should.&lt;/p&gt;

&lt;h3&gt;
  
  
  Introducing my vue.js setup
&lt;/h3&gt;

&lt;p&gt;If you don't know vue.js, you can &lt;a href="https://vuejs.org/"&gt;check it out here&lt;/a&gt;. Vue.js is a rather small framework (20KB compressed and minified) that focuses on the "view" part of the application (that's why it's pronounced /vjuː/, like "view" - just in case you wondered). Additionally, there are plenty of resources, plugins and so on that you can use to customize it to your needs (a comprehensive list is available here: &lt;a href="https://github.com/vuejs/awesome-vue"&gt;awesome-vue&lt;/a&gt;). So let's start:&lt;/p&gt;

&lt;h3&gt;
  
  
  The Foundation: Vue-cli
&lt;/h3&gt;

&lt;p&gt;Comparable to angular, the vue environment also &lt;a href="https://cli.vuejs.org/"&gt;has a cli&lt;/a&gt; that you can use to generate an application according to your needs. Even better, you can choose what tools you like to use and you can configure it to your needs (e.g. webpack) without ejecting the configuration. A simple command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vue create &amp;lt;projectname&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;creates a new project and you are able to choose, which css-framework you like to use, if you want babel and / or typescript, if you create a PWA (automatic manifest generation), which test framework for unit and e2e tests you prefer and if you opt for eslint or the deprecated (but still awesome) tslint. This alone is a huge advantage, as you are able to create the environment in a way that perfectly matches your needs. I personally use the configuration&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="o"&gt;[&lt;/span&gt;Vue 2] dart-sass, babel, typescript, pwa, router, vuex, unit-jest, e2e-cypress
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;but this can be very opinionated. After creating the project, you can launch a pretty cool dashboard via&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vue ui
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;which shows you not only your projects (it's possible to have a multi-project Monorepo in vue), but also the bundle sizes and the transpilation statistics. It's awesome!&lt;/p&gt;

&lt;h3&gt;
  
  
  Getting stuff: Dependency injection
&lt;/h3&gt;

&lt;p&gt;As mentioned before, vue only concentrates on the view part of your application. So the next thing I usually tend to do is to introduce dependency injection and for this task, I absolutely love &lt;a href="https://inversify.io/"&gt;inversify.js&lt;/a&gt; although people are discussing on &lt;a href="https://github.com/inversify/InversifyJS/issues/1225"&gt;how to proceed with future maintenance&lt;/a&gt;. It's very well established and plenty of larger projects are using this, so that I'm optimistic that even if the maintainer does not support it in the future, there will be forks or other ideas to further support this framework.&lt;/p&gt;

&lt;p&gt;After installation, I basically do the whole DI configuration in three files:&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;di.types.ts
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;TYPES&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="cm"&gt;/**
   * Services
   */&lt;/span&gt;
  &lt;span class="na"&gt;DATA_SERVICE&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;Symbol&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="k"&gt;for&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;DATA_SERVICE&lt;/span&gt;&lt;span class="dl"&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;This file defines Symbols, so that inversify has unique tokens to inject things.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;di.container.ts
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Container&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;inversify&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;getDecorators&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;inversify-inject-decorators&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Container&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt; &lt;span class="na"&gt;defaultScope&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Singleton&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt; &lt;span class="p"&gt;});&lt;/span&gt;

&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;lazyInject&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;getDecorators&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="nx"&gt;lazyInject&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This file is just to create a singleton container and make it possible to "lazy inject things". This is necessary due to a babel / webpack issue: On startup of the application, several files can request stuff and if you don't have the container imported from an own module, some things like lazy inject won't work&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;di.config.ts
&lt;/li&gt;
&lt;/ol&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;reflect-metadata&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;container&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@/di.container&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;TYPES&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@/di.types&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;DataService&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="sr"&gt;/services/&lt;/span&gt;&lt;span class="nx"&gt;data&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;service&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;ts&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;container&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bind&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;DataService&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;TYPES&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DATA_SERVICE&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;to&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;DataService&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here we bind a service to our previously defined Symbols. That's basically the whole magic about itroducing dependency injection. Easy, wasn't it?&lt;/p&gt;

&lt;h3&gt;
  
  
  Property decorators
&lt;/h3&gt;

&lt;p&gt;The next thing to tackle for a scalable application is, that we want to have a well written component that is easy to read and to reuse. Vue components are usually &lt;strong&gt;single file&lt;/strong&gt;, which has it's benefits (e.g. if you want to change some css, and then html and oh, you also need to introduce this property in typescript...). It's also easier to maintain some code standard about how large a component should possibly become, if you had single file components (e.g. &amp;gt;250loc =&amp;gt; linter error). To additionally increase readability, I like to use typescript class components flavoured with &lt;a href="https://github.com/kaorun343/vue-property-decorator"&gt;vue property decorators&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Here's some example, how a class component with decorators and dependency injection could look like:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight vue"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"hello-world"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="si"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;message&lt;/span&gt; &lt;span class="si"&gt;}}&lt;/span&gt;
        The sum of &lt;span class="si"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="si"&gt;}}&lt;/span&gt; + &lt;span class="si"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt; &lt;span class="si"&gt;}}&lt;/span&gt; is &lt;span class="si"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt; &lt;span class="si"&gt;}}&lt;/span&gt;.
        Our current mood is &lt;span class="si"&gt;{{&lt;/span&gt; &lt;span class="nx"&gt;mood&lt;/span&gt; &lt;span class="si"&gt;}}&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;template&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"ts"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
    &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;lazyInject&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@/di.decorator&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;TYPES&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;@/di.types&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
    &lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;Component&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Prop&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;vue-property-decorator&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Component&lt;/span&gt;
    &lt;span class="k"&gt;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;HelloWorld&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="nx"&gt;mood&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;lazyInject&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;TYPES&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;DATA_SERVICE&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; 
        &lt;span class="nx"&gt;dataService&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;DataService&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Prop&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="nx"&gt;message&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;string&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Prop&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="nx"&gt;a&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="p"&gt;@&lt;/span&gt;&lt;span class="nd"&gt;Prop&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
        &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="o"&gt;!&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;number&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

        &lt;span class="kd"&gt;get&lt;/span&gt; &lt;span class="nx"&gt;sum&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="nx"&gt;a&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nx"&gt;b&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="k"&gt;async&lt;/span&gt; &lt;span class="nx"&gt;mounted&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;mood&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;dataService&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="kd"&gt;get&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s2"&gt;`/api/v1/mood`&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;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;script&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;&lt;/span&gt;&lt;span class="k"&gt;style&lt;/span&gt; &lt;span class="na"&gt;lang=&lt;/span&gt;&lt;span class="s"&gt;"scss"&lt;/span&gt; &lt;span class="na"&gt;scoped&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="nc"&gt;.hello-world&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/&lt;/span&gt;&lt;span class="k"&gt;style&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;pretty neat, isn't it? 😁 Having this result is a good first step for creating a scalable vue app. If you are interested in more of this topic, I'm gonna talk about state management, testability and deployment (e.g. different environments) in the next part of this article series. Thank you for reading!&lt;/p&gt;

</description>
      <category>vue</category>
      <category>javascript</category>
      <category>typescript</category>
      <category>webdev</category>
    </item>
    <item>
      <title>5 reasons you might NOT need a mobile app</title>
      <dc:creator>Marcel Cremer</dc:creator>
      <pubDate>Tue, 10 Nov 2020 07:38:10 +0000</pubDate>
      <link>https://dev.to/marcel_cremer/5-reasons-you-might-not-need-a-mobile-app-3kh8</link>
      <guid>https://dev.to/marcel_cremer/5-reasons-you-might-not-need-a-mobile-app-3kh8</guid>
      <description>&lt;p&gt;When I'm scrolling through my mobile phone the last days, I'm recognizing that I haven't installed many apps that were not pre-installed. To be honest, for a long time was thinking, it was just me with this "app avoidance behaviour". However, I went curious and asked my social bubble about how many and what apps they have installed. After I got some input, I started to realize, that others also don't download many apps for different reasons. In fact, sometimes it feels even painful to only have the "tool" app, without a suitable Desktop or web alternative (e.g. for my bank accounting analytics). So today, whenever I have to argument about pro / con app, I have 5 indicators when you don't need an app:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. You have a business2business model
&lt;/h3&gt;

&lt;p&gt;Let's start with something simple: If your business is B2B, your main application shouldn't be an app. The reason is simple: B2B licensing is almost never done via the app stores or in-app transactions. What happens instead is, that people will download your app, won't be able to use it and leave bad reviews in the app store (no matter &lt;strong&gt;HOW FAT YOU WROTE&lt;/strong&gt;, that it's not for public usage 😜). This will cost time, money and nerves. So if you publish something in an app store, make sure it provides some value for B2C (business to consumer).&lt;/p&gt;

&lt;h3&gt;
  
  
  2. You don't need too much "native" features
&lt;/h3&gt;

&lt;p&gt;Now this is a big one for me: Why do you actually &lt;strong&gt;NEED&lt;/strong&gt; a mobile app? Does it have any benefit to implement it, or is it just "cool" to have an app? Many apps that are offered are not using the full potential of native apps. If you don't need to have access to all the 28 sensors of the latest x-phone and don't need the store as marketing instrument, why should you take the extra effort to maintain a native app? Even if you need some "native" features, you can most often rely on using a progressive web app (PWA), because things like camera, push messages etc. are already supported. If you're curious, open &lt;a href="https://whatwebcando.today/"&gt;this page&lt;/a&gt; on your mobile phone and you can see the exact featureset, that is provided without creating a native app.&lt;/p&gt;

&lt;h3&gt;
  
  
  3. You have a data heavy application
&lt;/h3&gt;

&lt;p&gt;As I wrote in the introduction, some apps can be a pain to use. This might be personal taste, but I can identify them for myself most of the time as "data heavy applications". What do I mean with that? Every app, where you need to type much, swipe much, present analytics, show plenty of tables and so on. Smartphones don't have a physical keyboard (anymore) and most people cannot write 1 sentence correctly without looking at the screen. It might be okay to write some sentences in a messenger or a short email on the mobile, but don't expect the user to write novels in your app. And if you really need to provide this app, please provide at least a desktop / web alternative, so that they have the choice to do the heavy work on a computer.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Your development cycle becomes more complex and expensive
&lt;/h3&gt;

&lt;p&gt;Providing apps is expensive. And I don't mean, it creates "a bit" additional expenses - it's huge!&lt;/p&gt;

&lt;p&gt;Let's start with the obvious things:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  You have to have a developer account per app store (at least google and apple)&lt;/li&gt;
&lt;li&gt;  You pay for the publishing into the appstore&lt;/li&gt;
&lt;li&gt;  You need a different build pipeline to deploy into the stores&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So that's what everyone has on their mind, if they think of additional costs, right?&lt;/p&gt;

&lt;p&gt;Now let's think a little bit further:&lt;/p&gt;

&lt;h5&gt;
  
  
  Your developers need to get a huge knowledge about all platforms
&lt;/h5&gt;

&lt;p&gt;I hear you saying: "Why? There's react native, nativescript and whatever out there! Writing native apps is easy!"&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Nope, it's not!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;First of all, those abstraction Frameworks are exactly this - an abstraction of the different platforms with the benefit of a "single codebase". However, abstraction always means, that it has to find the lowest common denominator between the different platforms. So as long as you don't do something "special", your code will work out of the box. But as we identified in the previous reasons already, &lt;strong&gt;the whole point about providing an app, is to provide something special!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So faster than you even know it, your developers have to learn at least three frameworks: Android, iOS and react native / nativescript / ...&lt;/p&gt;

&lt;p&gt;Most of the time, the abstraction frameworks also have some "CSS-like" styling syntax. This basically means, that you cannot use your already created CSS from your web application, but have to write the exact same code in a different manner to make it app compatible.&lt;/p&gt;

&lt;h4&gt;
  
  
  Apple has built their own community
&lt;/h4&gt;

&lt;p&gt;Have you ever tried to develop an iOS app with Windows? It doesn't work, because apple has shut down all doors to the outside. If you want to have an iOS app, you're forced to give out macs to your developers (and if they aren't used to it, they'll wonder about the new keyboard layout😁).&lt;/p&gt;

&lt;p&gt;"But we're already using macs to work!"&lt;/p&gt;

&lt;p&gt;Okay cool - this simplifies things. But... how do you test iOS apps in your continuous integration pipeline?&lt;/p&gt;

&lt;p&gt;The answer is: You need additional services, that offer you dedicated time on a mac to do automatic testing. This is (of course) expensive, because there are not many providers who offer calculation power on macs.&lt;/p&gt;

&lt;h3&gt;
  
  
  5. You have a flexible application with lots of changes
&lt;/h3&gt;

&lt;p&gt;Another thing that isn't considered when introducing an app is, that it takes time to update it in the app store.&lt;/p&gt;

&lt;p&gt;Have this breaking change of the API or this super critical security update? You have to wait up to 48 hours until it's out there!&lt;/p&gt;

&lt;p&gt;The different platforms use a combination of manual and automatic reviewing which is of course good for the app store reputations, but very bad for the developer experience. And depending on the platform, you cannot even force the update of your app, so people might still be working with an old version.&lt;/p&gt;

&lt;h3&gt;
  
  
  Summary
&lt;/h3&gt;

&lt;p&gt;As you can see in my argumenation, the decision of making an app should be well reasoned. I'm not all against providing native apps for your customer, but I think the decision in favor for an app is oftenly made way too quickly and without considering, how much impact this will have on your product lifecycle and maintenance costs.&lt;/p&gt;

</description>
      <category>pwa</category>
      <category>mobile</category>
      <category>app</category>
      <category>appdevelopment</category>
    </item>
    <item>
      <title>Explain like I'm five: How does docker application update work?</title>
      <dc:creator>Marcel Cremer</dc:creator>
      <pubDate>Wed, 29 May 2019 06:10:43 +0000</pubDate>
      <link>https://dev.to/marcel_cremer/explain-like-i-m-five-how-does-docker-application-update-work-1ank</link>
      <guid>https://dev.to/marcel_cremer/explain-like-i-m-five-how-does-docker-application-update-work-1ank</guid>
      <description>&lt;p&gt;Whenever I read about docker or containers in general, I wonder how it could possibly work in real world applications. &lt;/p&gt;

&lt;p&gt;That's what I (think I) understood until now:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;docker encapsulates an application, but not the applications data&lt;/li&gt;
&lt;li&gt;updates are done by completely exchanging the applications container (e.g. remove myApp 1.0.0 and start myApp 1.0.1)&lt;/li&gt;
&lt;li&gt;all non-volatile data is stored outside of the container in volumes (which are basically shared directories between the host and docker's containers)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, if that's how it's done, how do Update processes / database schema updates  / ... work?&lt;/p&gt;

&lt;p&gt;A more specific example: If I have an postgres container and I need to update the database version (ergo: install the new container). How do I update the database files to the newer version, when the postgresql installation / updater will be never executed?&lt;/p&gt;

</description>
      <category>explainlikeimfive</category>
      <category>docker</category>
    </item>
    <item>
      <title>🏇 A simple tip to improve angulars compilation speed</title>
      <dc:creator>Marcel Cremer</dc:creator>
      <pubDate>Fri, 17 May 2019 06:09:15 +0000</pubDate>
      <link>https://dev.to/marcel_cremer/a-simple-tip-to-improve-angulars-compilation-speed-5dm0</link>
      <guid>https://dev.to/marcel_cremer/a-simple-tip-to-improve-angulars-compilation-speed-5dm0</guid>
      <description>&lt;p&gt;Do you have a large angular application that takes too long to compile / serve / compile tests? This little thing helped me:&lt;/p&gt;

&lt;h3&gt;
  
  
  Increasing the node process memory
&lt;/h3&gt;

&lt;p&gt;By default, a node process can take up to 1,76GB of RAM. This is by original design of Javascript, where the assumption was, that a single thread (which node has) will not exceed a total of 2GB RAM.&lt;/p&gt;

&lt;p&gt;However, things got a bit more complex the last few years, because JavaScript frameworks evolved and allowed to compose different libraries to a framework or in our case - the angular compile mechanism.&lt;/p&gt;

&lt;p&gt;And if your compilation process reaches this limit, the node garbage collector will start alternating with the compilation process, freeing up just enough space so that the next piece of work can be executed by ngc.&lt;/p&gt;

&lt;p&gt;If you're like me, you might think: &lt;strong&gt;Why the hell should ngc ever exceed this limit?!?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;The short answer is: Because it does many things for you 😃&lt;/p&gt;

&lt;p&gt;Okay, to be a bit more specific:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  it bundles assets into your final build&lt;/li&gt;
&lt;li&gt;  it keeps several hundred files in memory to do tree-shaking&lt;/li&gt;
&lt;li&gt;  it compiles scss-files&lt;/li&gt;
&lt;li&gt;  it organizes chunks into module / vendor chunks&lt;/li&gt;
&lt;li&gt;  it seperates often used code pieces for shared use into a common chunk&lt;/li&gt;
&lt;li&gt;  ...and much much more :)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So how do we get rid of that &lt;em&gt;"free memory / do a bit more work / free memory"&lt;/em&gt;-cycle?&lt;/p&gt;

&lt;h3&gt;
  
  
  Increasing the node memory limit with max_old_space_size
&lt;/h3&gt;

&lt;p&gt;Node has a simple flag to change the maximum RAM consumption before the garbage collector will start to agressively free up memory. You can use it like&lt;/p&gt;

&lt;p&gt;&lt;code&gt;node --max_old_space_size=&lt;/code&gt;&lt;em&gt;size in MB&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;As I have 24GB of RAM in my machine, I don't have any problem to assign 8 GB to the node process. But I also don't want to lose the comfort of the ng cli, so how to automatically assign the parameter to ng commands?&lt;/p&gt;

&lt;p&gt;The solution is simple, but maybe not too obvious:&lt;/p&gt;

&lt;p&gt;We call the ng cli directly out of the node_modules folder using a node script. I called this variant &lt;strong&gt;"nghm"&lt;/strong&gt; &lt;em&gt;(for ng high memory)&lt;/em&gt; and built it like this:  &lt;/p&gt;

&lt;p&gt;&lt;code&gt;"nghm": "node --max_old_space_size=8096 ./node_modules/@angular/cli/bin/ng"&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Having this script in mind, we can transform "ng serve" into&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm run nghm -- serve&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;which will now consume up to 8GB RAM. A production build could look like&lt;/p&gt;

&lt;p&gt;&lt;code&gt;npm run nghm -- build --prod --progress=false --aot=true --vendor-chunk&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;And the Numbers?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Well, that might depend from project to project, but in my project this particular change has reduced the compilation time from ~3:26min to ~1:36min (I picked 2 times from our CI system, that are pretty average - no science here😉).&lt;/p&gt;

&lt;p&gt;It might be influenced by how large your assets are, how many files are compiled and so on, but if you struggle with long compilation times, just give it a try.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://marcel-cremer.de/blog/angular-compilation-speed/"&gt;marcel-cremer.de&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>npm</category>
      <category>angular</category>
      <category>node</category>
    </item>
    <item>
      <title>Why your Open Source Project might lack (my?) contribution (1)</title>
      <dc:creator>Marcel Cremer</dc:creator>
      <pubDate>Thu, 16 May 2019 06:09:32 +0000</pubDate>
      <link>https://dev.to/marcel_cremer/why-your-open-source-project-might-lack-my-contribution-1-4m8g</link>
      <guid>https://dev.to/marcel_cremer/why-your-open-source-project-might-lack-my-contribution-1-4m8g</guid>
      <description>&lt;p&gt;Many developers like to "give something back" to the community by supporting Open Source projects in one way or another. The types of contribution can vary widely, e.g.:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Reporting Issues and / or Feature Requests&lt;/li&gt;
&lt;li&gt;  Fixing things, they need themselves&lt;/li&gt;
&lt;li&gt;  Add some value (a new Feature, better documentation, ...)&lt;/li&gt;
&lt;li&gt;  "Swarm intelligence" by contributing to brainstormings or discussions&lt;/li&gt;
&lt;li&gt;  Testing (and giving feedback)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, sometimes contributors are also repelled by various reasons. The following reasons are some of mine...&lt;/p&gt;

&lt;h3&gt;
  
  
  How important it is, to have a low hurdle in your project
&lt;/h3&gt;

&lt;p&gt;My first and top reason not to contribute to a project is...&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;...not finding a good starting point!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Like really, if you check out a project, maybe install dependencies and then the build doesn't work first try, there's a chance of about 90% percent for me to drop the idea of contribution.&lt;/p&gt;

&lt;p&gt;Sometimes it takes dozens of steps to get the build running. Sometimes you find an issue where someone reports, that step xy is missing in the documentation and it's still not updated. Sometimes you need to cherry-pick ideas from different places to get something working.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Why should I spend my time and diligence in contributing to something, that seems not important to the maintainer?&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Make it easy for contributors to take the first steps, document it well and keep it updated all the time. It's really important to support people, who want to support your project!&lt;/p&gt;

&lt;p&gt;A good example for a low first run hurdle (node-based in this case):&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Check out the project&lt;/li&gt;
&lt;li&gt;  npm i&lt;/li&gt;
&lt;li&gt;  copy conf.json* to conf.json and change database setttings &lt;em&gt;(json exists and just needs to be modified - easy!)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;  npm run serve&lt;/li&gt;
&lt;li&gt;  Success!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now it's possible to play around with code while reading it, get instant feedback on what changes do and so on.&lt;/p&gt;

&lt;p&gt;Keep also the following things in mind:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  If you have unit tests &lt;em&gt;(and I hope you have some)&lt;/em&gt;, make them available as simple as the first compilation &lt;em&gt;(e.g. npm run test:watch in this case)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;  if you have a database dependency, put the schema and initial seed in your VCS. No one wants to open an administration, execute ten random SQL files and maybe get a consistent database &lt;em&gt;(or not)&lt;/em&gt;! Provide an automated script or create the database automatically on startup, if it doesn't exist!&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Keep your project fast!
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;"Okay, so I got this library and it has a bug. I found the line of code in github already, so let's fix this real quick and send out a pull request:&lt;br&gt;
git clone xyz&lt;br&gt;
install dependencies...&lt;br&gt;
...&lt;br&gt;
...&lt;br&gt;
Okay, that took a while. Let's start the program to see, if I can reproduce the error.&lt;br&gt;
...&lt;br&gt;
...&lt;br&gt;
...&lt;br&gt;
Ehm, will this ever finish?&lt;br&gt;
...&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;If you want contributors to send Pull / Merge requests, &lt;strong&gt;care for your project's performance&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;Sometimes the issue is obvious: Even from reading the code on the source code repository, you can put your finger on the line where the error happens.&lt;/p&gt;

&lt;p&gt;However, to get a pull request, the contributor needs to&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  check out the code&lt;/li&gt;
&lt;li&gt;  install deps&lt;/li&gt;
&lt;li&gt;  maybe add a database / server / whatever&lt;/li&gt;
&lt;li&gt;  get it running&lt;/li&gt;
&lt;li&gt;  reproduce the error &lt;em&gt;(or write a test)&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;  fix the error&lt;/li&gt;
&lt;li&gt;  push it&lt;/li&gt;
&lt;li&gt;  create an issue&lt;/li&gt;
&lt;li&gt;  create a PR referencing the issue&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you ever see it from this perspective, you surely recognize that there's a lot of stuff to do &lt;em&gt;(to fix your "little" mistake)&lt;/em&gt;.&lt;/p&gt;

&lt;p&gt;If it takes about an hour to setup the development environment, have the first compilation done and get tests running, I tend to just drop the idea to create a fix and instead just open an issue. Even if I had the patience to create this fix, I wouldn't have the time for it in my daily business.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;So please keep the development cycle fast!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Some ideas to achieve this:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;  Create some small projects that are working for themselves instead of providing one large monolith&lt;/li&gt;
&lt;li&gt;  Keep the dependencies small&lt;/li&gt;
&lt;li&gt;  Don't create 1 million fake entries in your initial database seed. If someone want's to do stress test, he could easily apply an additional seed&lt;/li&gt;
&lt;li&gt;  Run tests on the continous integration server - especially if they aren't easy to set up locally. It'll be much easier to throw something against the server and let him validate if everything is fine, than setting up some hard-to-setup-test-suites&lt;/li&gt;
&lt;li&gt;  if you have easy to use unit tests, make sure that they have a short feedback loop. If the suite takes 3 seconds to test and someone saves every 3 seconds, 50% of the time will be wasted for compilation / waiting for tests&lt;/li&gt;
&lt;li&gt;  if it's not possible to keep the whole test suite that fast, make it easy to isolate tests. In node / jasmine for example there's an fdescribe and fit that will only execute that particular test suite / test case. Make sure, that the isolated tests are as fast as possible&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Maintain your project
&lt;/h3&gt;

&lt;p&gt;Everyone who puts up a project on github, gitlab or something is the so-called "maintainer", but many people don't really maintain their project.&lt;/p&gt;

&lt;p&gt;To make this point really clear: No one expects an open source maintainer to be available 24/7 and always have an answer to any given topic.&lt;/p&gt;

&lt;p&gt;However, if someone takes his time to carefully open an issue on your project, handle the issue itself carefully as well:&lt;/p&gt;

&lt;p&gt;If you've seen the issue but don't have the time right now, write a short note that you've seen it and...&lt;em&gt;drum roll&lt;/em&gt;...don't have the time to work on it right now! People like to be noticed by others, especially if they put some work in their issue. The answer&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"Hey, I saw your issue but I'm on a business trip atm. Coming back 2 u in a few days"&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Is already some kind of appreciation to the creator, shows that you take him seriously and also that you &lt;em&gt;(and the project your maintaining)&lt;/em&gt; is still active.&lt;/p&gt;

&lt;p&gt;The same is of course true for pull / merge requests. If you have 20 open requests without any notice or discussion, the 21st requests won't be opened,&lt;br&gt;
because everyone will think: This project is unmaintained.&lt;/p&gt;

&lt;h3&gt;
  
  
  End of Part 1
&lt;/h3&gt;

&lt;p&gt;Because this article seems to grow rapidly and I still have some things noted here, I'm going to make a cut at this point.&lt;/p&gt;

&lt;p&gt;I'd love to hear, if you also struggle with some of those things and also, if you'd like to read some more on this topic :-)&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://www.marcel-cremer.de/opensource/"&gt;marcel-cremer.de&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>opensource</category>
      <category>organisation</category>
      <category>management</category>
    </item>
    <item>
      <title>The Icon evolution and "How I switched from Font based Icons to SVG"</title>
      <dc:creator>Marcel Cremer</dc:creator>
      <pubDate>Fri, 01 Feb 2019 07:05:46 +0000</pubDate>
      <link>https://dev.to/marcel_cremer/the-icon-evolution-and-how-i-switched-from-font-based-icons-to-svg-11bm</link>
      <guid>https://dev.to/marcel_cremer/the-icon-evolution-and-how-i-switched-from-font-based-icons-to-svg-11bm</guid>
      <description>&lt;p&gt;Last week, we made the decision to migrate from our font-based icon set to &lt;a href="//feathericons.com"&gt;feather icons&lt;/a&gt; - an SVG based font set. Since I've been using font based Icons like forever and had to read a bit about icons in general, I'm going to share what I learned with you. So please join me on a journey into...&lt;/p&gt;

&lt;h3&gt;
  
  
  The Evolution of Icon Sets
&lt;/h3&gt;

&lt;p&gt;A long time ago, in a world where CSS didn't exist, Icons were displayed via &lt;strong&gt;images&lt;/strong&gt;. &lt;/p&gt;

&lt;p&gt;And it was &lt;em&gt;good&lt;/em&gt;. &lt;br&gt;
Until...&lt;/p&gt;

&lt;p&gt;People realisied, that images are very inflexible regarding their display size. Also, they consumed much bandwidth (which was costly) and if over-used, the website became slow (at that time, each image request blocked the main thread of the browser). But luckily, CSS arrived. &lt;/p&gt;

&lt;p&gt;So people started to use so called &lt;strong&gt;image sprites&lt;/strong&gt;, where a bunch of icons were placed on one image (which was cacheable). By positioning via CSS it was possible, to extract parts of this image sprite to just show the one icon needed in that particular place.&lt;/p&gt;

&lt;p&gt;And it was &lt;em&gt;good&lt;/em&gt;. &lt;br&gt;
Until...&lt;/p&gt;

&lt;p&gt;Web designers had again to struggle with images. Because people wanted to have the same icon in different colors and sizes, the image sprite grew larger and larger. Also accessibility became a problem. &lt;/p&gt;

&lt;p&gt;So at around 2012, people got a new Idea: We can have text in different colors, scale it like we want to and even apply shadows on them. We can also draw text "above" other text by CSS positioning, so we could "craft" a new character by combining 2 others. And all that, by having a small file, which contains a definition on how to draw those Characters. &lt;/p&gt;

&lt;p&gt;&lt;em&gt;But what if it didn't contain characters? What if it contained Icons?&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;That's how &lt;strong&gt;Font based Icon sets&lt;/strong&gt; were born. The icons were drawn carefully and delivered as a font set, where each "character" represented one icon. &lt;/p&gt;

&lt;p&gt;They could be easily accessed by writing the corresponding character (e.g. via Unicode) or later via ligatures. They could be colored and sized, combined and even CSS effects were possible on them.&lt;/p&gt;

&lt;p&gt;Although fonts weren't made for icons, the Icon Fonts lived a long and happy life. &lt;/p&gt;

&lt;p&gt;And it was &lt;em&gt;good&lt;/em&gt;. &lt;br&gt;
Until...&lt;/p&gt;
&lt;h3&gt;
  
  
  A small introduction in SVG
&lt;/h3&gt;

&lt;p&gt;Scalable Vector graphics (short: SVG) are a standard to describe 2-dimensional Vector graphics in XML. According to &lt;a href="https://caniuse.com/#search=SVG"&gt;caniuse.com&lt;/a&gt;, all "modern" Browsers support them. Others can be polyfilled e.g. by &lt;a href="https://github.com/jonathantneal/svg4everybody"&gt;svg4everybody&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;A simple example would be&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;svg&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;circle&lt;/span&gt; &lt;span class="na"&gt;cx=&lt;/span&gt;&lt;span class="s"&gt;"5"&lt;/span&gt; &lt;span class="na"&gt;cy=&lt;/span&gt;&lt;span class="s"&gt;"5"&lt;/span&gt; &lt;span class="na"&gt;r=&lt;/span&gt;&lt;span class="s"&gt;"4"&lt;/span&gt; &lt;span class="na"&gt;fill=&lt;/span&gt;&lt;span class="s"&gt;"currentColor"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/svg&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;which paints a circle with the current color.&lt;/p&gt;

&lt;h3&gt;
  
  
  Reasons to use SVG based Icon sets
&lt;/h3&gt;

&lt;p&gt;Here's a (incomplete) list of benefits for SVG based Icons. &lt;/p&gt;

&lt;p&gt;They are...  &lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;fast to paint&lt;/li&gt;
&lt;li&gt;much smaller than traditional Image or font based icon sets&lt;/li&gt;
&lt;li&gt;because they are basically code, they can be extended (e.g. by adding a rectangle into the above example)&lt;/li&gt;
&lt;li&gt;consume less bandwidth, because they can be compressed for transfer (it's a text definition after all... :) )&lt;/li&gt;
&lt;li&gt;They can even be used within a regular &amp;lt;img&amp;gt; tag (although this limits your flexibility to adjusting width and height)&lt;/li&gt;
&lt;li&gt;while Font based Icon positioning can be tricky (because they are inserted on a pseudo element, e.g. in CSS with :before and :after selector and the content-attribute), SVG based Icons can be just placed as an element itself and will be drawn nicely in their given dimensions&lt;/li&gt;
&lt;li&gt;SVGs support Anti-Aliasing, which makes them in general a bit sharper than their font based counterparts.&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  My Personal Decisions: JavaScript vs Angular implementation vs Sprites
&lt;/h3&gt;

&lt;p&gt;When I started with the migration to SVG based Icons, what I first found was a JavaScript implementation that builds the SVG (first paragraph on &lt;a href="https://github.com/feathericons/feather"&gt;feathericons&lt;/a&gt;). However, as I was working in an Angular SPA, I didn't want to use external JS and create overhead.&lt;/p&gt;

&lt;p&gt;So my next "station" on the way to SVGs was, to check out if someone already built something for angular, and of course, someone did: &lt;a href="https://github.com/michaelbazos/angular-feather"&gt;Angular Feather&lt;/a&gt; supports the import of single icons just as needed, where needed in the angular Application. Nice!&lt;/p&gt;

&lt;p&gt;But wait... as every icon is encapsulated in an Angular component, I wouldn't have had access to the SVG and therefor, I wouldn't have been able to modify the color of Icon parts, add additional paths to the SVG or whatever else someone could imagine.&lt;/p&gt;

&lt;p&gt;There had to be another option, and if I carefully read the rest of the Feather Icons site until the end, I would've seen it right at the beginning: &lt;strong&gt;SVG Sprites&lt;/strong&gt;!&lt;/p&gt;

&lt;h3&gt;
  
  
  SVG Sprites
&lt;/h3&gt;

&lt;p&gt;SVG Sprites are basically an xml file, where many Icon definitions are stored with a corresponding anchor. In case of Feather Icons, the SVG sprite is about 50kb (uncompressed) which was very acceptable for my Web Application.&lt;/p&gt;

&lt;p&gt;So I created the base class in css, which describes the overall icon behaviour:&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;.fi&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1em&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="nl"&gt;height&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;1em&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;stroke&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;currentColor&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;stroke-width&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="m"&gt;2&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;stroke-linecap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;round&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;stroke-linejoin&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="n"&gt;round&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="py"&gt;fill&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;none&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;Because I chose relative sizes, the icons are as high as they should be in the different places according to the font size (just like their font based counterparts).&lt;/p&gt;

&lt;p&gt;The "stroke" defines how the lines defined by the SVG should be drawn. Because it's set to "currentColor", the icon will use the current font color of it's context.&lt;/p&gt;

&lt;p&gt;Right after defining those basics, I was able to exchange my icons to their SVG-equivalent:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight html"&gt;&lt;code&gt;&lt;span class="nt"&gt;&amp;lt;svg&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"fi"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;use&lt;/span&gt; &lt;span class="na"&gt;xlink:href=&lt;/span&gt;&lt;span class="s"&gt;"/assets/feather/feather-sprite.svg#user"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&amp;lt;/svg&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(note #user, which is the anchor reference for the Icon I want to draw out of the SVG sprite)&lt;/p&gt;

&lt;p&gt;And what should I say? &lt;strong&gt;It just works!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;I was even able to create additional helper classes, for small, large and 2x 3x and 4x original size, by adding a few simple CSS classes.&lt;/p&gt;

&lt;p&gt;I hope you could also take something out of my journey through the icon evolution. Which ones do you prefer and why?&lt;/p&gt;

</description>
      <category>icons</category>
      <category>svg</category>
      <category>css</category>
    </item>
    <item>
      <title>5 Tips for better NPM script organization</title>
      <dc:creator>Marcel Cremer</dc:creator>
      <pubDate>Wed, 30 Jan 2019 07:16:17 +0000</pubDate>
      <link>https://dev.to/marcel_cremer/5-tips-for-better-npm-script-organization-2gh9</link>
      <guid>https://dev.to/marcel_cremer/5-tips-for-better-npm-script-organization-2gh9</guid>
      <description>&lt;p&gt;Not too long ago, it was pretty normal to use grunt, gulp and other tools to organize building, testing and other tasks in JS-Projects. However, this required people to install, maintain and understand different build systems, structures and configurations.&lt;/p&gt;

&lt;h3&gt;
  
  
  NPM Scripts to the rescue!
&lt;/h3&gt;

&lt;p&gt;Everyone who uses npm as their package manager already has a package.json and the ability, to run scripts from there. So what is more obvious, than using npm scripts for automated tasks around the project?&lt;/p&gt;

&lt;p&gt;However, since the npm scripts is in no way opinionated about modeling complex build systems, the organisation and consistency of the scripts is in responsibility of the maintaining developer. And here are some tips on what you could do.&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Consistent script names
&lt;/h3&gt;

&lt;p&gt;If you start using NPM for several tasks, your script section might grow pretty fast. You might have for example scripts for unit testing, for integration testing, the same with coverage reports and also as watch-mode for development. If it grows organic, you might end up with something like&lt;br&gt;
&lt;/p&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;"build"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&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;"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;"..."&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-watch"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&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;"integration-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;"..."&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"watch-integration-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;"..."&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-coverage"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&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;"test-integration-coverage"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&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;"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;"..."&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;&lt;strong&gt;&lt;em&gt;Urks...&lt;/em&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;You might not notice it in the first place, but more often you'll misspell whatever you want to do, e.g. you write&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run integration-test-watch 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;instead of&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run watch-integration-test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;triggering the well known "Command not found"-Error.&lt;/p&gt;

&lt;p&gt;So somewhen you get the idea to change it the other way around, and guess what? The next time you try it, you write it &lt;strong&gt;wrong again&lt;/strong&gt; , because you don't have a system...yet :)&lt;/p&gt;

&lt;p&gt;So what we need is some naming scheme, that is consistent in your own aesthetical point of view. For example, I use something like:&lt;br&gt;
&lt;/p&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;"build"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&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;"build:production"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&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;"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;"..."&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:coverage"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&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;"test:watch"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&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;"test:integration"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&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;"test:integration:coverage"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&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;"test:integration:watch"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&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;So I start off with what I want to do, followed by specifying it or calling additional behaviours. As the order always stays the same, I'm not so likely to misspell things.  &lt;/p&gt;

&lt;p&gt;Also I have some "internal" scripts, that are only used for DRY purposes inside of the package.json. Usually I let them start with a hashtag, so that people don't get the idea to use them directly. For example:&lt;br&gt;
&lt;/p&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;"\#:copy:assets"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&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;"\#:copy:configuration-templates"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&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;"\#:generate:polyfills"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&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;h3&gt;
  
  
  2. Performance
&lt;/h3&gt;

&lt;p&gt;One thing people often don't care about is performance. If we think of unit tests, it's pretty obvious that every second counts. So if you press ctrl+s about 10 times a minute, and every testing cycle takes 3 seconds, you spend &lt;strong&gt;about half your time (10 * 3 = 30 seconds) waiting for your test results&lt;/strong&gt;! Scary, isn't it?&lt;/p&gt;

&lt;p&gt;If you're in a typescript environment, the code also needs to be compiled into javascript before the tests etc. can be executed. So take a minute upfront to think about your task execution, before wasting hours and hours with waiting.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use modules like &lt;a href="https://www.npmjs.com/package/concurrently"&gt;concurrently&lt;/a&gt; whenever you're able to execute tasks in parallel (e.g. having your typescript-compiler watch .ts files, and your tests watch the output .js-files).&lt;/li&gt;
&lt;li&gt;Try to avoid that different tasks do the same (e.g. integration testing and unit testing both trigger the typescript compiler)&lt;/li&gt;
&lt;li&gt;Make granular scripts for different tasks and chain them in convenience scripts&lt;/li&gt;
&lt;li&gt;review your scripts from time to time to see, what bottlenecks you encounter&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  3. Platform independence
&lt;/h3&gt;

&lt;p&gt;Because I primarily develop on windows (blame me if you want...), I really hate it when I want to contribute to some Open Source project, and the&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;script fails because it's relying on some unix command. Try to use node-implementations whenever you can, to avoid platform specific code.&lt;/p&gt;

&lt;p&gt;For Example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Use &lt;a href="https://www.npmjs.com/package/rimraf"&gt;rimraf&lt;/a&gt; instead of rm -rf&lt;/li&gt;
&lt;li&gt;Use &lt;a href="https://www.npmjs.com/package/copyfiles"&gt;copyfiles&lt;/a&gt; instead of copying via OS commands&lt;/li&gt;
&lt;li&gt;... you get the idea ;)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Even worse is the usage of npm packages that rely on &lt;strong&gt;native OS calls&lt;/strong&gt;, which need to be compiled with node-gyp before being usable.&lt;/p&gt;

&lt;p&gt;If you don't believe me, have a look at &lt;a href="https://stackoverflow.com/search?q=node-gyp"&gt;stackoverflow&lt;/a&gt; on how many problems node-gyp creates, &lt;strong&gt;before&lt;/strong&gt; you decide to use some native OS library to "asynchronously add 2 numbers" (or other curiousities like that)!&lt;/p&gt;

&lt;p&gt;I know, some scenarios need native libraries and that's perfectly fine, but please think twice before adding them as a dependency. If the cause is for example performance, provide a &lt;em&gt;"slow, platform-indepedent, nodejs"-way&lt;/em&gt; as default and add the &lt;em&gt;"native call"-way&lt;/em&gt; as a &lt;strong&gt;peer dependency&lt;/strong&gt;, so people can decide themselves, if the performance is worth the native module compilation.&lt;/p&gt;

&lt;p&gt;Always prefer options over "might not be working for someone", because the persons you otherwise push away might have sent you an incredible pull request.&lt;/p&gt;

&lt;h3&gt;
  
  
  4. Additional parameters
&lt;/h3&gt;

&lt;p&gt;Sometimes I see projects, that have the exact same script multiple times implemented, just to add different parameters. That is fine if you're providing convenience methods (e.g. serve to start a development webserver), but if you have a dozen of them, you might also think about people just parametrizing your scripts.&lt;/p&gt;

&lt;p&gt;So instead of&lt;br&gt;
&lt;/p&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;"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;"node server.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;"start:integration-port"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"node server.js --port=4202"&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:https"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"node server.js --https=true"&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:integration-port:https"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"node server.js --port=4202 --https"&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;you could also provide a single start command, and use -- to pass additional parameters to the script. That can be used like&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm run start
npm run start &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="nt"&gt;--port&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;4202
npm run start &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="nt"&gt;--https&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;true
&lt;/span&gt;npm run start &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="nt"&gt;--port&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;4202 &lt;span class="nt"&gt;--https&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="nb"&gt;true&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  5. NPX instead of single command scripts
&lt;/h3&gt;

&lt;p&gt;Since NPM 5, NPM supports a tool called "NPX". What it basically does is, it executes a script from your dependencies as node executable.&lt;/p&gt;

&lt;p&gt;For example instead of writing&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;node ./node_modules/typescript/bin/tsc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;you could write&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx tsc
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and would execute your local typescript compiler (more information &lt;a href="https://www.npmjs.com/package/npx"&gt;here&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;Sometimes I look into projects, that have 20 NPM scripts or something, and some of them are&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&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="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"webpack"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"webpack"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"tsc"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"tsc"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="err"&gt;//&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="err"&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;which are pretty useless. Use NPX and tighten your package.json even more.&lt;/p&gt;

&lt;p&gt;Do you have some more tips? How do you structure your package.json?&lt;/p&gt;

</description>
      <category>npm</category>
      <category>javascript</category>
      <category>node</category>
    </item>
    <item>
      <title>Start. Testing. Now!</title>
      <dc:creator>Marcel Cremer</dc:creator>
      <pubDate>Mon, 19 Nov 2018 07:51:54 +0000</pubDate>
      <link>https://dev.to/marcel_cremer/start-testing-now-2o76</link>
      <guid>https://dev.to/marcel_cremer/start-testing-now-2o76</guid>
      <description>&lt;p&gt;Hello hello - nice that you got here!&lt;/p&gt;

&lt;p&gt;If you read this, I'm pretty sure you care about your work. You want to deliver good quality Software, and of course you also want to test.&lt;/p&gt;

&lt;p&gt;If you're like me, you &lt;strong&gt;really really want to test&lt;/strong&gt;, but you just don't know to start. Like - what the...?&lt;/p&gt;

&lt;p&gt;There are &lt;strong&gt;tons of testing frameworks&lt;/strong&gt; out there, you're code looks like it could be never, ever tested at all and everytime you ask a question on the web like&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"How do I test databases?"&lt;/p&gt;

&lt;p&gt;"How can I assure, that my Rest-Service work?"&lt;/p&gt;

&lt;p&gt;...&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;you get put down from the community:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;"That's not Unit Testing - that's integration / end2end / ... testing! You're doing it all wrong, blah blah blah..."&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;But really - you don't care how it's named. I mean, you want to deliver &lt;strong&gt;good quality Software&lt;/strong&gt;, so... whatever, just test it, right? It looks like there is no starting point for "normal" guys and girls out there: Either you get it, or you don't...&lt;/p&gt;

&lt;h3&gt;
  
  
  Wrong, wrong, wrong!
&lt;/h3&gt;

&lt;p&gt;I absolutely feel you and your thoughts, because I was at the exact same point several times. When I was a total beginner at testing, I felt like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Okay, I get this framework, but how can I apply it to my code base?&lt;/li&gt;
&lt;li&gt;I can only test trivial and obviously working things with Unit tests (which slows me down)&lt;/li&gt;
&lt;li&gt;The effort to test is just to high&lt;/li&gt;
&lt;li&gt;Everytime I change my code, I also need to change my tests...&lt;/li&gt;
&lt;li&gt;It's just not worth it!!!1eleven&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Now that I'm only a relative beginner (hey, at least I dipped my toe into the water), let me tell you the &lt;em&gt;dark and secret&lt;/em&gt; truth, no one was able to reveal to you:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Testing is not about tests. It's about Software Design!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Phew...&lt;/p&gt;

&lt;p&gt;And here comes another one:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;You're code will become better automatically, if you try to auto-test it!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Wow!&lt;/p&gt;

&lt;p&gt;So there's really something else behind this topic, that divides beginners and pros, and now you know what. But how can someone cross this bridge?&lt;/p&gt;

&lt;h3&gt;
  
  
  Start testing - today!
&lt;/h3&gt;

&lt;p&gt;It's that simple! You just write a test for a trivial little thing. You might even think: This won't ever go wrong, this test is useless! But it doesn't matter. Soon you'll have a hundred of them. And you'll see more and more potential for automated tests in your codebase.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Software testing is a Skill!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;And every little thing you read, do and learn about it, gives you a little more experience. Not only about coding, but also about the way you design and implement your Software.&lt;/p&gt;

&lt;p&gt;At the beginning, you might test something trivial, or you might even start with writing End 2 End tests. It doesn't matter, because every line of code will expand your horizont, little by little.&lt;/p&gt;

&lt;p&gt;Soon you'll see, that you need to restructure your code a bit, so that you can apply a test on it.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You'll make it less coupled to external dependencies, so that you have the chance to spy/mock/stub/fake some things.&lt;/li&gt;
&lt;li&gt;You care about Dependency injection, Dependency inversion, and about Object Oriented / Domain Driven / functional Design in General&lt;/li&gt;
&lt;li&gt;You might write smaller chunks of codes, so that each class and method has a single responsibility (which is testable)&lt;/li&gt;
&lt;li&gt;You might think of event or message based architectures to decouple your code even more&lt;/li&gt;
&lt;li&gt;You start using more configuration files or parameters, so that you don't even have to code so many changes anymore&lt;/li&gt;
&lt;li&gt;...&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And most important:&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;You Start thinking about your code, before you write it!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;It will be so awesome, because a whole new world opens up for you. You'll re-read all the stuff about design patterns, refactoring and software design and now you see so much more in it. You know how to combine things, move them around and / or reassign them with ease.&lt;/p&gt;

&lt;p&gt;You'll feel like you're a code magician! A sort of tibetian monk with supernatural coding powers.&lt;/p&gt;

&lt;p&gt;And someday after, it'll just become &lt;strong&gt;natural&lt;/strong&gt; to think this way. You'll have it integrated in your day to day workflow. You write great code, others are stunned about, and don't even think about it.&lt;/p&gt;

&lt;p&gt;And then, you try to help the newbies with their testing Requests on the internet...&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;No, this is not unit testing. You're testing with external dependencies... that's integration testing! Try to avoid overusing that... mind the upside down testing Pyramid! ... ...&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Life is strange ¯\_(ツ)_/¯&lt;/p&gt;

</description>
      <category>motivation</category>
      <category>unittests</category>
      <category>testing</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
