<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Mathieu Lavoie</title>
    <description>The latest articles on DEV Community by Mathieu Lavoie (@m4thieulavoie).</description>
    <link>https://dev.to/m4thieulavoie</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%2F366164%2F7e4d1415-3ba9-4ccf-a445-e06423b54239.jpeg</url>
      <title>DEV Community: Mathieu Lavoie</title>
      <link>https://dev.to/m4thieulavoie</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/m4thieulavoie"/>
    <language>en</language>
    <item>
      <title>Taking advantage of the quarantine as a developer</title>
      <dc:creator>Mathieu Lavoie</dc:creator>
      <pubDate>Mon, 24 Aug 2020 19:47:05 +0000</pubDate>
      <link>https://dev.to/m4thieulavoie/taking-advantage-of-the-quarantine-as-a-developer-5elk</link>
      <guid>https://dev.to/m4thieulavoie/taking-advantage-of-the-quarantine-as-a-developer-5elk</guid>
      <description>&lt;p&gt;Picture by &lt;a href="https://www.pexels.com/@ivan-samkov"&gt;Ivan Samkov&lt;/a&gt; on &lt;a href="https://www.pexels.com/photo/woman-with-face-mask-looking-at-a-laptop-4240606/"&gt;Pexels&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The current world situation is (hopefully) something we'll experience once in our lives. In a sense, for us developers, it is a unique opportunity to take advantage of all this free time to perfect our skills. If you did not do at least one of those items, you might have missed a great opportunity to take your career to the next level.&lt;/p&gt;

&lt;h1&gt;
  
  
  Update your portfolio
&lt;/h1&gt;

&lt;p&gt;Your portfolio is both where you describe yourself and your experience and you have an unique opportunity to showcase your skills and your creativity in this sandbox. The more unique the better.&lt;/p&gt;

&lt;h1&gt;
  
  
  Catch up on (new) technologies
&lt;/h1&gt;

&lt;p&gt;New packages and frameworks come out almost every day, it's pretty much impossible to keep up. However, now's a one of a kind chance for you to read and play with this fancy new tech you never got the chance to take a couple of hours with. Don't forget it doesn't have to be a &lt;em&gt;new&lt;/em&gt; technology. You can definitely catch up on anything that can help your day-to-day job. As an example, I am reading a lot on design systems and on Web Accessibility lately.&lt;/p&gt;

&lt;h1&gt;
  
  
  Think about your career path
&lt;/h1&gt;

&lt;p&gt;When we're on the 40h/week wave, we tend to put our career on cruise control and not think about it too much. What about sitting with a coffee and thinking about if you're where you wanted to be a year earlier. Even better, are you doing the right things to get where you aim career-wise? And where do you want to go in the first place? You should all write that down with a clear goal and some action items to achieve this. If you struggle with all of this, your manager certainly can help with that.&lt;/p&gt;

&lt;h1&gt;
  
  
  Find a side hustle
&lt;/h1&gt;

&lt;p&gt;Ever heard of passive income? As a developer, you are in the best position possible to build and publish some source of passive income over the internet. Don't get me wrong, it is super hard to get it to even pay back your servers (don't even think about your time your put in it). My point here is not to get rich, but more to get your hands dirty in a real project where you have to touch to every part of a complex project (design, front-end, back-end, ...). The journey is more important than the destination in that use case, and I found myself learning &lt;em&gt;way more&lt;/em&gt; doing that than any other project.&lt;/p&gt;

&lt;h1&gt;
  
  
  Contribute to an open-source project
&lt;/h1&gt;

&lt;p&gt;Chances are you are daily using an open-source library. Ever wonder how the heck they achieve [any problem it actually solves for you]? Well, why don't you take 5 minutes and dig in their code? Often times, you'll realize they have a very similar project structure to your own project, and that not this many code is involved. Or even better (at least I felt this way the first times I opened OSS code): you realize you can &lt;em&gt;understand their code&lt;/em&gt;. At some point, you'll even see things they could improve! What now? Why not simply opening a pull request on their repo!&lt;/p&gt;

&lt;p&gt;Whether that's to update your 4 years old portfolio, reading a ton of articles over the internet, writing what seems to be useless Codepens, or starting a new side-project, I hope you tried your best at taking advantage of the pandemic by improving your skills as a developer. Did I miss to cover something else in my list (I probably did.)? If so, write it down in the comments!&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>career</category>
    </item>
    <item>
      <title>How I managed to use SCSS inside Web Components</title>
      <dc:creator>Mathieu Lavoie</dc:creator>
      <pubDate>Fri, 01 May 2020 00:32:17 +0000</pubDate>
      <link>https://dev.to/m4thieulavoie/how-i-managed-to-use-scss-inside-web-components-3lk9</link>
      <guid>https://dev.to/m4thieulavoie/how-i-managed-to-use-scss-inside-web-components-3lk9</guid>
      <description>&lt;p&gt;A couple of years ago, I remember rushing to learn the fourth version of Angular to get up to speed with "moderns" web frameworks. About when I got okay-ish with it, we started writing more and more React at work, so I switched onto it. Then emerged Vue.js, svelte, and many others. Modern frameworks keep being easier to implement, to use, and being lighter. At some extend, the more they evolve, the closer they get to barebone Javascript. During this time, another concept is making its way quietly: Web Components. Why are we so reticent to start daily drive this nice technology? I asked myself the question, and tried it for a while. Let me walk through my road blocks, and how I managed to get over each one of them.&lt;/p&gt;

&lt;p&gt;For a while now, I have been reading quite a bit on Web Components and even though it's still at early stages (let's be honest), the potential of this concept truly is insane. Like any developer, I quickly dropped my in-progress project to play around with Web Components and realized how amazing they are. Soon enough I stumbled upon three deal breakers (or challenges, you pick!) before making Web Components my go-to technology:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;It's not supported by every browser&lt;/li&gt;
&lt;li&gt;I miss Typescript&lt;/li&gt;
&lt;li&gt;Reusing CSS is pretty much impossible in the Shadow DOM&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;So I started digging, and you might also probably know, but it is pretty trivial to make web components supported in every modern browsers with Polyfills, and adding Typescript to Web Components is very possible (my personal stack to transpile to CommonJS is &lt;code&gt;babel-loader&lt;/code&gt; inside webpack).&lt;/p&gt;

&lt;p&gt;The part I scratched my head a bit more is to reuse CSS to keep my code as DRY (Don't Repeat Yourself) as possible. Plus, working without SCSS would be too much of a bummer for me to move forward with Web Components. There had to be a way.&lt;/p&gt;

&lt;h2&gt;
  
  
  What exactly is the issue?
&lt;/h2&gt;

&lt;p&gt;We need a proper example here. When you create a Web Component with a Shadow Root, you can't just hook it with a &lt;code&gt;.scss&lt;/code&gt; file like in React or Angular. You need to pass the &lt;em&gt;actual&lt;/em&gt; plain boring CSS to a created &lt;code&gt;style&lt;/code&gt; element.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;CatViewer&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;HTMLElement&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;super&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;style&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;style&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`
      p {
        color: blue;
      }
    `&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;shadowRoot&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;attachShadow&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;open&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;paragraph&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;p&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;paragraph&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Here is some blue text.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nx"&gt;shadowRoot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;shadowRoot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;paragraph&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;&lt;strong&gt;Note that you can attach a stylesheet to a Shadow DOM, but that implies your stylesheet won't be bundled in your component. This is exactly why this solution does not work for me&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;So after hours of googling, I could not find much, except having something more less like CSS-in-JS, bleeding &lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties"&gt;CSS variables&lt;/a&gt;, or the deprecated &lt;a href="http://tabatkins.github.io/specs/css-apply-rule/"&gt;@apply rule&lt;/a&gt;. &lt;em&gt;There had to be a way&lt;/em&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Ever heard of shower thoughts?
&lt;/h2&gt;

&lt;p&gt;To be honest, I am not sure if I was about to give up, or ready to put this Web Component thing on the ice again, but I had a shower thought: &lt;code&gt;What if there was a way of compiling a SCSS file, and retrieve its result as a javascript string?&lt;/code&gt; Easy enough! To do so, a simple webpack loader could do the trick just fine.&lt;/p&gt;

&lt;p&gt;That's how I ended up creating my first webpack loader: &lt;a href="https://github.com/m4thieulavoie/sass-to-string"&gt;sass-to-string&lt;/a&gt; and started dogfooding it just to realize how convenient it was (for me at least) to use SCSS inside plain Web Components.&lt;/p&gt;

&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;

&lt;p&gt;First off, install the dependency&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;npm install sass-to-string --save-dev
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Then, all you need to do is add this webpack config&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;module&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&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;styles.scss$/&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/&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;sass-to-string&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;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;sass-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;sassOptions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="na"&gt;outputStyle&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;compressed&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="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="p"&gt;};&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;If you already had an existing &lt;code&gt;.scss&lt;/code&gt; config, you'll want to specify an &lt;code&gt;exclude&lt;/code&gt; statement in it&lt;br&gt;
&lt;/p&gt;

&lt;div class="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;module&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="na"&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="c1"&gt;// Your new shiny sass-to-string config&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;scss|css&lt;/span&gt;&lt;span class="se"&gt;)&lt;/span&gt;&lt;span class="sr"&gt;$/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
      &lt;span class="c1"&gt;// Excluding the `.styles.scss` extension&lt;/span&gt;
      &lt;span class="na"&gt;exclude&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;styles.scss$/&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="sr"&gt;/node_modules/&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;style-loader&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
        &lt;span class="nx"&gt;MiniCssExtractPlugin&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&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;css-loader&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;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;sass-loader&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="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 that's pretty much it!&lt;/p&gt;

&lt;p&gt;Once this is done, the usage is pretty simple : you create a &lt;code&gt;*.styles.scss&lt;/code&gt; file alongside your component (or wherever you want, who am I to judge?) and import it, like such&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;styles&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;./CatViewer.styles.scss&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 will give you a string containing the compiled CSS. Then, all you need to do is to inject it inside a style.&lt;/p&gt;

&lt;p&gt;Let's assume &lt;code&gt;CatViewer.styles.scss&lt;/code&gt; contains the following:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight scss"&gt;&lt;code&gt;&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

  &lt;span class="nt"&gt;span&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;pink&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;The variable &lt;code&gt;styles&lt;/code&gt; would end up with the following value:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;blue&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="p"&gt;}&lt;/span&gt;
&lt;span class="nt"&gt;p&lt;/span&gt; &lt;span class="nt"&gt;span&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="nl"&gt;color&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="no"&gt;pink&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;I know this is a stupid example, but you get the point! Let's take this into our component above.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight typescript"&gt;&lt;code&gt;&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="nx"&gt;styles&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;./CatViewer.styles.scss&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

&lt;span class="kd"&gt;class&lt;/span&gt; &lt;span class="nx"&gt;CatViewer&lt;/span&gt; &lt;span class="kd"&gt;extends&lt;/span&gt; &lt;span class="nx"&gt;HTMLElement&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
  &lt;span class="kd"&gt;constructor&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="k"&gt;super&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;style&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;style&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;textContent&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;styles&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;shadowRoot&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;this&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;attachShadow&lt;/span&gt;&lt;span class="p"&gt;({&lt;/span&gt;&lt;span class="na"&gt;mode&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;open&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;});&lt;/span&gt;
    &lt;span class="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;paragraph&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;createElement&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;p&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;paragraph&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;Here is some blue text with some &amp;lt;span&amp;gt;pink&amp;lt;/span&amp;gt;.&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;

    &lt;span class="nx"&gt;shadowRoot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;style&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
    &lt;span class="nx"&gt;shadowRoot&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;appendChild&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nx"&gt;paragraph&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 bam! We just took a shiny &lt;code&gt;.scss&lt;/code&gt; file, imported it as plain CSS in a Web Component class. If you did not notice already, since &lt;code&gt;sass-to-string&lt;/code&gt; relies on Webpack, it supports HMR (Hot Module Reload)!&lt;/p&gt;

&lt;p&gt;At the moment of writing those lines, I've been using this tool almost daily since about a month both at home and at work and it's been great so far. This simple loader added a lot more weight into the consideration of moving our future code into Web Components at work. Being able to re-use CSS in our components is a key for having a nice and clean CSS codebase. Not only that, but it also allows us to move away all the CSS code in a separate file, helping the separation of concepts at the same time.&lt;/p&gt;

&lt;p&gt;I really hope this article was helpful, or at least interesting. I spent many hours reading and messing around with Web Components and they are totally worth a shot. I know this article sounds like I'm trying to sell my package, but that's not it at all. I want to share my thought process on how I went from "Yeah impossible to do it" to "It's actually fairly easy to do!". We, developers, sometimes tend to forget our job is to create things from scratch, literally.&lt;/p&gt;




&lt;p&gt;Cover by &lt;a href="https://unsplash.com/@ryanquintal?utm_source=unsplash&amp;amp;utm_medium=referral&amp;amp;utm_content=creditCopyText"&gt;Ryan Quintal&lt;/a&gt; on Unsplash&lt;/p&gt;

</description>
      <category>showdev</category>
      <category>css</category>
      <category>webdev</category>
      <category>sass</category>
    </item>
  </channel>
</rss>
