Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save osama2kabdullah/e3a64df3d2b514ee2cfe8bbb19e4c8ac to your computer and use it in GitHub Desktop.
Save osama2kabdullah/e3a64df3d2b514ee2cfe8bbb19e4c8ac to your computer and use it in GitHub Desktop.
How to add Tailwind CSS in a shopify theme in development mode only

Add Tailwind CSS in Shopify Theme

  1. Initial node.js package manager with npm or yarn by running
yarn init -y 
#or
npm init -y
  1. Install packages and initialize a Tailwind config file
npm install -D tailwindcss @shopify/prettier-plugin-liquid
# and
npx tailwindcss init
  1. Create a CSS file in the assets directory. Name it tailwind.css or anything you want. doesnt matter.
  2. Paste this line of code in this file.
@tailwind base;
@tailwind components;
@tailwind utilities;
  1. Add a Liquid Stylesheet Tag to theme.liquid File in layouts Folder.
{{ 'application.css' | asset_url | stylesheet_tag }}
  1. Include this in your tailwind.config.js file.
module.exports = {
    ...
    content: ['./**/*.{liquid,json}'],
    ...
}
  1. Add a Watch Script to package.json file. This will continuasly compile your Tailwind CSS into raw css. Then your theme get the raw css.
"scripts": {
    "watch": "npx tailwind -i ./assets/tailwind.css -o ./assets/application.css --watch"
  },
  1. Alternatively you can write a script in your package.json file.
"start": "shopify theme dev",
"watch": "npx tailwind -i ./assets/tailwind.css -o ./assets/application.css --watch",
"dev": "npm run watch & npm run start"

This will help you run these aretwo in one command. If you use out of UNIX-like machine. This will maybe not work. But you can try this-

"dev": "npm-run-all --parallel start-watch wp-server"
@BenjErgizerBunny
Copy link

Thanks so much for making this guide! I'm new to Shopify dev. Will this work with Liquid? I have a feeling not?

@osama2kabdullah
Copy link
Author

Thanks so much for making this guide! I'm new to Shopify dev. Will this work with Liquid? I have a feeling not?

Yes, it will work. I have tried on our project. see this repo - https://github.com/osama2kabdullah/Theme1992

@BenjErgizerBunny
Copy link

BenjErgizerBunny commented Jan 16, 2025 via email

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment