<?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: mathumitha</title>
    <description>The latest articles on DEV Community by mathumitha (@mathumitha).</description>
    <link>https://dev.to/mathumitha</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%2F656484%2F0e237398-dd19-4859-a0f9-a4921467801c.jpeg</url>
      <title>DEV Community: mathumitha</title>
      <link>https://dev.to/mathumitha</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mathumitha"/>
    <language>en</language>
    <item>
      <title>Why do front end frameworks need node.js? Is not it server side?</title>
      <dc:creator>mathumitha</dc:creator>
      <pubDate>Fri, 07 Apr 2023 07:38:32 +0000</pubDate>
      <link>https://dev.to/mathumitha/why-do-front-end-frameworks-need-node-js-is-not-it-server-side-b1p</link>
      <guid>https://dev.to/mathumitha/why-do-front-end-frameworks-need-node-js-is-not-it-server-side-b1p</guid>
      <description>&lt;p&gt;Many of the developers who are just getting started with front end have questions like &lt;em&gt;“Is not Node.js backend framework?”&lt;/em&gt;, &lt;em&gt;“Why is it necessary to install Node.js for running my React application? Can’t I just link the CDN script and develop?”&lt;/em&gt;, &lt;em&gt;“Are node.js and Javascript same?”&lt;/em&gt;. Don’t worry! This article will give you better clarity about Node.js and its role in both front-end and back-end applications.&lt;/p&gt;

&lt;h2&gt;
  
  
  Are javascript and node.js the same?
&lt;/h2&gt;

&lt;p&gt;The answer is No. While Javascript is a programming language that can be used to create beautiful, interactive websites that run in a browser ecosystem, node.js is a server-side ecosystem built that allows the javascript to be run on the server-side.&lt;/p&gt;

&lt;h2&gt;
  
  
  Now, you may wonder what is the difference between running javascript in the browser and in the node.js run time?
&lt;/h2&gt;

&lt;p&gt;Both browser run time and node.js run time use javascript as a programming language. node.js is built using Chrome’s v8 javascript engine. In browser, you will have access to cookies, web apis, &lt;code&gt;document&lt;/code&gt; and &lt;code&gt;window&lt;/code&gt; objects which do not exist in node.js. However, node.js has access to file system and support module systems like CommonJs and ES. As Javscript keeps evolving, node.js quickly incorporates the latest updates and make them available in the ecosystem. But browsers are bit slow to upgrade. In node.js ecosystem, &lt;code&gt;import&lt;/code&gt; statements are supported out-of-the-box where as browser has limited support.&lt;/p&gt;

&lt;p&gt;Now that, we have understood how javascript is used in browser runtime and node.js run time. Let’s see how node.js is used in front-end.&lt;/p&gt;

&lt;p&gt;Let’s say you want to use react.js most of the tutorials ask you to install node and NPM unless you are explicitly searching to develop from cdn library. Why?? Let’s see..&lt;/p&gt;

&lt;p&gt;The role of Node.js in front-end frameworks and libraries:&lt;br&gt;
Even though Front-end frameworks can run seamlessly without relying node.js, in certain ways node.js plays a crucial role in improving the developer experience, optimising the overall architecture and providing a large-scale eco system to build the applications.&lt;/p&gt;

&lt;p&gt;Lets talk about a few examples here,&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Latest JavaScript features:&lt;/strong&gt; As mentioned earlier, javascript version supported by node.js is way advanced than browser. It is running Chrome’s v8 engine and stays up-to-date with all new javascript features. Developers can start leveraging the latest features like &lt;code&gt;import&lt;/code&gt; and reusable module systems. But, we can use transpilers to transform the javascript files to browser understandable formats.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;NPM — Node Package Manager&lt;/strong&gt; — It hosts wide range of both front end and backend javascript based packages running on the node.js run time. Unlike the traditional way in which we need to manually download the libraries to consume in the projects, npm provides a cool cli to install and manage packages.
Build tools such as webpack, Browserify, Gulp and Grunt which are written in node.js and designed to be used with npm. Developers can leverage this type of building and bundling tools in their applications. Before arrival of these tools in npm, the backend systems were taking care of building and bundling tasks.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Code quality tools&lt;/strong&gt; like Linters which help in identifying the issues related to syntax and even allow the developers to set the custom standards. These tools are built on top of node.js and can be leveraged in front-end applications.&lt;/li&gt;
&lt;li&gt;There are many css preprocessors such as &lt;strong&gt;Sass, Less&lt;/strong&gt; and packages like &lt;strong&gt;styled-component&lt;/strong&gt; are available in npm.
Testing — Frameworks like jest allows the developers to write unit tests which can help them capture the bug if code is modified in future.&lt;/li&gt;
&lt;li&gt;node.js also helps in &lt;strong&gt;hot reloading&lt;/strong&gt; with which, on every code save, the page would be refreshing automatically.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In summary, node.js is used in both front end and back end. In front-end, its mainly used for dependency management, building, testing and even server-side rendering. In backend, its used to build server side applcications and APIs. Overall, it provides a flexible platform with improved developer experience.&lt;/p&gt;

</description>
      <category>webdev</category>
      <category>javascript</category>
      <category>node</category>
      <category>react</category>
    </item>
    <item>
      <title>Shadow DOM simplified</title>
      <dc:creator>mathumitha</dc:creator>
      <pubDate>Sun, 26 Jun 2022 08:05:59 +0000</pubDate>
      <link>https://dev.to/mathumitha/demystifying-shadow-dom-2obk</link>
      <guid>https://dev.to/mathumitha/demystifying-shadow-dom-2obk</guid>
      <description>&lt;h3&gt;
  
  
  DOM
&lt;/h3&gt;

&lt;p&gt;Before we dive into shadow DOM, let's rewind what a DOM is. According to the definition, the DOM is a Programming Interface that allows the interaction with the structure, style, and content of a web page. The DOM parser parses the HTML/XML Document and creates a tree-like structure where each element in the tree is called a node. Likewise, the CSSOM parser parses the stylesheets/inline styles and creates a tree-like structure similar to DOM where-in each node contains the required style information. Finally, the outputs of DOM and CSSOM parsers are combined together, and the render tree is built which beautifully displays the content in the webpage.&lt;/p&gt;

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

&lt;p&gt;Shadow DOM is an *&lt;em&gt;encapsulated DOM *&lt;/em&gt; that is rendered separately from the main document. The script and styling present in the shadow DOM are private to the shadow DOM. This means that &lt;code&gt;document.querySelector()&lt;/code&gt; will not return the Shadow DOM elements. The styles added to the shadow DOM will not leak outside of the Shadow DOM and the outside styles will not leak inside the shadow DOM. Therefore, you can apply styles directly to the generic selectors, ids, and classes without worrying about the conflicts. Shadow DOM provides both DOM and Style encapsulation.&lt;/p&gt;

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

&lt;p&gt;A few frameworks such as React.js, Vue.js make use of Virtual DOM to optimize the performance. React.js creates a copy of the real DOM and saves it in the memory. This copied version is called Virtual DOM. React.js doesn't update the real DOM directly. It runs a diffing algorithm to find out the changes. Whenever the state changes, React.js compares Virtual DOM with its previous versions. If it finds any, it updates only those changes into the real DOM. This process is called Reconciliation. So, the virtual DOM is used for improving performance and the Shadow DOM is used for encapsulation. You can create virtual DOM and attach it to shadow DOM or vice versa.&lt;/p&gt;

&lt;h3&gt;
  
  
  Are Web components and shadow DOM the same?
&lt;/h3&gt;

&lt;p&gt;No. Shadow DOM is the technology used in Web components. &lt;a href="https://www.webcomponents.org/"&gt;Web components&lt;/a&gt; are developed on top of shadow DOM. They make use of encapsulation provided by shadow DOM. They provide the set of APIs using which we can create &lt;strong&gt;encapsulated, reusable, custom elements&lt;/strong&gt;. These components are framework agnostic that can be used across all javascript applications. &lt;/p&gt;

&lt;h3&gt;
  
  
  Difference between web components and components created by Vue.js, React, Angular
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;DOM encapsulation:&lt;/strong&gt;&lt;br&gt;
As I said earlier, the difference lies in the encapsulation part. Although the frameworks support component reusability, a component will still have access to elements in other components using query selector APIs (&lt;code&gt;document.querySelector()&lt;/code&gt;). In the case of Web components, each component is strongly encapsulated and can only be accessed within the shadow DOM. &lt;code&gt;document.querySelector()&lt;/code&gt; does not return the elements on other web components.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Style encapsulation:&lt;/strong&gt;&lt;br&gt;
The frameworks like Vue.js and React.js don't support style encapsulation natively.  For vue.js, &lt;code&gt;vue-loader&lt;/code&gt; supports &lt;code&gt;scoped&lt;/code&gt; attribute for style tags. Other frameworks make use of css modules, css-in-js libraries to handle style encapsulation. However,&lt;code&gt;Angular&lt;/code&gt; supports emulated style encapsulation. It provides an option called &lt;a href="https://angular.io/api/core/ViewEncapsulation"&gt;encapsulation&lt;/a&gt; in the component API.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;

&lt;h3&gt;
  
  
  Building blocks of shadow DOM
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;
&lt;strong&gt;Shadow host&lt;/strong&gt; - The shadow host is the same as the other child nodes attached to the real DOM. It can be div, span, or anything in this &lt;a href="https://dom.spec.whatwg.org/#dom-element-attachshadow"&gt;list&lt;/a&gt;. &lt;code&gt;&amp;lt;text-area&amp;gt;&lt;/code&gt;, &lt;code&gt;&amp;lt;input /&amp;gt;&lt;/code&gt; have their own shadow DOM built-in by the browser.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Shadow tree&lt;/strong&gt; - The DOM tree inside the shadow DOM&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Shadow root&lt;/strong&gt; - The root node of the Shadow tree&lt;/li&gt;
&lt;/ol&gt;

&lt;h4&gt;
  
  
  Shadow DOM looks like below,
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--mOsMeENw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fmkelyrlf885i5fqdzdo.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--mOsMeENw--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fmkelyrlf885i5fqdzdo.png" alt="shadow dom" width="880" height="748"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  HTML Structure
&lt;/h4&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--KVQSltKA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u3gg0c5pcl5qlrnkypyh.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--KVQSltKA--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/uploads/articles/u3gg0c5pcl5qlrnkypyh.png" alt="shadow dom tree" width="880" height="277"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Creating Shadow DOM
&lt;/h3&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;shadowHost&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;div&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;shadowRoot&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nx"&gt;shadowHost&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="nx"&gt;shadowHost&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;id&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;shadow-host&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;innerHTML&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="s2"&gt;`
&amp;lt;h1&amp;gt;Hi, there!/h1&amp;gt;
&amp;lt;style&amp;gt;
   h1 {
     color: green;
   }
&amp;lt;/style&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;Hence, any element that calls &lt;code&gt;attachShadow&lt;/code&gt; will become a shadow host and create a shadow tree.&lt;br&gt;
In the above code, the mode is set to &lt;code&gt;open&lt;/code&gt;. If the shadow root is created with &lt;code&gt;open&lt;/code&gt; mode, the shadow root can be accessed by the real DOM elements in the following way,&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="nb"&gt;document&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;#shadow-host&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;innerHTML&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If the mode is set to &lt;code&gt;closed&lt;/code&gt;, the above code will return &lt;code&gt;null&lt;/code&gt;.&lt;/p&gt;

&lt;h3&gt;
  
  
  Browser compatibility
&lt;/h3&gt;

&lt;p&gt;Shadow DOM is supported by the &lt;a href="https://caniuse.com/shadowdomv1"&gt;latest browsers&lt;/a&gt; such as Chrome, Firefox (63 and onwards), Opera, Safari, and Edge. The &lt;a href="https://github.com/googlearchive/ShadowDOM"&gt;polyfills&lt;/a&gt; are also available for the unsupporting browsers.&lt;/p&gt;

</description>
      <category>javascript</category>
      <category>html</category>
      <category>dom</category>
      <category>css</category>
    </item>
    <item>
      <title>Create shareable ESlint configs for Vue projects</title>
      <dc:creator>mathumitha</dc:creator>
      <pubDate>Tue, 17 May 2022 05:08:06 +0000</pubDate>
      <link>https://dev.to/mathumitha/create-a-shareable-eslint-configs-for-vue-projects-1cc1</link>
      <guid>https://dev.to/mathumitha/create-a-shareable-eslint-configs-for-vue-projects-1cc1</guid>
      <description>&lt;p&gt;Linting helps projects follow the best practices, enforce coding conventions and ensure code quality. &lt;a href="https://eslint.org/"&gt;ESlint&lt;/a&gt; is a static code analysis tool that exclusively lints Javascript code.&lt;/p&gt;

&lt;p&gt;Any project that has an ESlint setup will adhere to code uniformity regardless of the expertise of developers. ESlint scans the code, reports the potential errors and stylistic errors then and there. Hence, developers can fix the errors on the fly even before it goes for code review. &lt;/p&gt;

&lt;p&gt;While ESlint fixes the coding style, &lt;a href="https://prettier.io/"&gt;Prettier&lt;/a&gt; can accompany to fix formatting. &lt;/p&gt;

&lt;p&gt;In this article, Let's create a package that exposes a reusable ESlint config that can be shared across Vue projects.&lt;/p&gt;

&lt;p&gt;Run the following command to create npm package. Make sure that the package name starts with &lt;code&gt;eslint-config&lt;/code&gt; such as &lt;code&gt;eslint-config-vue-standards&lt;/code&gt;, If the project has npm scope, you can name it &lt;code&gt;@scope/eslint-config&lt;/code&gt; as such.&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;p&gt;This will create a package.json file under our project directory.&lt;/p&gt;

&lt;p&gt;Let's install ESlint,&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;eslint &lt;span class="nt"&gt;--save-dev&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;ESlint is installed in &lt;code&gt;devDependencies&lt;/code&gt; and add it to &lt;code&gt;peerDependencies&lt;/code&gt; to ensure that consumer applications install the same version of ESlint.&lt;/p&gt;

&lt;p&gt;Next, Let's install the ESlint plugin that supports Vue files.&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 eslint-plugin-vue --save
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;ESlint rules are completely configurable based on our style guide. You can enable/disable them completely or under certain conditions. To know more, check &lt;a href="https://eslint.org/docs/user-guide/configuring/rules#configuring-rules"&gt;this guide.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There are many shareable ESlint Configs used by many companies such as &lt;a href="https://www.npmjs.com/package/eslint-config-airbnb"&gt;eslint-config-airbnb&lt;/a&gt; recommended by Airbnb. Similarly, you can also create your own set of configs as a package for your project or company based on the style guide you follow and share it across for the other teams to consume. Let's install some of the existing configs that already enforce the best practices.&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;eslint-config-airbnb-base eslint-plugin-import eslint-plugin-vuejs-accessibility &lt;span class="nt"&gt;--save&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Let's create a configuration file &lt;code&gt;index.js&lt;/code&gt; where we can extend the installed configs.&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;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;es6&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;span class="na"&gt;browser&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;span class="na"&gt;node&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;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;parserOptions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;ecmaVersion&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2021&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;sourceType&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;module&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;ecmaFeatures&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;jsx&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;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;extends&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;eslint:recommended&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="s2"&gt;airbnb-base&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="s2"&gt;plugin:import/recommended&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="s2"&gt;plugin:vue/recommended&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="s2"&gt;plugin:vuejs-accessibility/recommended&lt;/span&gt;&lt;span class="dl"&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;vue/camelcase&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;error&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;There, &lt;code&gt;env&lt;/code&gt; and &lt;code&gt;parserOptions&lt;/code&gt; are used to define the environments such as node, browser, and parsers such as jsx, ecma. I have added &lt;code&gt;vue/camelcase&lt;/code&gt; rule with &lt;code&gt;error&lt;/code&gt; configuration that will throw an error when expressions inside vue &lt;code&gt;&amp;lt;template&amp;gt;&lt;/code&gt; does not follow camelCase conventions.&lt;/p&gt;

&lt;p&gt;Let's configure prettier now,&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 prettier --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Like ESlint, Prettier also has to be a peerDependency.&lt;/p&gt;

&lt;p&gt;Let's install prettier configs,&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 eslint-config-prettier eslint-plugin-prettier --save
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Our final configs will look like the below after prettier configs added,&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;env&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;es6&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;span class="na"&gt;browser&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;span class="na"&gt;node&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;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;parserOptions&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;ecmaVersion&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2021&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;sourceType&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;module&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
    &lt;span class="na"&gt;ecmaFeatures&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="na"&gt;jsx&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;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="p"&gt;},&lt;/span&gt;
  &lt;span class="na"&gt;extends&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;eslint:recommended&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="s2"&gt;airbnb-base&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="s2"&gt;plugin:import/recommended&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="s2"&gt;plugin:vue/recommended&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="s2"&gt;plugin:vuejs-accessibility/recommended&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="s2"&gt;prettier&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="s2"&gt;plugin:prettier/recommended&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;rules&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;vue/camelcase&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="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;error&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;It is important to note that the prettier configuration file &lt;code&gt;.prettierrc.js&lt;/code&gt; must reside in the consumer application.&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;tabWidth&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
  &lt;span class="na"&gt;singleQuote&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;p&gt;&lt;strong&gt;Yay.We are done!&lt;/strong&gt;&lt;br&gt;
You can publish this package and start using in any vue application. To test it locally, you can install by running the following command.&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 &amp;lt;path-to-application&amp;gt;/eslint-vue-blog --save-dev
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This package is available in &lt;a href="https://github.com/mathu-mitha/eslint-config-vue"&gt;Github&lt;/a&gt;. &lt;/p&gt;

</description>
    </item>
    <item>
      <title>Dynamic Brand theming using CSS variables </title>
      <dc:creator>mathumitha</dc:creator>
      <pubDate>Sat, 26 Jun 2021 14:38:03 +0000</pubDate>
      <link>https://dev.to/mathumitha/dynamic-brand-theming-using-css-variables-2kbd</link>
      <guid>https://dev.to/mathumitha/dynamic-brand-theming-using-css-variables-2kbd</guid>
      <description>&lt;p&gt;Recently, I got to work on an e-commerce checkout page builder (No code tool) where the merchants can change the theme according to their brand. The merchants can configure their brand colour and secondary colour to various elements like buttons, containers, texts, etc. This configuration will be fetched using APIs and applied to checkout pages on rendering. I was exploring various approaches such as &lt;strong&gt;SASS/LESS/Stylus variables, CSS-in-JS libraries and CSS variables&lt;/strong&gt; for applying the theme. After a deep exploration, I ended up using CSS variables. In this article, I would like to explain the pros and cons of each approach and how I ended up using CSS variables.&lt;/p&gt;

&lt;h2&gt;
  
  
  SASS/LESS/Stylus variables:
&lt;/h2&gt;

&lt;p&gt;CSS preprocessors are scripting languages that allow developers to write DRY styles using variables, functions, mixins, etc. These DRY styles would be converted into raw CSS styles in compile time. If we are aware of all theme-related information during compile time, we can easily map them to these variables and achieve theming. As the checkout has to allow the merchants to change the theme dynamically in run time, we cannot go with this approach.&lt;/p&gt;

&lt;h2&gt;
  
  
  CSS-in-JS libraries:
&lt;/h2&gt;

&lt;p&gt;There are many CSS-in-Js libraries available in the market such as &lt;strong&gt;styled-components, emotion, glamorous,&lt;/strong&gt; etc. These provide extensive theming support. However, these libraries require &lt;code&gt;&amp;lt;ThemeProvider /&amp;gt;&lt;/code&gt; which has to be wrapped over the app in order to provide theming context. Vendor lock-in is another disadvantage of using this. We will not be able to easily switch to a different approach in the future. As we got used to the traditional CSS approach, the learning curve is also steep.&lt;/p&gt;

&lt;h2&gt;
  
  
  CSS Variables:
&lt;/h2&gt;

&lt;p&gt;CSS variables a.k.a custom properties allow us to change the values dynamically in the run time using Javascript. We can use var()to use a variable in the references of the stylesheet. You can assign the value of CSS variable either in CSS or javascript. Many latest browser versions support CSS variables. As CSS variables are supported by native CSS and the learning curve is also shallow, I preferred CSS variables for my theme-able system.&lt;/p&gt;

&lt;p&gt;Let’s create a simple checkout page that contains the shipping address section, the payment section and the cart section. The merchant would be able to configure &lt;code&gt;brandColor&lt;/code&gt;, &lt;code&gt;secondaryColor&lt;/code&gt; and &lt;code&gt;bodyBackgroundColor&lt;/code&gt; for these sections.&lt;/p&gt;

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

&lt;h3&gt;
  
  
  Step 1 — Mapping the variables to check out elements
&lt;/h3&gt;

&lt;p&gt;Let’s map each variable to the respective checkout elements.&lt;br&gt;
&lt;strong&gt;brandColor&lt;/strong&gt;- This is used for primary buttons, logo and border colours&lt;br&gt;
&lt;strong&gt;secondaryColor&lt;/strong&gt; — This is used in the apply coupon input group&lt;br&gt;
&lt;strong&gt;bodyBackgroundColor&lt;/strong&gt;- This is applied as a background colour to the main container.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdoyl43z973yvewb5zlx9.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdoyl43z973yvewb5zlx9.png" alt="Checkout mock ip image with pointers"&gt;&lt;/a&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  Step 2 — Using the CSS variables in the stylesheet.
&lt;/h3&gt;

&lt;p&gt;To assign a CSS variable to a property, we have to use &lt;code&gt;var()&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Let’s have a look at the selectors which use &lt;code&gt;brandColorvariable&lt;/code&gt;. The value for this variable will be set using javascript during run time.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;code&gt;secondaryColor&lt;/code&gt; variable is used for the apply coupon button.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;&lt;code&gt;bodyBackgroundColor&lt;/code&gt; is applied to the main container of the application.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Step 3 — Creating Merchant configuration JSON
&lt;/h3&gt;

&lt;p&gt;Our theme builder configuration will be exposed via API from the server. The configuration JSON will be looking something like this&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;p&gt;In order to demo, let’s mock the server response with static JSON. &lt;code&gt;getMerchantConfigfunction&lt;/code&gt; will return a promise which resolves the merchant configuration using the &lt;code&gt;merchantId&lt;/code&gt; argument.&lt;br&gt;
&lt;/p&gt;
&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;


&lt;h3&gt;
  
  
  Step 4 — Setting values for CSS variables in Javascript
&lt;/h3&gt;

&lt;p&gt;Now, let’s see how the variables are set in Javascript. As the variables are used across the stylesheet, let’s set the variables in the root element.&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;root&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="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;:root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;root&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="nf"&gt;setProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;--brandColor&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;merchant&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;brandColor&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;root&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="nf"&gt;setProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;--secondaryColor&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;merchant&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;secondaryColor&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="nx"&gt;root&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="nf"&gt;setProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;--bodyBackgroundColor&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;merchant&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bodyBackgroundColor&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;Now, we have to get the theme configuration for the merchant. Let’s say Merchant 1 is active. we have to call &lt;code&gt;getMerchantConfig&lt;/code&gt; function by passing merchantId &lt;code&gt;merchant1&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="kd"&gt;const&lt;/span&gt; &lt;span class="nx"&gt;setTheme&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;async &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;merchant&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="k"&gt;await&lt;/span&gt; &lt;span class="nf"&gt;getMerchantConfig&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;merchant1&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;root&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="nf"&gt;querySelector&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;:root&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;root&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="nf"&gt;setProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;--brandColor&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;merchant&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;brandColor&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;root&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="nf"&gt;setProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;--secondaryColor&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;     &lt;span class="nx"&gt;merchant&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;secondaryColor&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
  &lt;span class="nx"&gt;root&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="nf"&gt;setProperty&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;--bodyBackgroundColor&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="nx"&gt;merchant&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nx"&gt;bodyBackgroundColor&lt;/span&gt;&lt;span class="p"&gt;);&lt;/span&gt;
&lt;span class="p"&gt;};&lt;/span&gt;
&lt;span class="nf"&gt;setTheme&lt;/span&gt;&lt;span class="p"&gt;();&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;


&lt;p&gt;The final Js code will be looking like this.&lt;/p&gt;


&lt;div class="ltag_gist-liquid-tag"&gt;
  
&lt;/div&gt;



&lt;p&gt;That’s all, We are done with it 😎. You can see the working demo in the codepen. You can play around by passing different merchantIds to getMerchantConfig function. You can also try configuring other properties such as font-size, font-family, etc.&lt;/p&gt;

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

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

&lt;p&gt;Theming is much more simplified using CSS variables. There is no vendor lock-in. CSS variables are supported by native CSS and have great browser compatibility. It’s the best fit for my feature. CSS variables have much more potential other than theming. It reduces plenty of repetitive tasks. You can give it a try. I’m attaching a few good resources here.&lt;/p&gt;

&lt;ol&gt;
&lt;li&gt;&lt;a href="https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties#basic_usage" rel="noopener noreferrer"&gt;https://developer.mozilla.org/en-US/docs/Web/CSS/Using_CSS_custom_properties#basic_usage&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://electerious.medium.com/the-power-of-css-variables-6c4e4ebaf279" rel="noopener noreferrer"&gt;https://electerious.medium.com/the-power-of-css-variables-6c4e4ebaf279&lt;/a&gt;&lt;/li&gt;
&lt;/ol&gt;

</description>
      <category>javascript</category>
      <category>css</category>
      <category>design</category>
      <category>html</category>
    </item>
  </channel>
</rss>
