<?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: webdev03</title>
    <description>The latest articles on DEV Community by webdev03 (@webdev03).</description>
    <link>https://dev.to/webdev03</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%2F774062%2F893992f1-7f1c-45a4-9474-4cd20a06ee0c.png</url>
      <title>DEV Community: webdev03</title>
      <link>https://dev.to/webdev03</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/webdev03"/>
    <language>en</language>
    <item>
      <title>Setting up SvelteKit with TailwindCSS</title>
      <dc:creator>webdev03</dc:creator>
      <pubDate>Fri, 31 Dec 2021 06:15:06 +0000</pubDate>
      <link>https://dev.to/webdev03/setting-up-sveltekit-with-tailwindcss-4o3m</link>
      <guid>https://dev.to/webdev03/setting-up-sveltekit-with-tailwindcss-4o3m</guid>
      <description>&lt;p&gt;Hello everyone. This is my first post on the &lt;code&gt;dev.to&lt;/code&gt; community so I hope you all like it! :D&lt;/p&gt;

&lt;p&gt;In this tutorial I will go over the process of setting up SvelteKit with Tailwind CSS.&lt;/p&gt;

&lt;h2&gt;
  
  
  Setting up your SvelteKit project
&lt;/h2&gt;

&lt;p&gt;So, to set up a basic SvelteKit project, you can run this command.&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 svelte@next tailwind-sveltekit 
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can replace &lt;code&gt;tailwind-sveltekit&lt;/code&gt; with whatever directory name you want, or if you are already in the directory you want to use, you can remove it.&lt;/p&gt;

&lt;p&gt;Now you can run&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;(or you can use any package manager you like such as &lt;code&gt;pnpm&lt;/code&gt; or &lt;code&gt;yarn&lt;/code&gt;)&lt;br&gt;
and&lt;br&gt;
&lt;/p&gt;

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

&lt;/div&gt;



&lt;h2&gt;
  
  
  Adding Tailwind
&lt;/h2&gt;

&lt;p&gt;To add TailwindCSS, we will also need to use PostCSS.&lt;br&gt;
So, first, run this command in your terminal.&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;-D&lt;/span&gt; tailwindcss postcss autoprefixer
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You will now have Tailwind, PostCSS, and Autoprefixer installed.&lt;br&gt;
After that, run&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;npx tailwindcss init &lt;span class="nt"&gt;-p&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This will create two files, &lt;code&gt;tailwind.config.js&lt;/code&gt; and &lt;code&gt;postcss.config.js&lt;/code&gt; for you.&lt;br&gt;
Now, you need to rename these files. SvelteKit doesn't accept &lt;code&gt;.js&lt;/code&gt; files so change the file names to &lt;code&gt;tailwind.config.cjs&lt;/code&gt; and &lt;code&gt;postcss.config.cjs&lt;/code&gt; instead.&lt;br&gt;
In your &lt;code&gt;src/&lt;/code&gt; folder of your project, create a folder called &lt;code&gt;lib&lt;/code&gt; if you haven't already. Inside, create a &lt;code&gt;tailwind.css&lt;/code&gt; file and add this into the file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&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;/div&gt;



&lt;p&gt;In your &lt;code&gt;src/routes/&lt;/code&gt; you can make a &lt;code&gt;__layout.svelte&lt;/code&gt; file with this inside of it:&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;script&amp;gt;&lt;/span&gt;
&lt;span class="k"&gt;import&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;$lib/tailwind.css&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;span class="nt"&gt;&amp;lt;div&lt;/span&gt; &lt;span class="na"&gt;class=&lt;/span&gt;&lt;span class="s"&gt;"pt-2"&lt;/span&gt;&lt;span class="nt"&gt;&amp;gt;&lt;/span&gt;
  &lt;span class="nt"&gt;&amp;lt;slot&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;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Now you can &lt;code&gt;npm run dev&lt;/code&gt; and see it. But you may have noticed something off.&lt;br&gt;
TailwindCSS doesn't know about your Svelte code and so the Just-in-Time engine will only include the base style reset. So in your &lt;code&gt;tailwind.config.cjs&lt;/code&gt; file you should change it to&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;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="s1"&gt;./src/**/*.{js,ts,svelte}&lt;/span&gt;&lt;span class="dl"&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="p"&gt;}&lt;/span&gt;

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

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;content&lt;/code&gt; property is what has changed. This lets Tailwind know that your class names are there, so the JIT engine will know what to generate.&lt;/p&gt;

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

&lt;p&gt;I hope you enjoyed this tutorial. If you have any questions, please let me know. :D&lt;/p&gt;

</description>
      <category>tutorial</category>
      <category>webdev</category>
      <category>svelte</category>
      <category>tailwindcss</category>
    </item>
  </channel>
</rss>
