<?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>Forem: Alex Jover</title>
    <description>The latest articles on Forem by Alex Jover (@alexjoverm).</description>
    <link>https://forem.com/alexjoverm</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%2F13298%2F90781987-33cc-4f9f-9fb5-3e325023b693.jpeg</url>
      <title>Forem: Alex Jover</title>
      <link>https://forem.com/alexjoverm</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/alexjoverm"/>
    <language>en</language>
    <item>
      <title>Are you attending ViteConf 2024?</title>
      <dc:creator>Alex Jover</dc:creator>
      <pubDate>Tue, 24 Sep 2024 16:01:27 +0000</pubDate>
      <link>https://forem.com/storyblok/are-you-attending-viteconf-2024-340g</link>
      <guid>https://forem.com/storyblok/are-you-attending-viteconf-2024-340g</guid>
      <description>&lt;p&gt;It’s safe to say that ViteConf is the biggest online conference on the Web Development these days, gathering the main experts from all the frameworks and technologies in the industry. And it makes sense… which web project is not using Vite these days?&lt;/p&gt;

&lt;p&gt;We’re really thrilled about &lt;a href="https://viteconf.org/" rel="noopener noreferrer"&gt;ViteConf 24&lt;/a&gt;, happening &lt;strong&gt;3rd &amp;amp; 4th October&lt;/strong&gt;! As last year, we’re proud to be an official community partner. But that’s not all - our dear &lt;a href="https://x.com/alvarosabu" rel="noopener noreferrer"&gt;Alvaro Saburido&lt;/a&gt; is speaking at the conference! About what? Well… you wanted to know.&lt;/p&gt;

&lt;p&gt;Before that - we just &lt;a href="https://www.youtube.com/watch?v=sW6BHBIN-vk" rel="noopener noreferrer"&gt;published in Youtube&lt;/a&gt; an &lt;strong&gt;interview with &lt;a href="https://patak.dev/" rel="noopener noreferrer"&gt;Matias (Patak)&lt;/a&gt;&lt;/strong&gt;, Vite core team member and the mastermind behind ViteConf, and Alvaro sharing a few sneak peeks on the conference. Make sure not to miss it!&lt;/p&gt;

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

&lt;h2&gt;
  
  
  Main talk - How the ViteConf Pyraminx 3D Puzzle Was Built
&lt;/h2&gt;

&lt;p&gt;&lt;a href="https://x.com/alvarosabu" rel="noopener noreferrer"&gt;Alvaro&lt;/a&gt;, DX Engineer at Storyblok and author or the &lt;a href="https://tresjs.org/" rel="noopener noreferrer"&gt;Tres.js ecosystem&lt;/a&gt;, will dive deep into the technical creation of a fully interactive &lt;strong&gt;3D Pyraminx puzzle&lt;/strong&gt; that you’ll see at ViteConf. &lt;/p&gt;

&lt;p&gt;Would you believe that such immersive creation is built purely with Vue and TresJS? But that’s not all: it also leverages &lt;strong&gt;Web Containers&lt;/strong&gt;, a tool that enables running full-stack JavaScript environments directly in the browser.&lt;/p&gt;

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

&lt;p&gt;Spoiler alert: Alvaro will reveal the process behind turning this random crazy idea into a working, interactive 3D app. Expect to learn about:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;How to integrate &lt;strong&gt;TresJS&lt;/strong&gt; with &lt;strong&gt;Vue&lt;/strong&gt; to streamline 3D development.&lt;/li&gt;
&lt;li&gt;The magic behind &lt;strong&gt;Web Containers&lt;/strong&gt; and how they allow JavaScript to run directly in the browser—yes, including server-side code!&lt;/li&gt;
&lt;li&gt;The creative process behind that made the Pyraminx project an immersive reality.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Innovative, uh? The web is amazing and full of potential… really a talk not to miss! Check out &lt;a href="https://viteconf.org/24/speaker/alvarosabu" rel="noopener noreferrer"&gt;all details about Alvaro’s talk&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;One more thing… Did you know you can customize your ticket? Look at the fancy Storyblok custom ticket &lt;a href="https://viteconf.org/24/ecosystem/storyblok" rel="noopener noreferrer"&gt;https://viteconf.org/24/ecosystem/storyblok&lt;/a&gt;&lt;/p&gt;

</description>
      <category>vite</category>
      <category>techtalks</category>
      <category>astro</category>
    </item>
    <item>
      <title>🚀 Fresh Storyblok SDK releases, plus new Canada and Australia regions 🌍</title>
      <dc:creator>Alex Jover</dc:creator>
      <pubDate>Thu, 21 Dec 2023 13:54:34 +0000</pubDate>
      <link>https://forem.com/storyblok/fresh-storyblok-sdk-releases-plus-new-canada-and-australia-regions-f3g</link>
      <guid>https://forem.com/storyblok/fresh-storyblok-sdk-releases-plus-new-canada-and-australia-regions-f3g</guid>
      <description>&lt;p&gt;Following up on the &lt;a href="https://www.storyblok.com/mp/storyblok-adds-australia-and-canada" rel="noopener noreferrer"&gt;2 new regions announcement&lt;/a&gt;, we're thrilled to unveil the latest updates to our SDK family, introducing cutting-edge features, supporting the latest frameworks versions, and expanding our horizons to better serve our incredible community. &lt;/p&gt;

&lt;h2&gt;
  
  
  ✨ What Changed?
&lt;/h2&gt;

&lt;p&gt;🌍 &lt;strong&gt;2 new regions:&lt;/strong&gt; We added dedicated Australia 🦘 and Canada 🍁  regions, now available across all our SDKs. Having a Storyblok space hosted in your region is not an issue anymore! Check the &lt;a href="https://www.storyblok.com/mp/storyblok-adds-australia-and-canada" rel="noopener noreferrer"&gt;new regions blog post&lt;/a&gt; to know all the details about it.&lt;/p&gt;

&lt;p&gt;🚀 &lt;strong&gt;Astro 4 support:&lt;/strong&gt; We’re surfing the Astro 4 wave, featuring the brand-new Toolbar—now access to docs is instant! We’re also dropping support for Astro 2 (still available on &lt;code&gt;@storyblok/astro@3&lt;/code&gt;)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fifssu5xmvuhzbfy970xt.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fifssu5xmvuhzbfy970xt.png" alt="Astro 4 tooltip" width="800" height="576"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;🌟 &lt;strong&gt;Svelte 4 and SvelteKit 2.0 support:&lt;/strong&gt; Enjoy all the performance and UX improvements the Svelte team accomplished on SvelteKit 2.0.&lt;/p&gt;

&lt;p&gt;🛠️ &lt;strong&gt;Breaking change alert - storyblok-js-client v6:&lt;/strong&gt; We updated all SDKs to the latest js-client v6, including a bunch of bugfixes and improvements. Be aware that now the error messages have a different format, check out the details in the &lt;a href="https://github.com/storyblok/storyblok-js-client/releases/tag/v6.0.0" rel="noopener noreferrer"&gt;js-client v6 release&lt;/a&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  🔄 Steps to Update to the Latest SDK versions
&lt;/h3&gt;

&lt;p&gt;As simple as installing the latest version of the SDK of your choice on your project. As an example, for React SDK:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; @storyblok/react@latest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  🌍 Expanding Horizons: Leveraging the New Regions
&lt;/h2&gt;

&lt;p&gt;Integrating the newly introduced regions into your workflow is seamless! When initializing your SDK, simply add the &lt;strong&gt;&lt;code&gt;region&lt;/code&gt;&lt;/strong&gt; parameter within the &lt;strong&gt;&lt;code&gt;apiOptions&lt;/code&gt;&lt;/strong&gt;. To know all regions available, simply check out the &lt;a href="https://github.com/storyblok/storyblok-js?tab=readme-ov-file#region-parameter" rel="noopener noreferrer"&gt;SDK readme&lt;/a&gt;.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight jsx"&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;storyblokInit&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;apiPlugin&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="s2"&gt;@storyblok/react&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nf"&gt;storyblokInit&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;accessToken&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;YOUR_ACCESS_TOKEN&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;use&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nx"&gt;apiPlugin&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;apiOptions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;region&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ca&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="c1"&gt;// or "eu" (default), "us", "cn", "ap"&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;h3&gt;
  
  
  🛠️  Full List of New Frontend SDKs versions
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;JS SDK&lt;/strong&gt; (&lt;strong&gt;&lt;code&gt;@storyblok/js&lt;/code&gt;&lt;/strong&gt;) - &lt;a href="https://github.com/storyblok/storyblok-js/releases/tag/v3.0.0" rel="noopener noreferrer"&gt;v3.0.0&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Vue SDK&lt;/strong&gt; - &lt;a href="https://github.com/storyblok/storyblok-vue/releases/tag/v8.0.0" rel="noopener noreferrer"&gt;v8.0.0&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Nuxt SDK&lt;/strong&gt; - &lt;a href="https://github.com/storyblok/storyblok-nuxt/releases/tag/v6.0.0" rel="noopener noreferrer"&gt;v6.0.0&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;React SDK&lt;/strong&gt; - &lt;a href="https://github.com/storyblok/storyblok-react/releases/tag/v3.0.0" rel="noopener noreferrer"&gt;v3.0.0&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Astro SDK&lt;/strong&gt; - &lt;a href="https://github.com/storyblok/storyblok-astro/releases/tag/v4.0.0" rel="noopener noreferrer"&gt;v4.0.0&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Vue 2 SDK&lt;/strong&gt; - &lt;a href="https://github.com/storyblok/storyblok-vue-2/releases/tag/v4.0.0" rel="noopener noreferrer"&gt;v4.0.0&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Nuxt 2 SDK&lt;/strong&gt; - &lt;a href="https://github.com/storyblok/storyblok-nuxt-2/releases/tag/v3.0.0" rel="noopener noreferrer"&gt;v3.0.0&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Svelte SDK&lt;/strong&gt; - &lt;a href="https://github.com/storyblok/storyblok-svelte/releases/tag/v4.0.0" rel="noopener noreferrer"&gt;v4.0.0&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Gatsby SDK&lt;/strong&gt; - &lt;a href="https://github.com/storyblok/gatsby-source-storyblok/releases/tag/v7.0.0" rel="noopener noreferrer"&gt;v7.0.0&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  🧑‍💻  Ready to try it out?
&lt;/h2&gt;

&lt;p&gt;We really value your feedback, so don’t hesitate to jump in and ask your question in &lt;a href="https://discord.gg/jKrbAMz" rel="noopener noreferrer"&gt;Storyblok Discord&lt;/a&gt;, or open an issue in the related SDK Github repo.&lt;/p&gt;

&lt;p&gt;Are you new here? Go to &lt;a href="https://www.storyblok.com/technologies" rel="noopener noreferrer"&gt;Storyblok QuickStart&lt;/a&gt; and get your project fully integrated with your favorite framework in just 1 command!&lt;/p&gt;

&lt;p&gt;Happy coding! 🎉&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>headless</category>
      <category>react</category>
    </item>
    <item>
      <title>Hybrid Rendering: the secret way to smoothly test Vue.js components</title>
      <dc:creator>Alex Jover</dc:creator>
      <pubDate>Mon, 07 Mar 2022 07:00:00 +0000</pubDate>
      <link>https://forem.com/alexjoverm/hybrid-rendering-the-secret-way-to-smoothly-test-vuejs-components-275p</link>
      <guid>https://forem.com/alexjoverm/hybrid-rendering-the-secret-way-to-smoothly-test-vuejs-components-275p</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally posted on &lt;a href="https://vuedose.tips/hybrid-rendering-the-secret-way-to-test-components-in-vuejs"&gt;VueDose.tips&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;In the article &lt;a href="https://vuedose.tips/tips/deep-vs-shallow-rendering-in-vuejs-tests"&gt;Deep vs Shallow Rendering in Vue.js Tests&lt;/a&gt; I showed you how deep and shallow rendering works to create Vue.js tests.&lt;/p&gt;

&lt;p&gt;Each of them have their own use case and it could depend in your way of testing and architecting as well.&lt;/p&gt;

&lt;p&gt;But… why not having the best of both worlds? Let’s get into Hybrid Rendering.&lt;/p&gt;

&lt;p&gt;The &lt;strong&gt;Hybrid Rendering&lt;/strong&gt; consists on stubbing only part of the child components on a test.&lt;/p&gt;

&lt;p&gt;For instance, taking back the example from the tip, let's add another component called &lt;code&gt;FoodList&lt;/code&gt; to the &lt;code&gt;App&lt;/code&gt; component:&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;template&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;div&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;h3&amp;gt;&lt;/span&gt;User List&lt;span class="nt"&gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;UserList&lt;/span&gt; &lt;span class="na"&gt;:users=&lt;/span&gt;&lt;span class="s"&gt;"['Rob Wesley']"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;FoodList&lt;/span&gt; &lt;span class="na"&gt;:foods=&lt;/span&gt;&lt;span class="s"&gt;"['Tomatoes', 'Carrots']"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;script &lt;/span&gt;&lt;span class="na"&gt;setup&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;UserList&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./UserList&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;FoodList&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;./FoodList&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Assuming &lt;code&gt;FoodList&lt;/code&gt; has a similar implementation to &lt;code&gt;UserList&lt;/code&gt;, and we're using deep rendering, this test:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;mount&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="s2"&gt;@vue/test-utils&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;App&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@/App&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App.vue&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Deep renders the App component&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;wrapper&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;wrapper&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;html&lt;/span&gt;&lt;span class="p"&gt;()).&lt;/span&gt;&lt;span class="nx"&gt;toMatchSnapshot&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;will result in the following snapshot:&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;div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;h3&amp;gt;&lt;/span&gt;User List&lt;span class="nt"&gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;
      Rob Wesley
    &lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;
      Tomatoes
    &lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;
      Carrots
    &lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now, let's say that for whatsoever reason you want only to deep render &lt;code&gt;UserList&lt;/code&gt;, but not &lt;code&gt;FoodList&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;In that case, you can use the &lt;code&gt;stubs&lt;/code&gt; option of the &lt;code&gt;mount&lt;/code&gt; method in order to indicate which components must be stubbed:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;mount&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="s2"&gt;@vue/test-utils&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;App&lt;/span&gt; &lt;span class="k"&gt;from&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;@/App&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="nx"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;App.vue&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Hybrid renders the app component&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;wrapper&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;mount&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="na"&gt;stubs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;FoodList&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="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;wrapper&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;html&lt;/span&gt;&lt;span class="p"&gt;()).&lt;/span&gt;&lt;span class="nx"&gt;toMatchSnapshot&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
  &lt;span class="p"&gt;});&lt;/span&gt;
&lt;span class="p"&gt;});&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice I'm stubbing &lt;code&gt;FoodList&lt;/code&gt;. That's the way to apply hybrid rendering in a test, or partial shallow/deep rendering if you're more comfortable with that name.&lt;/p&gt;

&lt;p&gt;The generated snapshot in this case will be like:&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;div&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;h3&amp;gt;&lt;/span&gt;User List&lt;span class="nt"&gt;&amp;lt;/h3&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;li&amp;gt;&lt;/span&gt;
      Rob Wesley
    &lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;foodlist-stub&lt;/span&gt; &lt;span class="na"&gt;foods=&lt;/span&gt;&lt;span class="s"&gt;"Tomatoes,Carrots"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&amp;lt;/foodlist-stub&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;

&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Keep in mind that this won't work with &lt;code&gt;shallowMount&lt;/code&gt;, since it already stubs all child components. So make sure to use &lt;code&gt;mount&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Do you have any case in mind where this technique can be useful in your projects? Let me know on &lt;a href="https://twitter.com/vuedose"&gt;Twitter&lt;/a&gt;!&lt;/p&gt;

&lt;p&gt;That's it for today's tip!&lt;/p&gt;

&lt;p&gt;Stay cool 🦄&lt;/p&gt;

</description>
    </item>
    <item>
      <title>1 year organising Alicante Frontend</title>
      <dc:creator>Alex Jover</dc:creator>
      <pubDate>Tue, 21 Nov 2017 09:46:07 +0000</pubDate>
      <link>https://forem.com/alexjoverm/1-year-organising-alicante-frontend-do1</link>
      <guid>https://forem.com/alexjoverm/1-year-organising-alicante-frontend-do1</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="http://alexjoverm.github.io/2017/11/21/1-year-organising-Alicante-Frontend/"&gt;alexjoverm.github.io&lt;/a&gt; on November 21, 2017&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;Here are my insights about organising Alicante Frontend’s meetup after a year.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--CLSon_dg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://alexjoverm.github.io/2017/11/21/1-year-organising-Alicante-Frontend/birthday.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--CLSon_dg--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://alexjoverm.github.io/2017/11/21/1-year-organising-Alicante-Frontend/birthday.png" alt="First birthday of Alicante Frontend" title="First birthday of Alicante Frontend"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;One year ago, &lt;a href="https://twitter.com/aarongarciah"&gt;Aaron&lt;/a&gt;, &lt;a href="https://twitter.com/AlvYuste"&gt;Alvaro&lt;/a&gt; and I started this amazing ride together. It’s been a year of meeting lots of people and having lots of fun. Satisfaction, success and happiness are the words that come to my mind when I think of &lt;a href="http://alicantefrontend.es/"&gt;Alicante Frontend&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;At the beginning, we were not sure about this success. Unlike bigger cities, Alicante didn’t have much community, apparently. Similar meetups from cities around had a stable 20-30 RSVP average. Still, we decided to make it happen even expecting less than 20 people attending.&lt;/p&gt;

&lt;p&gt;Nowadays, it’s a pretty cool community that had a great variety of events, surpassing 100+ RSVP and having international events. We’ve had all kind of fun stuff, such as raffles and food&amp;amp;drinks networking. You can find us on the following channels:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://www.meetup.com/preview/Alicante-Frontend"&gt;Meetup&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="http://alicantefrontend.herokuapp.com/"&gt;Slack&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://twitter.com/AlicanteFront"&gt;Twitter&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What’s Alicante Frontend made of?
&lt;/h2&gt;

&lt;p&gt;First of all, we needed a &lt;strong&gt;regular place&lt;/strong&gt; to host the events. We were lucky to find &lt;a href="https://ulab.es/"&gt;ULab&lt;/a&gt;, a co-working center that made everything easy for us from the beginning. Not only allowing us to use the space, but also helping us preparing and promoting them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--Atse1zFF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://alexjoverm.github.io/2017/11/21/1-year-organising-Alicante-Frontend/ulab.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--Atse1zFF--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://alexjoverm.github.io/2017/11/21/1-year-organising-Alicante-Frontend/ulab.jpeg" alt="ULab, the coworking center where we host the meetups" title="ULab, the coworking center where we host the meetups"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In ULab, &lt;strong&gt;speakers&lt;/strong&gt; come and share whatever they’d like to. They’re core of the events, and very, very difficult to find. That’s why we like to compensate them for their effort. Lately we’ve been consistently having speakers every month, which is great.&lt;/p&gt;

&lt;p&gt;Usually, we get to the events a bit sooner so we start preparing it. We try to make some fun so the speakers relax and feel more comfortable.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--HywrlK78--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://alexjoverm.github.io/2017/11/21/1-year-organising-Alicante-Frontend/preparations.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--HywrlK78--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://alexjoverm.github.io/2017/11/21/1-year-organising-Alicante-Frontend/preparations.jpg" alt="Getting ready with speakers" title="Getting ready with speakers"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Then, an organizer gives a sync-up intro so we share some news, announcements, decisions or whatever that we have to for that month. We’d like to be as transparent as possible in order to keep the community informed.&lt;/p&gt;

&lt;p&gt;We had talks about JavaScript, functional (reactive) programming, building projects, Web performance, Web analytics, and even a workshop of Clojure. Special thanks to &lt;a href="https://twitter.com/FlavioCorpa"&gt;Flavio Corpa&lt;/a&gt;, &lt;a href="https://twitter.com/FlavioCorpa"&gt;Ciro Ivan&lt;/a&gt;, &lt;a href="https://twitter.com/kikobeats"&gt;Kikobeats&lt;/a&gt;, &lt;a href="https://github.com/joakin"&gt;Joaquin&lt;/a&gt;, &lt;a href="https://twitter.com/jmperezperez"&gt;Jose Manuel Perez&lt;/a&gt; and &lt;a href="https://twitter.com/laurabonmati"&gt;Laura Bonmati&lt;/a&gt; for their talks and keeping this community alive.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--TQQdr6FZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://alexjoverm.github.io/2017/11/21/1-year-organising-Alicante-Frontend/speakers.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--TQQdr6FZ--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://alexjoverm.github.io/2017/11/21/1-year-organising-Alicante-Frontend/speakers.jpg" alt="Several speakers of Alicante Frontend in 2017" title="Several speakers of Alicante Frontend in 2017"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In Alicante Frontend, we care about involving &lt;strong&gt;companies&lt;/strong&gt;. We believe there is a need of improving the culture and mindset of local companies, and what’s better than doing that starting from their people? We mentor each other on technologies, workflows and best practices. It’s a win-to-win: companies get more visibility and qualified employees while employees feel more satisfied and productive by learning stuff and meeting people in the community. We hope this increases the visibility for foreign companies to come to Alicante, which means more and better job opportunities.&lt;/p&gt;

&lt;p&gt;Thanks to the companies that help us, we can do all kind of cool stuff that requires a minimum amount of costs: having stickers, presents for the speakers, meetup’s costs…&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--A40xlLau--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://alexjoverm.github.io/2017/11/21/1-year-organising-Alicante-Frontend/sponsors.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--A40xlLau--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://alexjoverm.github.io/2017/11/21/1-year-organising-Alicante-Frontend/sponsors.png" alt="Sponsors and collaborators" title="Sponsors and collaborators"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Last but not least, Alicante Frontend is its &lt;strong&gt;people&lt;/strong&gt;. We all come to teach, to learn, to share, and more importantly to &lt;strong&gt;have fun&lt;/strong&gt;. That’s community, doesn’t matter how many you are, what matters is to enjoy meeting new people, talking about how your work is, what have you been doing lately and share experiences in general. We all are a great family.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--ajS2Tsgs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://alexjoverm.github.io/2017/11/21/1-year-organising-Alicante-Frontend/people.jpeg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--ajS2Tsgs--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://alexjoverm.github.io/2017/11/21/1-year-organising-Alicante-Frontend/people.jpeg" alt="Alicante Frontend's people" title="Alicante Frontend's people"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Part of that happens in the &lt;strong&gt;networking&lt;/strong&gt; , right after the event. Here we surely have fun.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--kLk53wVr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://alexjoverm.github.io/2017/11/21/1-year-organising-Alicante-Frontend/networking.jpg" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--kLk53wVr--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/http://alexjoverm.github.io/2017/11/21/1-year-organising-Alicante-Frontend/networking.jpg" alt="Alicante Frontend's networking" title="Alicante Frontend's networking"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h1&gt;
  
  
  The future
&lt;/h1&gt;

&lt;p&gt;We’d like to keep up the hype and continue growing and improving this lovely community. Taking a retrospective view and matching our values, we have plenty of cool ideas we want to try out next year:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Have more fun! Hands-on events&lt;/strong&gt; : knowing how difficult is to find speakers around here, and how fun people consider “practical” events, we’ll probably organise more workshop/hackaton-like events. Ideas: &lt;em&gt;Code in the Dark, Open Hacking (featuring Open Source), Katas…&lt;/em&gt;
&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Bring speakers&lt;/strong&gt; : we’d like to bring somehow known speakers from outside Alicante, having a sponsor covering the costs. We already have one confirmed for next year, so stay tuned! :)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Conference&lt;/strong&gt; : Alicante is a very convenient place for a conference, in terms of connections, weather and standard of living. That’s proven by the success of &lt;a href="http://reactalicante.es/"&gt;React Alicante&lt;/a&gt;. However, this is not something we can rush to do: organising a conference requires an extremely amount of time, energy and dedication, and we don’t have that much (we have lives aside from work and Alicante Frontend), so we need to make sure we can commit to it, and if we do, to enjoy it. For that reason, we cannot make sure this will happen this year. &lt;strong&gt;Would you like to be part of this?&lt;/strong&gt; We’ll need help for sure, so don’t hesitate in contacting us.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Any other ideas? Please tell us!&lt;/p&gt;

&lt;p&gt;We hope you get an overview of what Alicante Frontend is and what our values are. We wish this community to keep up growing and improving, bringing more people and companies together. We’re excited and doing our best to improve the Web community in Alicante! So if you haven’t come and visit us, what are you waiting for?&lt;/p&gt;

</description>
      <category>community</category>
    </item>
    <item>
      <title>My tips to be a happier developer</title>
      <dc:creator>Alex Jover</dc:creator>
      <pubDate>Mon, 13 Nov 2017 13:58:35 +0000</pubDate>
      <link>https://forem.com/alexjoverm/my-tips-to-be-a-happier-developer-53o</link>
      <guid>https://forem.com/alexjoverm/my-tips-to-be-a-happier-developer-53o</guid>
      <description>

&lt;p&gt;Here are some tips that I’m practising to be a happier developer.&lt;/p&gt;

&lt;p&gt;Are you often in a frustrated mood? Do you think sometimes that you don’t meet the deadlines? Are you worried about not performing well, or getting negative feedback, or that is too big for you? Do you sometimes suffer anxiety or stress?&lt;/p&gt;

&lt;p&gt;I’ve been suffering an anxiety/panic disorder for almost a year. I’m not gonna get into the details, is not a happy story and is somewhat complex, but the point is I’ve learned a lot on the way. I’m writing this article, both to remind myself and to tell you what have I learnt and found out during this time.&lt;/p&gt;

&lt;p&gt;Keep in mind that these are my points, it may work or not for you. Do you have any other you wanna share? :)&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Focus on success rather than failure
&lt;/h2&gt;

&lt;p&gt;Programming is an activity that it’s about constantly having a problem and solving it. That makes it a very risky activity. How many times did you get stuck at some point? And trying to find the reason of a bug? Probably you get to sleep and other day you solve it quickly, right?&lt;/p&gt;

&lt;p&gt;We usually have deadlines, which makes us to come up with a delivery plan. In addition, we expect the software we build to work flawlessly, and the the users of the system we’re building to like it.&lt;/p&gt;

&lt;p&gt;As you can see, there are many things that can go wrong (and will). So, what can we do about all that?&lt;/p&gt;

&lt;p&gt;Well, we &lt;strong&gt;can’t do anything to prevent this to happen&lt;/strong&gt;. But instead, we can:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Don’t blame yourself (or others)&lt;/strong&gt;: Remember &lt;strong&gt;you do everything the best you can&lt;/strong&gt; , so just don’t punish yourself when you get stuck, don’t meet a deadline or whatever goes wrong. Probably the reason was in a bad planning, or short time.&lt;/li&gt;
&lt;li&gt;Instead, &lt;strong&gt;congratulate yourself&lt;/strong&gt; for whatever tiny thing you did or tried. What I usually do is to by the end of the day, I &lt;strong&gt;write 4 or 5 things I did in a post-it&lt;/strong&gt; and stick it somewhere around.&lt;/li&gt;
&lt;li&gt;When something goes wrong, think on &lt;strong&gt;what you tried&lt;/strong&gt; to do instead of the failure itself. Then, you could do a &lt;strong&gt;retrospective&lt;/strong&gt; on yourself or with your team, to see how to do this better for the next time.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  2. Build empathy within your team
&lt;/h2&gt;

&lt;p&gt;Development is a team sport. One alone just cannot do much, plus it can get boring. So try to be as much comfortable as you can with the team you’re working on. Any social skill you can apply here will be good. Here some are my tips:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Learn to take/give feedback&lt;/strong&gt; : Nothing can be more annoying than someone putting down your work. So don’t be like that and give constructive feedback. One way is to apply the &lt;a href="http://www.rightattitudes.com/2008/02/20/sandwich-feedback-technique/"&gt;Sandwich model&lt;/a&gt; (good, bad, good) when you must say something unpleasant to someone. It’d be good for you if you can ignore non constructive feedback, or do the sandwich mentally yourself afterwards :)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Practise team building activities&lt;/strong&gt; : It can go from doing sport, going for lunch… anything&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Thank someone everyday&lt;/strong&gt; : This is a positive thinking technique that could apply to anything in your live. Send a message/email/whatever to a colleague thanking him/her, even for very small things, such as &lt;em&gt;“Hey John! Thanks a lot for helping me finding that bug before!”&lt;/em&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  3. Manage your time and priorities
&lt;/h2&gt;

&lt;p&gt;Nowadays life goes fast, so fast that we go faster with it. And we end up in a routine where we try to do too many things that we can manage to do. That makes us being really over-demanding on ourselves, leading to frustration and anxiety because of not completing the tasks, or doing it under much pressure for quite some time.&lt;/p&gt;

&lt;p&gt;You wanna prepare a talk, attend a meetup, keep your Open Source work, write on your blog, stay healthy practising sport, meet with friends, spend time with your family, run some side-project… and you work full time as well. Be careful, being too ambitious can turn against you.&lt;/p&gt;

&lt;p&gt;What can we do to about it?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Slow down and push the break&lt;/strong&gt; : Minimize your task queue. Keep in mind it is better to do 2 things well done, than 4 badly/quickly done.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Enjoy what you do&lt;/strong&gt; : When you slow down, you have more time to pay attention to what you’re doing, making it be more enjoyable. That’s what mindfulness stands for.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Apply a time management technique&lt;/strong&gt; : Personally I (kind of) use &lt;a href="http://lifehacker.com/productivity-101-a-primer-to-the-pomodoro-technique-1598992730"&gt;Pomodoro&lt;/a&gt;. The point is to enforce breaks to move and distract yourself in order to don’t spend hours on a task continuously.&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  4. Keep up your motivation
&lt;/h2&gt;

&lt;p&gt;I’m not a fan of Steve Jobs, but he said it very well:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;“Stay hungry, stay foolish”&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;There is nothing more wonderful that being motivated on what you’re doing. It makes you love your work and spread that to the people of your circle.&lt;/p&gt;

&lt;p&gt;Keeping yourself up to date and involved in the community of your technologies is a must for keeping up your motivation. You’ll grow, which makes you feel productive. You’ll socialize and meet new people. You’ll find people you admire and people who admire you, and that is really beautiful.&lt;/p&gt;

&lt;p&gt;You could feel like the following tips are against the point &lt;em&gt;Manage your time and priorities&lt;/em&gt;, but they are beneficial as long as you &lt;strong&gt;make sure you don’t overdo&lt;/strong&gt; , and set a &lt;strong&gt;limit&lt;/strong&gt; for these:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Do Open Source!&lt;/strong&gt; : Now is easier than ever, since an &lt;a href="https://opensource.guide/"&gt;open source guide&lt;/a&gt; has been created by github itself and lots of experienced OSS devs. I’ve started &lt;a href="https://github.com/alexjoverm"&gt;doing it&lt;/a&gt; and got many good feedback from my projects users! Not to mention the feeling when you’re doing something other people find useful&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Go to Meetups and conferences&lt;/strong&gt; : You’ll meet lots of people physically, which opens you a lot of doors and keeps you connected to more communities and its ecosystem. If you’re brave enough to speak in one, you’ll get a great feeling afterwards, so go and try and see what it feels like ;).&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Build side projects&lt;/strong&gt; : It can be anything, such as building dummy apps, organizing events, sharing knowledge, creating libraries, etc. Some things I did is to create this blog, become an &lt;a href="https://egghead.io/instructors/alex-jover-morales"&gt;Egghead instructor&lt;/a&gt;, create &lt;a href="https://www.meetup.com/es-ES/Alicante-Frontend/"&gt;Alicante Frontend&lt;/a&gt; meetup group with some friends, contributing to Open Source…&lt;/li&gt;
&lt;/ul&gt;

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

&lt;p&gt;There are really a lot of ways to be happier and better as a developer, and they come mostly from the psychology side instead of from being a successful developer. Here I told you some of my tips, I’m looking forward to hear yours!&lt;/p&gt;

&lt;p&gt;If you like it, please go and share it! You can follow me on this blog or on twitter as &lt;a href="https://twitter.com/alexjoverm"&gt;@alexjoverm&lt;/a&gt;. Any questions? Shoot!&lt;/p&gt;


</description>
      <category>humanside</category>
    </item>
    <item>
      <title>Write the first Vue.js Component Unit Test in Jest</title>
      <dc:creator>Alex Jover</dc:creator>
      <pubDate>Mon, 21 Aug 2017 06:25:40 +0000</pubDate>
      <link>https://forem.com/alexjoverm/write-the-first-vuejs-component-unit-test-in-jest-35f</link>
      <guid>https://forem.com/alexjoverm/write-the-first-vuejs-component-unit-test-in-jest-35f</guid>
      <description>&lt;p&gt;&lt;em&gt;Wait, a &lt;strong&gt;&lt;a href="https://leanpub.com/testingvuejscomponentswithjest"&gt;book on Testing Vue with Jest?&lt;/a&gt;&lt;/strong&gt; Yeah, this article is just the first chapter&lt;/em&gt; 😉&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/vuejs/vue-test-utils"&gt;vue-test-utils&lt;/a&gt;, the official VueJS testing library and based on &lt;a href="https://github.com/eddyerburgh/avoriaz"&gt;avoriaz&lt;/a&gt;, is just around the corner. &lt;a href="https://twitter.com/EddYerburgh"&gt;@EddYerburgh&lt;/a&gt; is indeed doing a very good job creating it. It provides all necessary tooling for making easy to write unit test in a VueJS application.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://facebook.github.io/jest"&gt;Jest&lt;/a&gt;, on the other side, is the testing framework developed at Facebook, which makes testing a breeze, with awesome features such as:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Almost no config by default&lt;/li&gt;
&lt;li&gt;Very cool interactive mode&lt;/li&gt;
&lt;li&gt;Run tests in parallel&lt;/li&gt;
&lt;li&gt;Spies, stubs and mocks out of the box&lt;/li&gt;
&lt;li&gt;Built in code coverage&lt;/li&gt;
&lt;li&gt;Snapshot testing&lt;/li&gt;
&lt;li&gt;Module mocking utilities&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Probably you’ve already written test without this tools, and just by using karma + mocha + chai + sinon + …, but you’ll see how much easier it can be 😉.&lt;/p&gt;

&lt;h2&gt;
  
  
  Set up a vue-test sample project
&lt;/h2&gt;

&lt;p&gt;Let’s start by creating a new project using &lt;a href="https://github.com/vuejs/vue-cli"&gt;&lt;code&gt;vue-cli&lt;/code&gt;&lt;/a&gt; answering NO to all yes/no questions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm &lt;span class="nb"&gt;install&lt;/span&gt; &lt;span class="nt"&gt;-g&lt;/span&gt; vue-cli
vue init webpack vue-test
&lt;span class="nb"&gt;cd &lt;/span&gt;vue-test
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then we’ll need to install some dependencies:&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="c"&gt;# Install dependencies &lt;/span&gt;
npm i &lt;span class="nt"&gt;-D&lt;/span&gt; jest jest-vue-preprocessor babel-jest
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;a href="https://github.com/vire/jest-vue-preprocessor"&gt;&lt;code&gt;jest-vue-preprocessor&lt;/code&gt;&lt;/a&gt; is needed for making jest understand &lt;code&gt;.vue&lt;/code&gt; files, and &lt;a href="https://github.com/babel/babel-jest"&gt;&lt;code&gt;babel-jest&lt;/code&gt;&lt;/a&gt; for the integration with Babel.&lt;/p&gt;

&lt;p&gt;As per &lt;code&gt;vue-test-utils&lt;/code&gt;, it &lt;del&gt;hasn’t been released yet, but for now you can add it to your &lt;code&gt;package.json&lt;/code&gt; from the source&lt;/del&gt; :&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Update (2017/10/10)&lt;/strong&gt;: it can be installed already from npm, since &lt;code&gt;beta.1&lt;/code&gt; has been published.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i &lt;span class="nt"&gt;-D&lt;/span&gt; vue-test-utils
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let’s add the following Jest configuration in the &lt;code&gt;package.json&lt;/code&gt;:&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="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="nl"&gt;"jest"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"moduleNameMapper"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"^vue$"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"vue/dist/vue.common.js"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"moduleFileExtensions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"js"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"vue"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"transform"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"^.+\\.js$"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;rootDir&amp;gt;/node_modules/babel-jest"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;".*\\.(vue)$"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"&amp;lt;rootDir&amp;gt;/node_modules/jest-vue-preprocessor"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Testing a Component
&lt;/h2&gt;

&lt;p&gt;I’ll be using Single File Components here, and I haven’t checked if it works by splitting them in their own &lt;code&gt;html&lt;/code&gt;, &lt;code&gt;css&lt;/code&gt; or &lt;code&gt;js&lt;/code&gt; files, so let’s assume you’re doing that as well.&lt;/p&gt;

&lt;p&gt;First create a &lt;code&gt;MessageList.vue&lt;/code&gt; component under &lt;code&gt;src/components&lt;/code&gt;:&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;template&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;ul&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;li&lt;/span&gt; &lt;span class="na"&gt;v-for=&lt;/span&gt;&lt;span class="s"&gt;"message in messages"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt; {{ message }} &lt;span class="nt"&gt;&amp;lt;/li&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/ul&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;script&amp;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="p"&gt;{&lt;/span&gt; 
        &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;list&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
        &lt;span class="na"&gt;props&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;messages&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="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And update &lt;code&gt;App.vue&lt;/code&gt; to use it, as follows:&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;template&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;id=&lt;/span&gt;&lt;span class="s"&gt;"app"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
        &lt;span class="nt"&gt;&amp;lt;MessageList&lt;/span&gt; &lt;span class="na"&gt;messages=&lt;/span&gt;&lt;span class="s"&gt;"messages"&lt;/span&gt; &lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
    &lt;span class="nt"&gt;&amp;lt;/div&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/template&amp;gt;&lt;/span&gt;

&lt;span class="nt"&gt;&amp;lt;script&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;MessageList&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;./components/MessageList&lt;/span&gt;&lt;span class="dl"&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="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;app&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; 
    &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;({&lt;/span&gt;
        &lt;span class="na"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Hey John&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Howdy Paco&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="na"&gt;components&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;MessageList&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;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have already a couple of components that we can test. Let’s create a &lt;code&gt;test&lt;/code&gt; folder under the project root, and a &lt;code&gt;App.test.js&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;Vue&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&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;App&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;../src/App&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="nx"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;App.test.js&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;cmp&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;vm&lt;/span&gt;

  &lt;span class="nx"&gt;beforeEach&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;cmp&lt;/span&gt; &lt;span class="o"&gt;=&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;extend&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="c1"&gt;// Create a copy of the original component&lt;/span&gt;
    &lt;span class="nx"&gt;vm&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;cmp&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
      &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// Replace data value with this fake data&lt;/span&gt;
        &lt;span class="na"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Cat&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="p"&gt;}).&lt;/span&gt;&lt;span class="nx"&gt;$mount&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="c1"&gt;// Instances and mounts the component&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;

  &lt;span class="nx"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;equals messages to ["Cat"]&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;vm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toEqual&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Cat&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="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Right now, if we run &lt;code&gt;npm test&lt;/code&gt; (or &lt;code&gt;npm t&lt;/code&gt; as a shorthand version), the test should run and pass. Since we’re modifying the tests, let’s better run it in &lt;strong&gt;watch mode&lt;/strong&gt; :&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm t &lt;span class="nt"&gt;--&lt;/span&gt; &lt;span class="nt"&gt;--watch&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  The problem with nested components
&lt;/h3&gt;

&lt;p&gt;This test is too simple. Let’s check that the output is the expected as well. For that we can use the amazing Snapshots feature of Jest, that will generate a snapshot of the output and check it against in the upcoming runs. Add after the previous &lt;code&gt;it&lt;/code&gt; in &lt;code&gt;App.test.js&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;has the expected html structure&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;vm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;$el&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toMatchSnapshot&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;That will create a &lt;code&gt;test/ __snapshots__ /App.test.js.snap&lt;/code&gt; file. Let’s open it and inspect it:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Jest Snapshot v1, https://goo.gl/fbAQLP&lt;/span&gt;

&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;`App.test.js has the expected html structure 1`&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`
&amp;lt;div
  id="app"
&amp;gt;
  &amp;lt;ul&amp;gt;
    &amp;lt;li&amp;gt;
      Cat
    &amp;lt;/li&amp;gt;
  &amp;lt;/ul&amp;gt;
&amp;lt;/div&amp;gt;
`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In case you haven’t noticed, there is a big problem here: the &lt;code&gt;MessageList&lt;/code&gt; component has been rendered as well. &lt;strong&gt;Unit tests must be tested as an independent unit&lt;/strong&gt; , meaning that in &lt;code&gt;App.test.js&lt;/code&gt; we wanna test &lt;code&gt;App&lt;/code&gt; component and don’t care at all about anything else.&lt;/p&gt;

&lt;p&gt;This can be the reason of several problems. Imagine for example, that the children components (&lt;code&gt;MessageList&lt;/code&gt; in this case) perform side effect operations on the &lt;code&gt;created&lt;/code&gt; hook, such as calling &lt;code&gt;fetch&lt;/code&gt;, a Vuex action or state changes? That’s something we definitely don’t want.&lt;/p&gt;

&lt;p&gt;Luckily, &lt;strong&gt;Shallow Rendering&lt;/strong&gt; solves this nicely.&lt;/p&gt;

&lt;h3&gt;
  
  
  What is Shallow Rendering?
&lt;/h3&gt;

&lt;p&gt;&lt;a href="http://airbnb.io/enzyme/docs/api/shallow.html"&gt;Shallow Rendering&lt;/a&gt; is a technique that assures your component is rendering without children. This is useful for:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Testing only the component you want to test (that’s what Unit Test stands for)&lt;/li&gt;
&lt;li&gt;Avoid side effects that children components can have, such as making HTTP calls, calling store actions…&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Testing a Component with vue-test-utils
&lt;/h2&gt;

&lt;p&gt;&lt;code&gt;vue-test-utils&lt;/code&gt; provide us with Shallow Rendering among other features. We could rewrite the previous test as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;shallow&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-test-utils&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;App&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;../src/App&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="nx"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;App.test.js&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;cmp&lt;/span&gt;

  &lt;span class="nx"&gt;beforeEach&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;cmp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;shallow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;App&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="c1"&gt;// Create a shallow instance of the component&lt;/span&gt;
      &lt;span class="na"&gt;data&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Cat&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="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;

  &lt;span class="nx"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;equals messages to ["Cat"]&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="c1"&gt;// Within cmp.vm, we can access all Vue instance methods&lt;/span&gt;
    &lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cmp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;vm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toEqual&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Cat&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="nx"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;has the expected html structure&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cmp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toMatchSnapshot&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And now, if you’re still running Jest in watching mode, you’ll see the test still pass, but the Snapshot doesn’t match. Press &lt;code&gt;u&lt;/code&gt; to regenerate it. Open and inspect it again:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Jest Snapshot v1, https://goo.gl/fbAQLP&lt;/span&gt;

&lt;span class="nx"&gt;exports&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;`App.test.js has the expected html structure 1`&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`
&amp;lt;div
  id="app"
&amp;gt;
  &amp;lt;!--  --&amp;gt;
&amp;lt;/div&amp;gt;
`&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You see? Now no children have been rendered and we tested the &lt;code&gt;App&lt;/code&gt; component &lt;strong&gt;fully isolated&lt;/strong&gt; from the component tree. Also, if you have any &lt;code&gt;created&lt;/code&gt; or whatever hooks in the children components, they haven’t been called either 😉.&lt;/p&gt;

&lt;p&gt;If you’re curious about &lt;strong&gt;how shallow render is implemented&lt;/strong&gt; , check out the &lt;a href="https://github.com/vuejs/vue-test-utils/blob/master/src/lib/stub-components.js"&gt;source code&lt;/a&gt; and you’ll see that basically is stubbing the &lt;code&gt;components&lt;/code&gt; key, the &lt;code&gt;render&lt;/code&gt; method and the lifecycle hooks.&lt;/p&gt;

&lt;p&gt;In the same vein, you can implement the &lt;code&gt;MessageList.test.js&lt;/code&gt; test as follows:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="nx"&gt;shallow&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-test-utils&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;MessageList&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;../src/components/MessageList&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="nx"&gt;describe&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;MessageList.test.js&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;let&lt;/span&gt; &lt;span class="nx"&gt;cmp&lt;/span&gt;

  &lt;span class="nx"&gt;beforeEach&lt;/span&gt;&lt;span class="p"&gt;(()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;cmp&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;shallow&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;MessageList&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="c1"&gt;// Beaware that props is overriden using `propsData`&lt;/span&gt;
      &lt;span class="na"&gt;propsData&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
        &lt;span class="na"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Cat&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="p"&gt;})&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;

  &lt;span class="nx"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;has received ["Cat"] as the message property&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cmp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;vm&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;messages&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toEqual&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Cat&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="nx"&gt;it&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;has the expected html structure&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nx"&gt;expect&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;cmp&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;element&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;toMatchSnapshot&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
  &lt;span class="p"&gt;})&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Find the &lt;a href="https://github.com/alexjoverm/vue-testing-series/tree/lesson-1"&gt;full example on Github&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="http://alexjoverm.github.io/2017/08/21/Write-the-first-Vue-js-Component-Unit-Test-in-Jest/"&gt;alexjoverm.github.io&lt;/a&gt; on August 21, 2017&lt;/em&gt;&lt;/p&gt;

</description>
      <category>vue</category>
      <category>javascript</category>
      <category>testing</category>
    </item>
    <item>
      <title>How I made a Progressive Web App out of my Blog</title>
      <dc:creator>Alex Jover</dc:creator>
      <pubDate>Mon, 14 Aug 2017 15:50:15 +0000</pubDate>
      <link>https://forem.com/alexjoverm/how-i-made-a-progressive-web-app-out-of-my-blog</link>
      <guid>https://forem.com/alexjoverm/how-i-made-a-progressive-web-app-out-of-my-blog</guid>
      <description>&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://alexjoverm.github.io/2017/08/07/How-I-made-a-Progressive-Web-App-out-of-my-Blog/?utm_source=devto" rel="noopener noreferrer"&gt;alexjoverm.github.io&lt;/a&gt; on August 7, 2017.&lt;/em&gt;&lt;/p&gt;

&lt;p&gt;One day I wanted to learn about PWA (Progressive Web App), so I though: What's better than doing it with my own blog?&lt;/p&gt;

&lt;p&gt;I think that's something developers do: when we wanna learn something, we go and get our hands dirty, right?&lt;/p&gt;

&lt;p&gt;The first thing I wanted was to get &lt;strong&gt;metrics and insights&lt;/strong&gt; on the blog at that point. For that I used &lt;a href="https://github.com/GoogleChrome/lighthouse" rel="noopener noreferrer"&gt;Lighthouse&lt;/a&gt; in its Chrome extension version.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fdfedz5ukvxi18l7bvfj2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fdfedz5ukvxi18l7bvfj2.png" alt="PWA metrics before"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;By default, the performance stats were quite good. I wasn't surprised: my blog runs on &lt;a href="https://hexo.io/" rel="noopener noreferrer"&gt;Hexo&lt;/a&gt;, a NodeJS static site generator which I'm in love with due to its blazing speed, easiness of deployment, and familiarity with NodeJS and its ecosystem.&lt;/p&gt;

&lt;p&gt;For the PWA metrics, it was half-way, and I've never payed attention to that. Let's see what steps I did to make it 100% a Progressive Web App.&lt;/p&gt;

&lt;h2&gt;
  
  
  1. Create a Web App Manifest and Icons
&lt;/h2&gt;

&lt;p&gt;The &lt;a href="https://developer.mozilla.org/en-US/docs/Web/Manifest" rel="noopener noreferrer"&gt;Web App Manifest&lt;/a&gt; is a JSON file designed to describe a Web Application. This is a excerpt of my &lt;a href="https://github.com/alexjoverm/blog/blob/master/themes/beautiful-hexo/source/manifest.json" rel="noopener noreferrer"&gt;&lt;code&gt;manifest.json&lt;/code&gt;&lt;/a&gt;:&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;"name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Alex Jover Blog"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"short_name"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"AlexJ Blog"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"theme_color"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"#008aff"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"background_color"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"#ffffff"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"display"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"standalone"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"icons"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"src"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"images/icons/icon-72x72.png"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"sizes"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"72x72"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"image/png"&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;},&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="err"&gt;...&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I think the names are pretty descriptive by themselves. Make sure at least you add the &lt;code&gt;name&lt;/code&gt;, &lt;code&gt;short_name&lt;/code&gt; and &lt;code&gt;icons&lt;/code&gt; fields.&lt;/p&gt;

&lt;p&gt;Some other fields you may be interested in, are &lt;a href="https://developer.mozilla.org/es/docs/Web/Manifest#start_urlhttps://developer.mozilla.org/es/docs/Web/Manifest#start_url" rel="noopener noreferrer"&gt;&lt;code&gt;start_url&lt;/code&gt;&lt;/a&gt; and &lt;a href="https://developer.mozilla.org/es/docs/Web/Manifest#scope" rel="noopener noreferrer"&gt;&lt;code&gt;scope&lt;/code&gt;&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;As per the &lt;strong&gt;icons&lt;/strong&gt;, you need to generate them in several sizes. For that I've used &lt;a href="https://app-manifest.firebaseapp.com/" rel="noopener noreferrer"&gt;this Web App Manifest generator&lt;/a&gt;, which also helps you creating the &lt;code&gt;manifest.json&lt;/code&gt; file. I've downloaded the zip file from that web, unzipped it and moved the files to where they belong. Then updated the &lt;code&gt;src&lt;/code&gt; property of the &lt;code&gt;icons&lt;/code&gt; array as needed.&lt;/p&gt;

&lt;p&gt;Finally, you must include it with a &lt;code&gt;meta&lt;/code&gt; tag in the &lt;a href="https://github.com/alexjoverm/blog/blob/master/themes/beautiful-hexo/layout/partial/head.jade" rel="noopener noreferrer"&gt;head of the HTML&lt;/a&gt; (you'll see my examples are in Jade/Pug, but I'll write it here in pure HTML):&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;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"manifest"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/manifest.json"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  2. Add meta tags
&lt;/h2&gt;

&lt;p&gt;You need to add &lt;a href="https://developers.google.com/web/fundamentals/design-and-ui/browser-customization/" rel="noopener noreferrer"&gt;some meta tags&lt;/a&gt; so all supported browsers would appropriately understand it as a Progressive Web App. The &lt;a href="https://github.com/alexjoverm/blog/blob/master/themes/beautiful-hexo/layout/partial/head.jade#L13-L23" rel="noopener noreferrer"&gt;tags I added&lt;/a&gt; are:&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;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"icon"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/images/icons/icon-152x152.png"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
&lt;span class="c"&gt;&amp;lt;!-- theme-color defines the top bar color (blue in my case)--&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"theme-color"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"#008aff"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;&amp;lt;!-- Add to home screen for Safari on iOS--&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"apple-mobile-web-app-capable"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"yes"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"apple-mobile-web-app-status-bar-style"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"default"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"apple-mobile-web-app-title"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"Alex Jover Blog"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;link&lt;/span&gt; &lt;span class="na"&gt;rel=&lt;/span&gt;&lt;span class="s"&gt;"apple-touch-icon"&lt;/span&gt; &lt;span class="na"&gt;href=&lt;/span&gt;&lt;span class="s"&gt;"/images/icons/icon-152x152.png"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;

&lt;span class="c"&gt;&amp;lt;!-- Add to home screen for Windows--&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"msapplication-TileImage"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"/images/icons/icon-152x152.png"&lt;/span&gt;&lt;span class="nt"&gt;/&amp;gt;&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;meta&lt;/span&gt; &lt;span class="na"&gt;name=&lt;/span&gt;&lt;span class="s"&gt;"msapplication-TileColor"&lt;/span&gt; &lt;span class="na"&gt;content=&lt;/span&gt;&lt;span class="s"&gt;"#000000"&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;As you can see, some platforms have their own meta tags.&lt;/p&gt;

&lt;h2&gt;
  
  
  3. Create a Pre-cache Service Worker
&lt;/h2&gt;

&lt;p&gt;Creating a &lt;a href="https://developers.google.com/web/fundamentals/getting-started/primers/service-workers" rel="noopener noreferrer"&gt;Service Worker&lt;/a&gt; could be a very tedious job, they're very versatile and allow to do a lot of things.&lt;/p&gt;

&lt;p&gt;For most cases, we wanna use them to cache all the static files, so our app can work offline. There are different strategies to do this, they all are explained very well in the &lt;a href="https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/" rel="noopener noreferrer"&gt;Offline Cookbook&lt;/a&gt;, written by &lt;a href="https://twitter.com/jaffathecake" rel="noopener noreferrer"&gt;Jake Archibald&lt;/a&gt; at Google. Another resource worth checking is &lt;a href="https://serviceworke.rs/" rel="noopener noreferrer"&gt;serviceworke.rs&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Still, it's quite some work to create and maintain a Service Worker for this purpose and every project. That's where &lt;a href="https://github.com/GoogleChrome/sw-precache" rel="noopener noreferrer"&gt;sw-precache&lt;/a&gt; comes in handy, a tool that automatically creates a pre-cache Service Worker for a set of static assets using the &lt;a href="https://developers.google.com/web/fundamentals/instant-and-offline/offline-cookbook/#cache-falling-back-to-network" rel="noopener noreferrer"&gt;cache-first&lt;/a&gt; strategy.&lt;/p&gt;

&lt;p&gt;If you're using Webpack in your project, you're lucky to have a &lt;a href="https://github.com/goldhand/sw-precache-webpack-plugin" rel="noopener noreferrer"&gt;sw-precache plugin&lt;/a&gt; that you can plug in your conf to create a Service Worker for your bundled assets automatically.&lt;/p&gt;

&lt;p&gt;In my case, I'm not using webpack, gulp or anything. Just a modified version of &lt;a href="https://github.com/twoyao/beautiful-hexo" rel="noopener noreferrer"&gt;Beautiful Hexo&lt;/a&gt; theme with plain css, js and images.&lt;/p&gt;

&lt;p&gt;But that's no problem. You can use &lt;strong&gt;sw-precache command line utility&lt;/strong&gt;. For that, I created first a &lt;a href="https://github.com/alexjoverm/blog/blob/master/sw-config.js" rel="noopener noreferrer"&gt;sw-config.js&lt;/a&gt; file, indicating the assets to cache and the prefix to strip out, since the service worker will be under the public folder as well:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;staticFileGlobs&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;public/css/**.css&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;public/**/**.html&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;public/**/**.jpg&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;public/**/**.png&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;public/js/**.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
  &lt;span class="p"&gt;],&lt;/span&gt;
  &lt;span class="na"&gt;stripPrefix&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;public&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;Then simply running &lt;code&gt;sw-precache --config sw-config.js&lt;/code&gt;, it creates a &lt;a href="https://github.com/alexjoverm/blog/blob/master/service-worker.js" rel="noopener noreferrer"&gt;service-worker.js&lt;/a&gt; file ready to use.&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: keep in mind Service Workers run only in localhost or in a HTTPS url&lt;/em&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  4. Register the Service Worker
&lt;/h2&gt;

&lt;p&gt;Once created a &lt;code&gt;service-worker.js&lt;/code&gt; file, you need to register it in your app. For that, I used a &lt;a href="https://github.com/GoogleChrome/sw-precache/blob/master/demo/app/js/service-worker-registration.js" rel="noopener noreferrer"&gt;battle tested service-worker-registration.js file&lt;/a&gt; located on the sw-precache repo.&lt;/p&gt;

&lt;p&gt;Then I simply copied it &lt;a href="https://github.com/alexjoverm/blog/blob/master/themes/beautiful-hexo/source/js/sw-register.js" rel="noopener noreferrer"&gt;to my repo&lt;/a&gt; where the js files of the theme are.&lt;/p&gt;

&lt;h2&gt;
  
  
  5. Glue all together
&lt;/h2&gt;

&lt;p&gt;So far I've got needed for building an offline ready and installable Progressive Web App:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Having a &lt;code&gt;manifest.json&lt;/code&gt; with icons&lt;/li&gt;
&lt;li&gt;Adding &lt;code&gt;meta&lt;/code&gt; tags&lt;/li&gt;
&lt;li&gt;Create a Service Worker for pre-caching&lt;/li&gt;
&lt;li&gt;Run in on HTTPS (I'm using Github Pages)&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Then only thing is, every time I post or change anything from the theme, I must re-create the precache service worker file, which is a bit repetitive.&lt;/p&gt;

&lt;p&gt;That's why I wrote a extremely &lt;a href="https://github.com/alexjoverm/blog/blob/master/deploy.sh" rel="noopener noreferrer"&gt;simple script&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;hexo generate &lt;span class="nt"&gt;-f&lt;/span&gt; &lt;span class="c"&gt;# re-generates the static assets&lt;/span&gt;
sw-precache &lt;span class="nt"&gt;--config&lt;/span&gt; sw-config.js &lt;span class="c"&gt;# creates the service worker&lt;/span&gt;
&lt;span class="nb"&gt;cp &lt;/span&gt;service-worker.js public &lt;span class="c"&gt;# copies it to the static site folder&lt;/span&gt;
hexo deploy &lt;span class="c"&gt;# deploys it to github pages&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;So as before I only needed to do &lt;code&gt;hexo deploy -g&lt;/code&gt;, which generates the &lt;code&gt;public&lt;/code&gt; folder and deploys it, now I had to add 2 steps in between for the service worker creation, and using this script it's very comfortable to do.&lt;/p&gt;

&lt;h2&gt;
  
  
  Checking out
&lt;/h2&gt;

&lt;p&gt;Running again a Lighthouse audit, I saw that was all to get the 100 PWA metrics, plus some extra performance and accessibility improvements I made:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fwtbxpbrwkhjfn22a2w0u.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fwtbxpbrwkhjfn22a2w0u.png" alt="PWA metrics after"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When I opened from my Android phone on Chrome, I saw the &lt;em&gt;"Add to Home"&lt;/em&gt; banner, which made me very happy to see my Blog being &lt;strong&gt;installable such a native app&lt;/strong&gt;:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fsi4odlya1s8l9k7348xc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fsi4odlya1s8l9k7348xc.png" alt="PWA metrics after"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And best of all, the blog is &lt;strong&gt;fully working offline&lt;/strong&gt;, so go try out turning off your internet connection and see the magic of a working Progressive Web App :)&lt;/p&gt;

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

&lt;p&gt;It's amazing to learn new stuff, specially such early technologies as Progressive Web Apps, but is even better to learn it by applying it to a real project of yourself!&lt;/p&gt;

</description>
      <category>pwa</category>
      <category>javascript</category>
    </item>
    <item>
      <title>Lazy loading in Vue using Webpack's code splitting</title>
      <dc:creator>Alex Jover</dc:creator>
      <pubDate>Wed, 19 Jul 2017 09:19:37 +0000</pubDate>
      <link>https://forem.com/alexjoverm/lazy-loading-in-vue-using-webpacks-code-splitting</link>
      <guid>https://forem.com/alexjoverm/lazy-loading-in-vue-using-webpacks-code-splitting</guid>
      <description>&lt;p&gt;When a &lt;a href="https://vuejs.org/"&gt;Vue&lt;/a&gt; app gets large, lazy loading components, routes or &lt;a href="https://vuex.vuejs.org/en"&gt;Vuex&lt;/a&gt; modules using &lt;a href="https://webpack.js.org/guides/lazy-loading/"&gt;Webpack's code splitting&lt;/a&gt; will boost it by loading pieces of code only when needed.&lt;/p&gt;

&lt;p&gt;We could apply lazy loading and code splitting in 3 different levels in a Vue app:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Components, also known as &lt;a href="https://vuejs.org/v2/guide/components.html#Async-Components"&gt;async components&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Router&lt;/li&gt;
&lt;li&gt;Vuex modules&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;But there is something they all have in common: they use &lt;a href="https://github.com/tc39/proposal-dynamic-import"&gt;dynamic import&lt;/a&gt;, which is understood by Webpack since version 2.&lt;/p&gt;

&lt;h2&gt;
  
  
  Lazy load in Vue components
&lt;/h2&gt;

&lt;p&gt;This is well explained in the &lt;a href="https://egghead.io/lessons/load-components-when-needed-with-vue-async-components"&gt;"Load components when needed with Vue async components"&lt;/a&gt; on Egghead.&lt;/p&gt;

&lt;p&gt;It's as simple as using the &lt;code&gt;import&lt;/code&gt; function when registering a component:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;Vue&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="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;AsyncCmp&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./AsyncCmp&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And using local registration:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="c1"&gt;// ...&lt;/span&gt;
  &lt;span class="na"&gt;components&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;AsyncCmp&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="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./AsyncCmp&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="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;By wrapping the &lt;code&gt;import&lt;/code&gt; function into an arrow function, Vue will execute it only when it gets requested, loading the module in that moment.&lt;/p&gt;

&lt;p&gt;If the component importing is using a &lt;a href="http://2ality.com/2014/09/es6-modules-final.html#named-exports-several-per-module"&gt;named export&lt;/a&gt;, you can use object destructuring on the returned Promise. For example, for the UiAlert component from &lt;a href="https://github.com/JosephusPaye/Keen-UI"&gt;KeenUI&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="nx"&gt;components&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;UiAlert&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;keen-ui&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(({&lt;/span&gt; &lt;span class="nx"&gt;UiAlert&lt;/span&gt; &lt;span class="p"&gt;})&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="nx"&gt;UiAlert&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Lazy load in Vue router
&lt;/h2&gt;

&lt;p&gt;Vue router has built in support for &lt;a href="https://router.vuejs.org/en/advanced/lazy-loading.html"&gt;lazy loading&lt;/a&gt;. It's as simple as importing your components with the &lt;code&gt;import&lt;/code&gt; function. Say we wanna lazy load a Login component in the &lt;em&gt;/login&lt;/em&gt; route:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Instead of: import Login from './login'&lt;/span&gt;
&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;Login&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="o"&gt;=&amp;gt;&lt;/span&gt; &lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./login&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;new&lt;/span&gt; &lt;span class="nx"&gt;VueRouter&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
  &lt;span class="na"&gt;routes&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="na"&gt;path&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;/login&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="na"&gt;component&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;Login&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
  &lt;span class="p"&gt;]&lt;/span&gt;
&lt;span class="p"&gt;})&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h2&gt;
  
  
  Lazy load a Vuex module
&lt;/h2&gt;

&lt;p&gt;Vuex has a &lt;code&gt;registerModule&lt;/code&gt; method that allow us to dynamically create Vuex modules. If we take into account that &lt;code&gt;import&lt;/code&gt; function returns a promise with the ES Module as the payload, we could use it to lazy load a module:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;store&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;Vuex&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;Store&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

&lt;span class="p"&gt;...&lt;/span&gt;

&lt;span class="c1"&gt;// Assume there is a "login" module we wanna load&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./store/login&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;).&lt;/span&gt;&lt;span class="nx"&gt;then&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;loginModule&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;store&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;registerModule&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;login&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;loginModule&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;h2&gt;
  
  
  Conclusion
&lt;/h2&gt;

&lt;p&gt;Lazy loading is made extremely simple with Vue and Webpack. Using what you've just read you can start splitting up your app in chunks from different sides and load them when needed, lightening the initial load of the app.&lt;/p&gt;

&lt;p&gt;If you like it, please go and share it! You can follow me on this blog or on twitter as &lt;a href="https://twitter.com/alexjoverm"&gt;@alexjoverm&lt;/a&gt;. Any questions? Shoot!&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally published at &lt;a href="https://alexjoverm.github.io/2017/07/16/Lazy-load-in-Vue-using-Webpack-s-code-splitting?utm_source=devto"&gt;alexjoverm.github.io&lt;/a&gt; on July 7, 2017.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>webpack</category>
      <category>vue</category>
    </item>
    <item>
      <title>Integrate TypeScript in your Vue project</title>
      <dc:creator>Alex Jover</dc:creator>
      <pubDate>Mon, 03 Jul 2017 08:37:09 +0000</pubDate>
      <link>https://forem.com/alexjoverm/integrate-typescript-in-your-vue-project</link>
      <guid>https://forem.com/alexjoverm/integrate-typescript-in-your-vue-project</guid>
      <description>&lt;p&gt;You have a &lt;a href="https://vuejs.org/"&gt;Vue&lt;/a&gt; project and you heard about all things &lt;a href="https://www.typescriptlang.org/"&gt;TypeScript&lt;/a&gt; can help you with. You decide to start using TypeScript. Here you'll see how to do that in an approachable and pragmatic way.&lt;/p&gt;

&lt;p&gt;In this article we'll assume you're using SFC (Single File Components), but it could work as well even if you're splitting them into multiple files. So... let's get started!&lt;/p&gt;

&lt;h2&gt;
  
  
  Integrating TypeScript
&lt;/h2&gt;

&lt;p&gt;We're gonna start from &lt;a href="https://github.com/vuejs-templates/webpack"&gt;Vue CLI Webpack's template&lt;/a&gt;, but it would work as well with the amazing &lt;a href="https://github.com/vuejs-templates/pwa"&gt;PWA template&lt;/a&gt;. Don't choose to use ESLint when you're ask to:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;vue init webpack my-app &lt;span class="c"&gt;# or: vue init pwa my-app&lt;/span&gt;
&lt;span class="nb"&gt;cd &lt;/span&gt;my-app
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We have to do 4 steps:&lt;/p&gt;

&lt;h3&gt;
  
  
  1. Create a &lt;code&gt;tsconfig.json&lt;/code&gt; file
&lt;/h3&gt;

&lt;p&gt;Let's start with something very simple, later we'll get back to the TypeScript configuration.&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;"compilerOptions"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"lib"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"dom"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"es5"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"es2015"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"target"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"es5"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"module"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"es2015"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"moduleResolution"&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"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"sourceMap"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;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;"allowSyntheticDefaultImports"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="kc"&gt;true&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The most important part is the &lt;code&gt;allowSyntheticDefaultImports&lt;/code&gt; setting. Since Vue types doesn't use ES2015 default exports, this setting must be set to by-pass that. You can see more info in &lt;a href="https://code.visualstudio.com/docs/languages/javascript#_common-questions"&gt;this VSCode docs page&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Setting &lt;code&gt;"module": "es2015"&lt;/code&gt; would make the code &lt;a href="https://alexjoverm.github.io/2017/03/06/Tree-shaking-with-Webpack-2-TypeScript-and-Babel/"&gt;tree-shakeable&lt;/a&gt; by producing ESM (EcmaScript Modules).&lt;/p&gt;

&lt;h3&gt;
  
  
  2. Add &lt;code&gt;ts-loader&lt;/code&gt; and webpack tweaks
&lt;/h3&gt;

&lt;p&gt;Install &lt;code&gt;typescript&lt;/code&gt; an &lt;code&gt;ts-loader&lt;/code&gt; with npm:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i &lt;span class="nt"&gt;-D&lt;/span&gt; typescript ts-loader
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then open &lt;code&gt;build/webpack.base.conf.js&lt;/code&gt;, and place the following code at &lt;strong&gt;the beginning&lt;/strong&gt; of &lt;code&gt;module.rules&lt;/code&gt;, right before than &lt;code&gt;vue-loader&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;rules&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="na"&gt;test&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="sr"&gt;ts$/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;exclude&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sr"&gt;/node_modules|vue&lt;/span&gt;&lt;span class="se"&gt;\/&lt;/span&gt;&lt;span class="sr"&gt;src/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;loader&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;ts-loader&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="na"&gt;options&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
          &lt;span class="na"&gt;appendTsSuffixTo&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sr"&gt;/&lt;/span&gt;&lt;span class="se"&gt;\.&lt;/span&gt;&lt;span class="sr"&gt;vue$/&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="p"&gt;...&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;In there, rename the entry to &lt;code&gt;.ts&lt;/code&gt; and add it to the extensions:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="p"&gt;...&lt;/span&gt;
&lt;span class="nx"&gt;entry&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;app&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./src/main.ts&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="nx"&gt;resolve&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;extensions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.ts&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.js&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;.json&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;h3&gt;
  
  
  3. Add &lt;code&gt;es-module: true&lt;/code&gt; to &lt;code&gt;build/vue-loader.conf.js&lt;/code&gt;
&lt;/h3&gt;

&lt;p&gt;That will tell vue-loader to use ES instead of CJS (CommonJS) modules, as describe in &lt;a href="https://github.com/vuejs/vue-loader/blob/master/docs/en/options.md#esmodule"&gt;vue-loader docs&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;module&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;exports&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;loaders&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;utils&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cssLoaders&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;
    &lt;span class="na"&gt;sourceMap&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;isProduction&lt;/span&gt;
      &lt;span class="p"&gt;?&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;build&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;productionSourceMap&lt;/span&gt;
      &lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;config&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;dev&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;cssSourceMap&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;extract&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nx"&gt;isProduction&lt;/span&gt;
  &lt;span class="p"&gt;}),&lt;/span&gt;
  &lt;span class="na"&gt;esModule&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="kc"&gt;true&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  4. Use TypeScript in files
&lt;/h3&gt;

&lt;p&gt;So you must do 2 things here:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Rename &lt;code&gt;.js&lt;/code&gt; to &lt;code&gt;.ts&lt;/code&gt; extensions within the &lt;code&gt;src&lt;/code&gt; folder&lt;/li&gt;
&lt;li&gt;Use &lt;code&gt;lang="ts"&lt;/code&gt; on the &lt;code&gt;script&lt;/code&gt; tag of you Vue file. For example in &lt;code&gt;App.vue&lt;/code&gt;:
&lt;/li&gt;
&lt;/ul&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;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;export&lt;/span&gt; &lt;span class="k"&gt;default&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&gt;name&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;app&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;&amp;lt;/script&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h3&gt;
  
  
  Troubleshooting
&lt;/h3&gt;

&lt;p&gt;If your editor is yelling at the line &lt;code&gt;import App from './App'&lt;/code&gt; in &lt;code&gt;main.js&lt;/code&gt; file about not finding the App module, you can add a &lt;code&gt;vue-shim.d.ts&lt;/code&gt; file to your project with the following content:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kr"&gt;declare&lt;/span&gt; &lt;span class="kr"&gt;module&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;*.vue&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;Vue&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&lt;/span&gt;&lt;span class="dl"&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;Vue&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;I'm using VSCode 1.13.1 and not seeing it, but I've seen it before.&lt;/p&gt;

&lt;h2&gt;
  
  
  TSLint, Prettier... Goddess!
&lt;/h2&gt;

&lt;p&gt;I've recorded &lt;a href="https://egghead.io/lessons/typescript-use-prettier-with-tslint-without-conflicts-c39670eb"&gt;a 2 min video on Egghead&lt;/a&gt; where I explain how you can set up TSLint with Prettier without any conflicts. Go check it out!&lt;/p&gt;

&lt;h2&gt;
  
  
  Ok, I can use TypeScript... so now what's next?
&lt;/h2&gt;

&lt;p&gt;At this point, TypeScript could already point you out to some errors you haven't noticed before by using built-in and third-party types and gives you a better dev experience by using type inference, as explained in &lt;a href="https://slack.engineering/typescript-at-slack-a81307fa288d"&gt;TypeScript at Slack&lt;/a&gt;, an article telling how Slack moved their codebase to TypeScript.&lt;/p&gt;

&lt;p&gt;Still, you must add your own types by using interfaces, types, enums, classes and whatever you need. That way you'll add more type coverage that TypeScript will use to apply static typing, assuring type safety.&lt;/p&gt;

&lt;p&gt;Ideally, you'd use the TypeScript 2.3 &lt;code&gt;strict&lt;/code&gt; compiler option in your &lt;code&gt;tsconfig.json&lt;/code&gt; because it'll bring you the most type safety. &lt;a href="https://twitter.com/mariusschulz"&gt;Marius Schulz&lt;/a&gt; has a &lt;a href="https://blog.mariusschulz.com/2017/06/09/typescript-2-3-the-strict-compiler-option"&gt;well explained article&lt;/a&gt; about this. By TypeScript 2.3, the strict option is a group of 4 options, but in future releases it could add more:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;strictNullChecks&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;noImplicitAny&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;noImplicitThis&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;alwaysStrict&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;However, if you have a medium/large codebase, using strict option will make you spend really a huge effort and time solving all the type shortage.&lt;/p&gt;

&lt;p&gt;For that case, a good way to integrate TypeScript is to start with the most flexible configuration, and as you add more type coverage to your codebase, start to enable individually the flags mentioned above, till you get to the point that you can apply the &lt;code&gt;strict&lt;/code&gt; option, so you can approach it in a pragmatic way.&lt;/p&gt;

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

&lt;p&gt;TypeScript brings you type safety to your codebase from the very start, but the more types you define, the more easy to detect bugs and errors and to make the code maintainable. Vue from version 2 is shipped with typings, so we can make use of them. They become more powerful when you use OOP (Object Oriented Programming) in Vue, but will see that in another post.&lt;/p&gt;

&lt;p&gt;If you like it, please go and share it! You can follow me on this blog or on twitter as &lt;a href="https://twitter.com/alexjoverm"&gt;@alexjoverm&lt;/a&gt;. Any questions? Shoot!&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Originally posted at &lt;a href="https://alexjoverm.github.io/2017/06/28/Integrate-TypeScript-in-your-Vue-project?utm_source=devto"&gt;alexjoverm.github.io&lt;/a&gt; on June 28, 2017&lt;/em&gt;&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>vue</category>
    </item>
    <item>
      <title>Use Prettier with TSLint and relax</title>
      <dc:creator>Alex Jover</dc:creator>
      <pubDate>Tue, 13 Jun 2017 08:22:17 +0000</pubDate>
      <link>https://forem.com/alexjoverm/use-prettier-with-tslint-and-relax</link>
      <guid>https://forem.com/alexjoverm/use-prettier-with-tslint-and-relax</guid>
      <description>&lt;p&gt;&lt;strong&gt;&lt;em&gt;Wait, a video explaining "Use Prettier with TSLint"?&lt;/em&gt; Yes! Check it out on &lt;a href="https://egghead.io/lessons/typescript-use-prettier-with-tslint-without-conflicts-c39670eb" rel="noopener noreferrer"&gt;Egghead.io&lt;/a&gt;!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/prettier/prettier" rel="noopener noreferrer"&gt;Prettier&lt;/a&gt; support for &lt;a href="https://www.typescriptlang.org/" rel="noopener noreferrer"&gt;TypeScript&lt;/a&gt; just landed. Let's see how &lt;a href="https://github.com/alexjoverm/tslint-config-prettier" rel="noopener noreferrer"&gt;tslint-config-prettier&lt;/a&gt; helps to seamlessly combine it with &lt;a href="https://palantir.github.io/tslint/" rel="noopener noreferrer"&gt;TSLint&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;Recently, &lt;a href="https://twitter.com/Vjeux" rel="noopener noreferrer"&gt;@vjeux&lt;/a&gt;, one of the authors of Prettier, announced TypeScript support in the following tweet:&lt;/p&gt;

&lt;p&gt;&lt;iframe class="tweet-embed" id="tweet-870670634908475392-528" src="https://platform.twitter.com/embed/Tweet.html?id=870670634908475392"&gt;
&lt;/iframe&gt;

  // Detect dark theme
  var iframe = document.getElementById('tweet-870670634908475392-528');
  if (document.body.className.includes('dark-theme')) {
    iframe.src = "https://platform.twitter.com/embed/Tweet.html?id=870670634908475392&amp;amp;theme=dark"
  }



&lt;/p&gt;

&lt;p&gt;That's pretty amazing! I've just went and tried it out. I was so impressed by how magic the experience was that I've &lt;a href="https://twitter.com/alexjoverm/status/871765191721197568" rel="noopener noreferrer"&gt;completely removed TSLint&lt;/a&gt; from &lt;a href="https://github.com/alexjoverm/typescript-library-starter" rel="noopener noreferrer"&gt;TypeScript library starter&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem
&lt;/h2&gt;

&lt;p&gt;Prettier and TSLint collide, since they both take care of formatting. For the following code, TSLint will give us the error &lt;code&gt;[tslint] Multiple spaces found before '{'. (no-multi-spaces)&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;DummyClass&lt;/span&gt;      &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;food&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sandwitch&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But, when we run Prettier, the code is automatically formatted:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nc"&gt;DummyClass&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nx"&gt;food&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;sandwitch&lt;/span&gt;&lt;span class="dl"&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 makes the workflow pretty useless, since we're getting linting errors that Prettier will solve.&lt;/p&gt;

&lt;h2&gt;
  
  
  The solution
&lt;/h2&gt;

&lt;p&gt;It's very simple:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Let Prettier take care of code formatting, and TSLint of the rest&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That's why I've created &lt;a href="https://github.com/alexjoverm/tslint-config-prettier" rel="noopener noreferrer"&gt;tslint-config-prettier&lt;/a&gt;. It disables all TSLint formatting related rules, as well as for &lt;a href="https://github.com/palantir/tslint-react" rel="noopener noreferrer"&gt;tslint-react&lt;/a&gt; and &lt;a href="https://github.com/buzinas/tslint-eslint-rules" rel="noopener noreferrer"&gt;tslint-eslint-rules&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The installation is straightforward, once you setup &lt;a href="https://palantir.github.io/tslint/" rel="noopener noreferrer"&gt;TSLint&lt;/a&gt; and &lt;a href="https://github.com/prettier/prettier" rel="noopener noreferrer"&gt;Prettier&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npm i &lt;span class="nt"&gt;-D&lt;/span&gt; tslint-config-prettier
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add it to the end of your &lt;code&gt;tslint.json&lt;/code&gt; file:&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;"extends"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"tslint:latest"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="s2"&gt;"tslint-config-prettier"&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we can use Prettier and TSLint without any problem!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fficj7k1b9csyqkom91ct.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fficj7k1b9csyqkom91ct.gif"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I must thank &lt;a href="https://twitter.com/Vjeux/status/871796320792608768" rel="noopener noreferrer"&gt;@vjeux for pointing me out&lt;/a&gt; to this solution and &lt;a href="https://twitter.com/JBlaak" rel="noopener noreferrer"&gt;@JBlack&lt;/a&gt; for the time to &lt;a href="https://github.com/alexjoverm/tslint-config-prettier/pull/1" rel="noopener noreferrer"&gt;review tslint-config-prettier&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;If you liked it, please go and share it! You can follow me on this blog or on twitter as &lt;a href="https://twitter.com/alexjoverm" rel="noopener noreferrer"&gt;@alexjoverm&lt;/a&gt;. Any questions? Shoot!&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Originally published on &lt;a href="https://alexjoverm.github.io/2017/06/12/Use-Prettier-with-TSLint-and-be-happy?utm_source=devto" rel="noopener noreferrer"&gt;Alex Jover blog&lt;/a&gt;&lt;/em&gt;&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>prettier</category>
      <category>tslint</category>
    </item>
    <item>
      <title>Use Prettier with TSLint and be happy</title>
      <dc:creator>Alex Jover</dc:creator>
      <pubDate>Mon, 12 Jun 2017 14:36:23 +0000</pubDate>
      <link>https://forem.com/alexjoverm/use-prettier-with-tslint-and-be-happy-ec3</link>
      <guid>https://forem.com/alexjoverm/use-prettier-with-tslint-and-be-happy-ec3</guid>
      <description>&lt;p&gt;&lt;a href="https://github.com/prettier/prettier" rel="noopener noreferrer"&gt;Prettier&lt;/a&gt; support for &lt;a href="https://www.typescriptlang.org/" rel="noopener noreferrer"&gt;TypeScript&lt;/a&gt; just landed. Let’s see how &lt;a href="https://github.com/alexjoverm/tslint-config-prettier" rel="noopener noreferrer"&gt;tslint-config-prettier&lt;/a&gt; helps to seamlessly combine it with &lt;a href="https://palantir.github.io/tslint/" rel="noopener noreferrer"&gt;TSLint&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;&lt;em&gt;Wait, a video explaining “Use Prettier with TSLint”?&lt;/em&gt; Yes! Check it out on &lt;a href="https://egghead.io/lessons/typescript-use-prettier-with-tslint-without-conflicts-c39670eb" rel="noopener noreferrer"&gt;Egghead.io&lt;/a&gt;!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;Recently, &lt;a href="https://twitter.com/Vjeux" rel="noopener noreferrer"&gt;@vjeux&lt;/a&gt;, one of the authors of Prettier, announced TypeScript support in the following tweet:&lt;/p&gt;

&lt;blockquote&gt;

&lt;/blockquote&gt;

&lt;p&gt;That’s pretty amazing! I’ve just went and tried it out. I was so impressed by how magic the experience was that I’ve &lt;a href="https://twitter.com/alexjoverm/status/871765191721197568" rel="noopener noreferrer"&gt;completely removed TSLint&lt;/a&gt; from &lt;a href="https://github.com/alexjoverm/typescript-library-starter" rel="noopener noreferrer"&gt;TypeScript library starter&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  The problem
&lt;/h2&gt;

&lt;p&gt;Prettier and TSLint collide, since they both take care of formatting. For the following code, TSLint will give us the error &lt;code&gt;[tslint] Multiple spaces found before '{'. (no-multi-spaces)&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;class DummyClass { food = 'sandwitch'}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;But, when we run Prettier, the code is automatically formatted:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;class DummyClass { food = 'sandwitch'}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This makes the workflow pretty useless, since we’re getting linting errors that Prettier will solve.&lt;/p&gt;

&lt;h2&gt;
  
  
  The solution
&lt;/h2&gt;

&lt;p&gt;It’s very simple:&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;Let Prettier take care of code formatting, and TSLint of the rest&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;That’s why I’ve created &lt;a href="https://github.com/alexjoverm/tslint-config-prettier" rel="noopener noreferrer"&gt;tslint-config-prettier&lt;/a&gt;. It disables all TSLint formatting related rules, as well as for &lt;a href="https://github.com/palantir/tslint-react" rel="noopener noreferrer"&gt;tslint-react&lt;/a&gt; and &lt;a href="https://github.com/buzinas/tslint-eslint-rules" rel="noopener noreferrer"&gt;tslint-eslint-rules&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;The installation is straightforward, once you setup &lt;a href="https://palantir.github.io/tslint/" rel="noopener noreferrer"&gt;TSLint&lt;/a&gt; and &lt;a href="https://github.com/prettier/prettier" rel="noopener noreferrer"&gt;Prettier&lt;/a&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm i -D tslint-config-prettier
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Add it to the end of your &lt;code&gt;tslint.json&lt;/code&gt; file:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;{ "extends": ["tslint:latest", "tslint-config-prettier"]}
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now we can use Prettier and TSLint without any problem!&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Falexjoverm.github.io%2F%2F2017%2F06%2F12%2FUse-Prettier-with-TSLint-and-be-happy%2Fprettier.gif" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/http%3A%2F%2Falexjoverm.github.io%2F%2F2017%2F06%2F12%2FUse-Prettier-with-TSLint-and-be-happy%2Fprettier.gif" title="Using Prettier" alt="Using Prettier"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I must thank &lt;a href="https://twitter.com/Vjeux/status/871796320792608768" rel="noopener noreferrer"&gt;@vjeux for pointing me out&lt;/a&gt; to this solution and &lt;a href="https://twitter.com/JBlaak" rel="noopener noreferrer"&gt;@JBlack&lt;/a&gt; for the time to &lt;a href="https://github.com/alexjoverm/tslint-config-prettier/pull/1" rel="noopener noreferrer"&gt;review tslint-config-prettier&lt;/a&gt;.&lt;/p&gt;

</description>
      <category>typescript</category>
    </item>
    <item>
      <title>Write a library using TypeScript library starter</title>
      <dc:creator>Alex Jover</dc:creator>
      <pubDate>Sat, 01 Apr 2017 12:33:55 +0000</pubDate>
      <link>https://forem.com/alexjoverm/write-a-library-using-typescript-library-starter</link>
      <guid>https://forem.com/alexjoverm/write-a-library-using-typescript-library-starter</guid>
      <description>&lt;p&gt;&lt;em&gt;Explained in a &lt;a href="https://egghead.io/lessons/typescript-create-a-typescript-library-using-typescript-library-starter" rel="noopener noreferrer"&gt;video lesson on Egghead&lt;/a&gt;&lt;/em&gt; &lt;/p&gt;

&lt;p&gt;Have you ever written a library in JavaScript or TypeScript? Are you planning to do it? If so, you must try &lt;a href="https://github.com/alexjoverm/typescript-library-starter" rel="noopener noreferrer"&gt;Typescript library starter&lt;/a&gt;, a starter kit that will make easy to get started while providing all features you know to write a library in Typescript.&lt;/p&gt;

&lt;p&gt;Writing a library or project always requires some work:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Prepare configuration: package.json, tsconfig.json, CI, bundling, build, minification, types generation...&lt;/li&gt;
&lt;li&gt;Testing tools: Unit test (with watch mode), coverage...&lt;/li&gt;
&lt;li&gt;Release versions and changelog: This is a repetitive work that takes some time&lt;/li&gt;
&lt;li&gt;API Docs generation&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://github.com/alexjoverm/typescript-library-starter" rel="noopener noreferrer"&gt;Typescript library starter&lt;/a&gt; solves all of that and more, plus:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Uses latest tools: RollupJS (with &lt;a href="https://alexjoverm.github.io/2017/03/06/Tree-shaking-with-Webpack-2-TypeScript-and-Babel/" rel="noopener noreferrer"&gt;tree-shaking&lt;/a&gt;), Prettier, Jest, TSLint, Typedoc...&lt;/li&gt;
&lt;li&gt;Multiple bundle generation, as described in &lt;a href="http://2ality.com/2017/04/setting-up-multi-platform-packages.html" rel="noopener noreferrer"&gt;2ality&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Focused on automation: with a set of scripts you as a user have all the work done&lt;/li&gt;
&lt;li&gt;Allows automatic releases to Github and Npm by using and configuring Semantic Release&lt;/li&gt;
&lt;li&gt;Is already configured to work on Travis, Coveralls, generate types, and more!&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Let's see how easy is to use it.&lt;/p&gt;

&lt;h2&gt;
  
  
  Get started
&lt;/h2&gt;

&lt;p&gt;Let's start 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;git clone https://github.com/alexjoverm/typescript-library-starter.git
cd typescript-library-starter
npm install
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A prompt will show up asking your library name:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F3rylupedav8026le066s.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2F3rylupedav8026le066s.png" alt="Initial prompt"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;When you do so, it will configure the project for you based on the library name and your git config. It re-inits the git directory, configures rollup, package.json and your entry files (both src and test).&lt;/p&gt;

&lt;p&gt;See it yourself! Try running &lt;code&gt;npm t&lt;/code&gt;, it will run a sample test. Or run &lt;code&gt;npm run build&lt;/code&gt;, it will create a &lt;code&gt;dist&lt;/code&gt; folder with the bundle, typings file and documentation.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fl09lupzu2ep9ya9al1s7.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fl09lupzu2ep9ya9al1s7.png" alt="Dist folder"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;See all the &lt;a href="https://github.com/alexjoverm/typescript-library-starter#npm-scripts" rel="noopener noreferrer"&gt;commands available on the repo Readme&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now start coding. You'll see when you make a commit, your code is automatically formatted! That's thanks to Prettier :)&lt;/p&gt;

&lt;h2&gt;
  
  
  Automatic releases and Travis CI
&lt;/h2&gt;

&lt;p&gt;We need to do some previous steps. First, make sure you've created an account on:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;npm&lt;/li&gt;
&lt;li&gt;Travis&lt;/li&gt;
&lt;li&gt;Coveralls&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also, make sure you've set the &lt;code&gt;repository.url&lt;/code&gt; property on your &lt;code&gt;package.json&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Now, run the following script:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;node tools/semantic-release-prepare
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The script will setup 2 githooks: commitmsg and prepush. They're convenient, since &lt;a href="https://github.com/semantic-release/semantic-release" rel="noopener noreferrer"&gt;semantic release&lt;/a&gt; works by following &lt;a href="https://github.com/conventional-changelog/conventional-changelog" rel="noopener noreferrer"&gt;conventional commit messages&lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;At this point, you just need to install semantic release. &lt;strong&gt;Answer NO&lt;/strong&gt; to the "Generate travis.yml" question, because it is already prepared for you.&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 -g semantic-release-cli
semantic-release setup
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From now on, better use &lt;code&gt;npm run commit&lt;/code&gt;. It will show you a prompt which is very convenient for creating a conventional commit. Note that running &lt;code&gt;git commit -a&lt;/code&gt; without the proper commit message will fail.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fodilqrbecojf0hjaaqx2.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fthepracticaldev.s3.amazonaws.com%2Fi%2Fodilqrbecojf0hjaaqx2.png" alt="Conventional commit"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You'll notice that when you run &lt;code&gt;git push&lt;/code&gt;, the exactly same command that Travis CI runs is run locally on your machine, so you can see early if the build will fail.&lt;/p&gt;

&lt;h2&gt;
  
  
  Wrapping up
&lt;/h2&gt;

&lt;p&gt;We haven't dived into any kind of configuration, but we were able to not only write a dummy library, but also make sure all quality steps (linting, testing, coverage) are asserted and that we can create bundles, builds, typings and all things needed for a TypeScript library.&lt;/p&gt;

&lt;p&gt;Not only that, but also how to make maintainability easy by automating releases!&lt;/p&gt;

&lt;p&gt;If you liked &lt;a href="https://github.com/alexjoverm/typescript-library-starter" rel="noopener noreferrer"&gt;Typescript library starter&lt;/a&gt;, please give it a star. If you have any feedback, you can either open an issue or reach me at &lt;a href="https://twitter.com/alexjoverm" rel="noopener noreferrer"&gt;@alexjoverm&lt;/a&gt;&lt;/p&gt;

</description>
      <category>typescript</category>
      <category>rollupjs</category>
      <category>babel</category>
      <category>library</category>
    </item>
  </channel>
</rss>
