<?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: 👨🏾‍💻 Kam Banwait</title>
    <description>The latest articles on DEV Community by 👨🏾‍💻 Kam Banwait (@scriptedpixels).</description>
    <link>https://dev.to/scriptedpixels</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%2F115990%2F1b59265f-8905-4888-a3db-55f1c4d930d5.jpeg</url>
      <title>DEV Community: 👨🏾‍💻 Kam Banwait</title>
      <link>https://dev.to/scriptedpixels</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/scriptedpixels"/>
    <language>en</language>
    <item>
      <title>Setting up DaisyUI, Tailwind, Vue and Vite</title>
      <dc:creator>👨🏾‍💻 Kam Banwait</dc:creator>
      <pubDate>Sun, 21 Aug 2022 13:10:18 +0000</pubDate>
      <link>https://dev.to/scriptedpixels/setting-up-daisyui-tailwind-vue-and-vite-3k7e</link>
      <guid>https://dev.to/scriptedpixels/setting-up-daisyui-tailwind-vue-and-vite-3k7e</guid>
      <description>&lt;p&gt;I've decided to document how to set-up and use DaisyUI, with Vue and Tailwind, having used it recently in a client project. I added DaisyUI to ensure there was some consistency in the application I was building. It was initially being developed by myself but then it quickly grew to being developed by developers in multiple teams. Features and components were built without any wire-frames or base styleguides to follow. Some groundwork &lt;strong&gt;had&lt;/strong&gt; to be introduced before the UI became too fragmented.&lt;/p&gt;

&lt;h2&gt;
  
  
  Prerequisites
&lt;/h2&gt;

&lt;ol&gt;
&lt;li&gt;You'll need &lt;a href="https://nodejs.org/en/" rel="noopener noreferrer"&gt;Node&lt;/a&gt; installed globally on your machine.&lt;/li&gt;
&lt;li&gt;See what &lt;a href="https://daisyui.com" rel="noopener noreferrer"&gt;DaisyUI&lt;/a&gt; offers&lt;/li&gt;
&lt;/ol&gt;

&lt;h2&gt;
  
  
  Initial setup
&lt;/h2&gt;

&lt;p&gt;We'll be using &lt;a href="http://vitejs.dev/" rel="noopener noreferrer"&gt;Vite&lt;/a&gt; as our development server. It's now the standard, over Webpack, for developing JS applications. I highly recommend moving your existing web app builds over to Vite. The speed increase is worth the migration process.&lt;/p&gt;

&lt;p&gt;Pop open your terminal of choice and run the following commands:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Run &lt;code&gt;npm init vite projectName&lt;/code&gt;, where &lt;code&gt;projectName&lt;/code&gt; will be the name of a new folder for your application

&lt;ul&gt;
&lt;li&gt;select &lt;code&gt;vue&lt;/code&gt; using the arrow keys and press enter to select&lt;/li&gt;
&lt;li&gt;select &lt;code&gt;vue&lt;/code&gt; again&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Once that has completed, you should see a prompt to &lt;code&gt;cd&lt;/code&gt; into your new project directory

&lt;ul&gt;
&lt;li&gt;run &lt;code&gt;npm install&lt;/code&gt; to install the base dependencies&lt;/li&gt;
&lt;li&gt;run &lt;code&gt;npm run dev&lt;/code&gt; if you want to see the base Vue app. You can also experience how fast Vite is at getting your dev server running&lt;/li&gt;
&lt;li&gt;If you've ran the last command, exit out of it so we can install the remaining dependencies&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;Run &lt;code&gt;npm install -D tailwindcss postcss autoprefixer&lt;/code&gt; to get &lt;a href="https://tailwindcss.com" rel="noopener noreferrer"&gt;tailwind&lt;/a&gt;, &lt;a href="https://postcss.org/" rel="noopener noreferrer"&gt;postcss&lt;/a&gt; and &lt;a href="https://autoprefixer.github.io/" rel="noopener noreferrer"&gt;autoprefixer&lt;/a&gt; installed as Dev dependencies

&lt;ul&gt;
&lt;li&gt;run &lt;code&gt;npx tailwindcss init -p&lt;/code&gt; to generate config files for Tailwind and PostCss&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;

&lt;p&gt;Open your new project directory in your IDE&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;In &lt;code&gt;tailwind.config.js&lt;/code&gt; we need to update &lt;code&gt;content: []&lt;/code&gt; with &lt;code&gt;content: ["./index.html", "./src/**/*.{vue,js,ts,jsx,tsx}",]&lt;/code&gt; to tell Tailwind to look at our &lt;code&gt;index.html&lt;/code&gt; and our &lt;code&gt;Vue.js&lt;/code&gt; files where we'll be using Tailwind classes&lt;/li&gt;
&lt;li&gt;In &lt;code&gt;./src/&lt;/code&gt; we need to create a new CSS file. It can be called anything you like. I call it &lt;code&gt;index.css&lt;/code&gt;. Within this file we need to add the following to import Tailwind's directives for each of its layers:
&lt;/li&gt;
&lt;/ul&gt;

&lt;pre class="highlight css"&gt;&lt;code&gt;&lt;span class="k"&gt;@tailwind&lt;/span&gt; &lt;span class="n"&gt;base&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;@tailwind&lt;/span&gt; &lt;span class="n"&gt;components&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;span class="k"&gt;@tailwind&lt;/span&gt; &lt;span class="n"&gt;utilities&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;



&lt;ul&gt;
&lt;li&gt;In your &lt;code&gt;./src/main.js&lt;/code&gt; add the following line &lt;code&gt;import './index.css'&lt;/code&gt;, under &lt;code&gt;import App from './App.vue'&lt;/code&gt; to import the new stylesheet. You should have:
&lt;/li&gt;
&lt;/ul&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;createApp&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&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;./App.vue&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;'&lt;/span&gt;&lt;span class="s1"&gt;./index.css&lt;/span&gt;&lt;span class="dl"&gt;'&lt;/span&gt;

&lt;span class="nf"&gt;createApp&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="nf"&gt;mount&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;/code&gt;&lt;/pre&gt;



&lt;ul&gt;
&lt;li&gt;Empty the contents of &lt;code&gt;./src/App.vue&lt;/code&gt; and add the below with Tailwind's classes:
&lt;/li&gt;
&lt;/ul&gt;

&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;template&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text-3xl font-bold underline mb-10&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="o"&gt;!&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/template&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;ul&gt;
&lt;li&gt;Back in your terminal, run &lt;code&gt;npm run dev&lt;/code&gt; and go to the URL Vite has provided, e.g: &lt;code&gt;http://localhost:3000&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;You should see a plain white page with &lt;code&gt;Hello vue!&lt;/code&gt; in large bold text with an underline:&lt;/li&gt;
&lt;li&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%2Fsfsni1xuryopwjsfw7y9.png" alt="Hello Vue in plain TailwindCss" width="356" height="356"&gt;&lt;/li&gt;
&lt;li&gt;You can now exit this as we need to add &lt;a href="https://daisyui.com/" rel="noopener noreferrer"&gt;DaisyUI&lt;/a&gt; to the application&lt;/li&gt;
&lt;li&gt;In your terminal, run the following to install DaisyUI: &lt;code&gt;npm i daisyui&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;In the &lt;code&gt;tailwind.config.js&lt;/code&gt; file we need to add &lt;code&gt;require("daisyui")&lt;/code&gt; within the &lt;code&gt;plugins&lt;/code&gt; array. You should have the following in your &lt;code&gt;tailwind.config.js&lt;/code&gt; file:
&lt;/li&gt;
&lt;/ul&gt;

&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="cm"&gt;/** @type {import('tailwindcss').Config} */&lt;/span&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;content&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;./index.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="s2"&gt;./src/**/*.{vue,js,ts,jsx,tsx}&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;theme&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
    &lt;span class="na"&gt;extend&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;plugins&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;require&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;daisyui&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;ul&gt;
&lt;li&gt;Back in your &lt;code&gt;./src/App.vue&lt;/code&gt; file we can start adding some DaisyUI classes, e.g:
&lt;/li&gt;
&lt;/ul&gt;

&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;template&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;h1&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;text-3xl font-bold underline mb-10&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt; &lt;span class="nx"&gt;Vue&lt;/span&gt;&lt;span class="o"&gt;!&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/h1&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;  &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;button&lt;/span&gt; &lt;span class="kd"&gt;class&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;btn btn-primary&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;&lt;span class="nx"&gt;Hello&lt;/span&gt; &lt;span class="nx"&gt;Daisy&lt;/span&gt; &lt;span class="nx"&gt;button&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/button&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="sr"&gt;/template&lt;/span&gt;&lt;span class="err"&gt;&amp;gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;



&lt;ul&gt;
&lt;li&gt;In your terminal, run the following to see the changes &lt;code&gt;npm run dev&lt;/code&gt;. You should now see an updated page with a theme and styled button:&lt;/li&gt;
&lt;li&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%2Fl6qqqm4tnrwe3kbth404.png" alt="Hello Vue with DaisyUI" width="356" height="356"&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;li&gt;&lt;p&gt;That's it! We've now got access to all of &lt;a href="https://daisyui.com/components/" rel="noopener noreferrer"&gt;DaisyUI's components&lt;/a&gt; throughout our application&lt;/p&gt;&lt;/li&gt;

&lt;/ul&gt;

&lt;h3&gt;
  
  
  Taking it a step further for future applications
&lt;/h3&gt;

&lt;p&gt;I feel like the following steps are important to create a template for any new applications you feel like building:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Delete the contents of the following directories:

&lt;ul&gt;
&lt;li&gt;&lt;code&gt;./src/components/&lt;/code&gt;&lt;/li&gt;
&lt;li&gt;&lt;code&gt;./src/assets/&lt;/code&gt;&lt;/li&gt;
&lt;/ul&gt;


&lt;/li&gt;

&lt;/ul&gt;

&lt;p&gt;That's it, You can now commit this to a repo and use it when you're starting new projects. I've created my version &lt;a href="https://bitbucket.org/scriptedpixels/basedaisyuitailwindvuevite/src/main" rel="noopener noreferrer"&gt;here&lt;/a&gt; for you to clone if you'd like.&lt;/p&gt;

</description>
      <category>vue</category>
      <category>vite</category>
      <category>daisyui</category>
      <category>tailwindcss</category>
    </item>
  </channel>
</rss>
