Shopify TailwindCSS and daisyui Setup Guide — Build Stunning Themes Fast| Sabbirz | Blog

How to Integrate TailwindCSS with daisyui in Shopify: Step-by-Step Guide

shopify-configure-tailwindcss

Shopify TailwindCSS and daisyui Setup Guide — Build Stunning Themes Fast

Prerequisites

  1. You have already created a development store on Shopify.
  2. You have set up Shopify's local development environment.

Step-by-step guide

  1. Create a file called .shopifyignore in the root folder of your Shopify project and add the following content:
    node_modules
    package.json
    package-lock.json
  2. Create a .gitignore file (if you don't already have one) and add node_modules:
    node_modules
  3. Run the following command in the Shopify root folder to create package.json:
    npm init -y
  4. Install TailwindCSS and its Vite plugin:
    npm install tailwindcss @tailwindcss/vite
  5. In Shopify's assets directory, create a file named tailwind.input.css and add the following line:
    @import "tailwindcss";
  6. Create a file named shopify.theme.toml with the following content (replace the URL with your store URL):
    [environments.development]
    store = "https://your-store-name.myshopify.com/"
    Shopify creating toml file
  7. Install the concurrently npm package as a development dependency. This package helps run multiple commands simultaneously:
    npm install concurrently --save-dev
  8. Open your package.json file and add the following script inside the "scripts" section:
    "dev": "concurrently \"shopify theme dev -e development\" \"npx @tailwindcss/cli -i ./assets/tailwind.input.css -o ./assets/tailwind.output.css --watch\""
  9. Run the development script:
    npm run dev
  10. Open assets/tailwind.output.css and notice that TailwindCSS has purged unused styles and kept only the required ones.
  11. Open your theme.liquid file and before the closing </head> tag, include the generated CSS file:
    <head>
      <!-- Other head elements -->
      <meta name="viewport" content="width=device-width, initial-scale=1.0">
      {{ 'tailwind.output.css' | asset_url | stylesheet_tag: preload: true, media: 'all' }}
    </head>

    Note: If you don’t add <meta name="viewport" content="width=device-width, initial-scale=1.0"> in the theme.liquid the tailwindcss media queries WILL NOT WORK.

  12. Everything is set up! Now you can add TailwindCSS classes to your Shopify theme and enjoy the styling magic.

Shopify: How to integrate daisyui with tailwindcss

  1. Install daisyui using
    npm i -D daisyui@latest
  2. Open assets/tailwind.input.css and add daisyui
    @import "tailwindcss";
    @plugin "daisyui" {
      themes: light --default;
    }
  3. To know more about controlling the daisyui theme, navigate to the daisyui website

Related posts