Shopify Theme Development With Vite, Tailwind and Alpine.js: How We Do It
After building headless Shopify stores for a while, and we came back to Online Store 2.0. Shopify's theme editor is better than anything we built around it: merchants get sections, blocks and settings they can change without waiting on us.
What we do replace is the rest of what a typical theme ships with. Hand-written stylesheets grow with every new section, and web components are hard to restyle when you're testing a lot. So on top of Liquid, we've decided to use Tailwindcss for styling, Alpine.js instead of web components with TypeScript for type safety and built with Vite.
Those choices came from years of building with different stacks and getting a few things wrong.
In this article, we'll walk you through how we got here, why each tool earns its place in a Shopify theme, and what this setup costs you, because it isn't free.
Before we get started, if you run a Shopify store, grab our CRO Audit Megalist below. It's a 148-point spreadsheet that scores each item by impact and ease, so you know what to fix first.
Our road to Tailwind
Back in 2015, our team was in love with Bootstrap. Then we started adding custom styles on top of it, then BEM, then our own utility classes. Eventually we asked ourselves whether we needed Bootstrap at all, scrapped it, and built our own base with Sass mixins and generated utility classes.
Long story short - we came to the same conclusion as Tailwindcss creators independently - utility classes are superior when properly abstracted. Tailwind was already ready to use in production, so we abandoned our own framework and stayed with Tailwindcss.
We've told the full story of how we moved to Tailwind in a separate post. What matters here is that by the time we took on more Shopify work, Tailwind was already how we wrote CSS everywhere else. The question was whether it would hold up in Liquid. It did, and for a few reasons that turned out to matter even more on Shopify than anywhere else.
Why we use Tailwind in Shopify themes
The stylesheet stops growing with the store
A Shopify store never stops changing. New landing pages, seasonal sections, redesigned product pages, and constant onslaught of experiments and new ideas. With BEM, every one of those adds CSS, and almost nothing ever gets deleted because nobody can be sure it isn't used somewhere.
With Tailwind, the CSS grows with the number of different utilities you use, not with the number of sections. Tailwind scans the theme's Liquid files and compiles only the classes it finds, so a store with 80 sections ships roughly the same stylesheet as one with 30. And when a style needs to change, you change it in place, in the section that uses it, without risking breaking it elsewhere.
A/B test variants can't break the control
This is the reason we'd pick Tailwind for Shopify today even if we didn't already use it. We run a lot of A/B tests on our clients' themes, and each variant has to be isolated. So it's usually a copy of a section, snippet or block with some changes, that's replaced in the test.
When the styles live in the markup, the variant's file carries its own design. Changing the heading size or the button layout in the variant can't touch the control, because there's no shared .hero__title rule they both depend on.
With a traditional stylesheet, every variant edit is a chance to change the control by accident, and an experiment where the control also changed is an experiment you have to throw away.
Every project speaks the same language
grid md:grid-cols-3 gap-6 means the same thing in every theme we maintain. A developer who jumps into a client's theme for the first time doesn't need to learn its naming conventions, and they can confidently make changes without risking breaking anything.
That also goes for AI coding agents, which do more of our day-to-day work every month. An agent writing a section with Tailwind classes uses vocabulary it already knows, and its changes stay inside the file it's editing. That's a lot safer than letting it loose on a 6,000-line theme.css file.
Keeping Tailwind isolated in an existing theme
Most of our work is on themes that already exist, and dropping Tailwind into one as-is will break it. Tailwind's base styles reset margins, headings and buttons that the theme's CSS relies on, and class names like hidden or container often clash with ones the theme already uses.
So on an inherited theme, we leave the base styles out and add a prefix. A class like flex becomes tw:flex, which can't collide with anything the theme already has. On themes we build from scratch, we use plain class names and Tailwind's full setup, which is how the examples in this post are written.
Why Alpine.js
For interactivity we looked at the obvious options. jQuery is already in plenty of themes we inherit, and HTMX fits server-rendered pages nicely. We also tried web components, since Shopify's own themes use them.
Finally Alpine.js won, for three reasons.
It's light and easy to extend
Alpine.js is one small script that reads attributes on your HTML. There's no build-time rendering, no hydration and no virtual DOM. When it's missing something, adding it is easy. Shopify sends prices in cents, so we made a custom directive - x-currency. About 20 lines of TypeScript, ensures correct price formatting with the users's active currency and locale:
<span x-currency="$store.cart.cart.total_price">{{ cart.total_price | money }}</span>Liquid prints the price on page load, and Alpine keeps it right as the cart changes, in every currency the store sells in.
Global stores handle the hard parts
The cart is where theme JavaScript usually gets messy, because the header count, the cart drawer, the product form and the upsell widget all need the same data.
Alpine solves that with global stores.
The cart lives in one store that any component on the page can read and change. It loads the cart when the page loads and wraps Shopify's Ajax Cart API in a few methods, like addToCart and removeProduct.
Every part of the theme reads from that store. The header count is $store.cart.item_count, the drawer opens when $store.cart.visible is true, and the add to cart button disables itself while a request is in flight:
<button
type="button"
class="w-full bg-black py-3 text-white disabled:opacity-50"
:disabled="$store.cart.processing"
@click="$store.cart.addToCart({{ product.selected_or_first_available_variant.id }}, 1)"
>
{{ 'products.product.add_to_cart' | t }}
</button>No more custom events to stay in sync. And because Alpine puts its stores on window, old code in an inherited theme can call window.Alpine.store('cart').addToCart(variantId, 1) too, so we can replace a theme's cart one piece at a time.
Components move between projects
We weighed Alpine against jQuery and HTMX, and the syntax decided it.
With jQuery, a separate script finds elements by class name and wires them up, so you can't tell what a button does by reading the section. HTMX keeps the behaviour in the markup like Alpine does, but it's built around fetching HTML from a server and swapping it into the page.
You can make that work on Shopify, since the Section Rendering API returns a section's HTML for HTMX to swap in. It just isn't elegant. The cart API answers in JSON. You can ask it to re-render sections along with the cart, but their HTML comes back inside that JSON, so HTMX can't swap it in without extra code. And opening a drawer or changing a quantity becomes a round trip for something the browser already knows.
In Alpine, x-show="open" and @click="open = !open" keep that state where it's used, which makes a component easy to adapt for multiple themes.
Web components lost for a different reason. Their shadow DOM keeps styles out, which is exactly what you don't want when you're testing a lot. To try a new layout for a component, you need to restyle it from the outside, and the shadow DOM gets in the way.
We want the presentation in Liquid and Tailwind, where a variant can change it freely, and the logic in TypeScript, where it stays the same for the control and every variant.
Why Vite and TypeScript
Tailwind and TypeScript both need a build step, and Vite is the one we use everywhere else.
On Shopify, the Shopify Vite plugin makes it work by generating a Liquid snippet called vite-tag. While we develop, it loads our files from Vite's development server, so a saved change shows up in the browser straight away.
In production, it loads the compiled files from Shopify's CDN, with a hashed name like app-ChvKLISQ.css that changes whenever the contents do, so customers never get a stale file.
Why TypeScript
A theme's JavaScript talks to a lot of things it doesn't control: Shopify's cart API, the window.Shopify object, and whatever apps the store has installed. We write types for all of them, and that pays off in a few ways:
- Mistakes show up in the editor, not on the live store. Misspell a property on the cart or pass a string where Shopify expects a number, and the editor flags it before anyone opens the store.
- Refactoring is safe. Rename a method in the cart store and TypeScript lists every place that calls it.
- The code documents itself. A developer, or an agent, picking up the theme can see what a function expects without reading all of it.
Why modules
Instead of one script that does everything, our code is split into small files, each with one job: the cart store, the currency directive, a track() helper that sends an event to Intelligems, Clarity, and other system. Each one is imported where it's needed.
That has three practical benefits.
- The same modules go into every client theme, so a fix to the cart store reaches every store we maintain.
- A test variant imports the same logic as the control, so the only difference is the one we're testing.
- And a page that needs a lot of JavaScript gets its own entry point, so the product page's code doesn't load on the blog.
How we ship it?
Every client theme is connected to Shopify's GitHub integration, so merging to main deploys the live theme.
Shopify deploys whatever is in the branch but doesn't run builds, so a GitHub Action is required to build the assets on every push.
All of this, the config, the cart store, the directives and Actions, lives in one internal toolkit that we install on every client theme and update with a single command.
When we find a problem, we fix it once and every theme gets the fix on its next update.
The drawbacks
As everything this setup has trade-offs.
There's a build step, and built files can cause conflicts. Every build renames the files it changes, so two branches with their own builds will conflict on merge. We handle that by never committing compiled files by hand, letting the Action build them. A small cleanup script removes older copies that slip through. It works, it's stable, but it's not required on most themes.
Your source code lives only in GitHub. Shopify stores the compiled bundles, not the TypeScript, the Tailwind setup or the Vite config they were built from. Open the code editor in the admin and you'll see minified files, and a quick fix made there gets overwritten by the next build. If the store owner downloads the theme, or a new developer takes over without access to the repository, they get the same minified files and nothing to build them from. The theme editor works as usual, since settings and template changes sync back to GitHub, but anyone changing code has to work in the repository, which can be a good thing.
It's worth it if you want to speed up testing and grow your store aggressively.
Variants that can't break the control, logic every test shares, and fixes that reach every running experiment at once are what let us run more tests on a store, and run them faster.
Frequently asked questions
Q: Can you use Vite with Shopify themes?
A: Yes. The Shopify Vite plugin generates a Liquid snippet that loads your files from the Vite development server while you work, and from Shopify's CDN in production. Liquid still renders your pages, so sections and the theme editor keep working as normal.
Q: Should you use Tailwind in a Shopify theme?
A: We think so, especially if you run A/B tests. Tailwind keeps the stylesheet small as the store grows, lets you change styles in the section that uses them, and means a test variant can't change the control's design. In an existing theme, leave out Tailwind's base styles and add a prefix so it can't clash with the theme's CSS.
Q: Is Alpine.js a good fit for Shopify themes?
A: Yes. Alpine adds behaviour to the HTML that Liquid already rendered, so there's no second rendering step and no hydration. It's small, easy to extend, and its global stores let every part of the theme share state like the cart.
Q: Will Vite delete files from my Shopify assets folder?
A: It can. By default, Vite empties its output folder on every build, and in a Shopify theme that's the assets folder. Set emptyOutDir to false and use a clean plugin that removes only the files Vite generated.
Q: Why are my Shopify breakpoints not working on older iPhones or iPads?
A: If you build with Vite 8, your breakpoints may come out as range media queries, which iOS Safari below 16.4 ignores. Those devices then show the mobile layout at every width. Setting build.cssTarget to include safari16 outputs min-width queries instead.
Wrapping up
Liquid is the one part of a Shopify theme you don't get to choose. Everything else, we picked because it solved a problem we'd already had: Tailwind because our own CSS kept turning into a mess, Alpine because it works with Liquid instead of against it, and TypeScript and Vite because a theme we test every week needs code we can change safely. It comes with a build step and a repository you can't do without, and for the stores we work with, that's a trade worth making.
This is the same stack behind our custom Shopify theme development. If you'd like it running on your store, get in touch. And if you're working in Liquid yourself, you might also like our guide to building nested blocks in Shopify sections.
Talk to a human


