<?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: Chris King</title>
    <description>The latest articles on DEV Community by Chris King (@morzaram0).</description>
    <link>https://dev.to/morzaram0</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%2F695480%2F18d7a426-1082-4fc3-b6ee-814045e4706b.jpeg</url>
      <title>DEV Community: Chris King</title>
      <link>https://dev.to/morzaram0</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/morzaram0"/>
    <language>en</language>
    <item>
      <title>How to Install Shoelace with Rails 7, esbuild, and Tailwind JIT</title>
      <dc:creator>Chris King</dc:creator>
      <pubDate>Thu, 13 Jan 2022 19:41:31 +0000</pubDate>
      <link>https://dev.to/morzaram0/how-to-install-shoelace-with-rails-7-esbuild-and-tailwind-jit-107a</link>
      <guid>https://dev.to/morzaram0/how-to-install-shoelace-with-rails-7-esbuild-and-tailwind-jit-107a</guid>
      <description>&lt;p&gt;After struggling to get this working myself I made a guide for future users! Hope you enjoy!&lt;/p&gt;

&lt;p&gt;Shout out to &lt;a class="mentioned-user" href="https://dev.to/jaredcwhite"&gt;@jaredcwhite&lt;/a&gt; for making the &lt;a href="https://dev.to/jaredcwhite/how-to-install-shoelace-with-rails-7-esbuild-and-postcss-1cg9"&gt;article to get me half way there &lt;/a&gt;.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Using postcss instead?&lt;/strong&gt;&lt;br&gt;
&lt;a href="https://dev.to/jaredcwhite/how-to-install-shoelace-with-rails-7-esbuild-and-postcss-1cg9"&gt;Follow this article!&lt;/a&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  Installing tailwind
&lt;/h2&gt;

&lt;p&gt;If you're just starting out with a new project&lt;/p&gt;

&lt;p&gt;&lt;code&gt;rails new your_project_name --css tailwind&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;otherwise follow this:&lt;/p&gt;

&lt;p&gt;For more documentation on tailwind installation: &lt;a href="https://github.com/rails/tailwindcss-rails" rel="noopener noreferrer"&gt;https://github.com/rails/tailwindcss-rails&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Run &lt;code&gt;./bin/bundle add tailwindcss-rails&lt;/code&gt;&lt;br&gt;
Run &lt;code&gt;./bin/rails tailwindcss:install&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The second command will guide you through the setup of tailwind&lt;/p&gt;
&lt;h2&gt;
  
  
  Installing Shoelace
&lt;/h2&gt;
&lt;h3&gt;
  
  
  1. Install via yarn
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;yarn add @shoelace-style/shoelace&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  2a (Option 1) Move required files from node_modules manually
&lt;/h3&gt;

&lt;p&gt;You can either copy the files yourself but have a large git commit of 1k+ files or you can have a script setup (see 2b) and follow the git ignore section&lt;/p&gt;

&lt;p&gt;&lt;code&gt;node_modules/@shoelace-style/shoelace/dist/themes/*.css&lt;/code&gt; to &lt;code&gt;app/assets/stylesheets/shoelace&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;&lt;code&gt;node_modules/@shoelace-style/shoelace/dist/assets&lt;/code&gt; to &lt;code&gt;public/shoelace-assets&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  2b (Option 2) Create a script to copy over files from node_modules.
&lt;/h3&gt;

&lt;p&gt;In your package.json add the following to your scripts.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;"scripts": {
    "build": "yarn shoelace:prepare &amp;amp;&amp;amp; esbuild app/javascript/*.* --bundle --sourcemap --outdir=app/assets/builds",
    "shoelace:prepare": "mkdir -p public/shoelace-assets &amp;amp;&amp;amp; yarn shoelace:copy-assets &amp;amp;&amp;amp; yarn shoelace:copy-styles",
    "shoelace:copy-assets": "cp -r node_modules/@shoelace-style/shoelace/dist/assets public/shoelace-assets",
    "shoelace:copy-styles": "copyfiles --flat node_modules/@shoelace-style/shoelace/dist/themes/*.css app/assets/stylesheets/shoelace"
  }
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The build command copies over the icons and such to the public assets. I git ignore these because we don't need to have thousands of them clogging up the git repo. It hydrates itself everytime you run &lt;code&gt;bin/dev&lt;/code&gt; so no need to worry about them.&lt;/p&gt;

&lt;p&gt;I use copyfiles package because it's a cleaner way to copy css only files so run &lt;/p&gt;

&lt;p&gt;&lt;code&gt;yarn add copyfiles&lt;/code&gt; before running the scripts&lt;/p&gt;

&lt;p&gt;once done, run &lt;code&gt;yarn shoelace:copy-styles&lt;/code&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  2b.2 (Optional) Add icons to .gitignore
&lt;/h3&gt;

&lt;p&gt;&lt;strong&gt;Skip this if you followed 2a!!&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In your gitignore add &lt;code&gt;public/shoelace-assets&lt;/code&gt; to the file&lt;/p&gt;

&lt;h3&gt;
  
  
  3. Import styles to application.tailwind.css file
&lt;/h3&gt;

&lt;p&gt;Now that you've imported everything, add the following to the tailwind file right below the &lt;a class="mentioned-user" href="https://dev.to/tailwind"&gt;@tailwind&lt;/a&gt; imports&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;@tailwind base;
@tailwind components;
@tailwind utilities;

@import "shoelace/light";
@import "shoelace/dark";  /* Optional */

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

&lt;/div&gt;



&lt;h3&gt;
  
  
  Adding your desired javascript to application.js
&lt;/h3&gt;

&lt;p&gt;This will be something that you'll need to keep updating as you add certain components. Say you want to add a button and icon component. You'll need to add the following to &lt;code&gt;/javascript/application.js&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;The import for the button:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import "@shoelace-style/shoelace/dist/components/button/button.js"
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;It's important to set this when using icons because this tells shoelace where the icons are:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;// This is the import for the icon component
import "@shoelace-style/shoelace/dist/components/icon/icon.js"
// This is the routing and importing of the icons themselves
import { setBasePath } from "@shoelace-style/shoelace/dist/utilities/base-path.js"
setBasePath("/shoelace-assets")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Note: when you want to add new components from shoelace this is where you stick the import code. You're using a bundler so make sure you select bundler and add the import. Here's an image of what I'm talking about&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%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Frvp80c9plxh53t9qfch3.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%2Frvp80c9plxh53t9qfch3.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Test drive it
&lt;/h2&gt;

&lt;p&gt;Okay cool, now that you've got this setup let's test drive it.&lt;/p&gt;

&lt;p&gt;On one of your pages add the following to generate a 'follow me twitter' button with the twitter icon&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;&amp;lt;p&amp;gt;&amp;lt;sl-button type="primary"&amp;gt;
  &amp;lt;sl-icon name="twitter"&amp;gt;&amp;lt;/sl-icon&amp;gt;
  Follow on Twitter
&amp;lt;/sl-button&amp;gt;&amp;lt;/p&amp;gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Start your server with &lt;code&gt;bin/dev&lt;/code&gt; and the result should look like this&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%2F8zsiv241e0iii5y5ers1.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%2F8zsiv241e0iii5y5ers1.png" alt="Image description"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;And voila, you're up and running with tailwind &amp;amp; shoelace!&lt;/p&gt;

&lt;p&gt;I'm sure this isn't the best way, but it works. I'm still quite new to this so apologies if this isn't best practice.&lt;/p&gt;

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

</description>
      <category>tailwindcss</category>
      <category>rails</category>
      <category>webcomponents</category>
      <category>shoelace</category>
    </item>
  </channel>
</rss>
