reactpifyjs
v1.0.25
Published
π The easiest way to add React components to any Shopify theme with Vite, Tailwind CSS, and intelligent Liquid auto-generation
Downloads
36
Maintainers
Readme
π Reactpify
The ultimate React integration library for Shopify themes. Build modern, interactive components with React while maintaining perfect SEO and theme compatibility.
β¨ Features
π Automatic Liquid Generation
- React β Liquid: Automatically generates Shopify Liquid templates from your React components
- SEO-friendly fallbacks: HTML shells rendered server-side for perfect SEO
- Theme Editor compatibility: Components work seamlessly in Shopify's theme customizer
π¨ Intelligent Theme Integration
- Automatic Style Analysis: Detects and extracts original theme styles
- Perfect Scoping: CSS automatically scoped to avoid conflicts with existing theme
- Tailwind Integration: Full Tailwind CSS v4 support with theme-aware configuration
π Bidirectional Watch System
- React β Liquid Sync: Changes in React components automatically update Liquid files
- Manual Edit Detection: Detects when Liquid files are manually modified
- Real-time Updates: Vite-powered development with instant hot reloading
π§© Fragment System
- Reusable Snippets: Share common Liquid schema fragments across components
- Auto-injection: Fragments automatically injected during build process
- Extensible: Easy to add custom fragments for your specific needs
π Prerequisites
Reactpify installs ON TOP of existing Shopify themes. Before installing, you need:
πͺ Existing Shopify Theme
- A working Shopify theme directory with these folders:
your-theme/ βββ assets/ βββ layout/ βββ sections/ βββ snippets/ βββ templates/
π― Compatible Themes
- β Dawn (Shopify's free theme)
- β Horizon (Latest Shopify theme)
- β Any modern Shopify theme (Online Store 2.0+)
- β Custom themes with standard structure
π How to Get a Shopify Theme
Option 1: Download from your Shopify store
# Install Shopify CLI
npm install -g @shopify/cli @shopify/theme
# Download your live theme
shopify theme pull
# Or start with Dawn (free theme)
shopify theme init my-theme --clone-url="https://github.com/Shopify/dawn"Option 2: Use an existing theme directory If you already have a Shopify theme folder, navigate to it:
cd your-existing-theme/
# Now you can install Reactpifyπ Quick Start
Installation
β οΈ Important: Run this command INSIDE your Shopify theme directory
cd your-theme-folder/
npm install reactpifyjsReactpify will automatically:
- β Detect your Shopify theme
- β Install all necessary files
- β
Update
layout/theme.liquid - β Create example components
- β Set up the build system
Basic Usage
- Create a React Component
// src/components/hello/Hello.tsx
import React, { useState } from 'react';
interface HelloProps {
title?: string;
showButton?: boolean;
}
export const Hello: React.FC<HelloProps> = ({
title = "Hello World",
showButton = true
}) => {
const [clicked, setClicked] = useState(false);
return (
<div className="reactpify-container max-w-md mx-auto p-6">
<div className="bg-blue-500 text-white p-6 rounded-lg shadow-lg text-center">
<h1 className="text-2xl font-bold mb-4">{title}</h1>
{showButton && (
<button
onClick={() => setClicked(!clicked)}
className="bg-white text-blue-500 px-4 py-2 rounded hover:bg-gray-100 transition-colors font-semibold"
>
{clicked ? 'β
Clicked!' : 'π Click me'}
</button>
)}
</div>
</div>
);
};- Create the Liquid Template
<!-- src/components/hello/section.hello.liquid -->
{% comment %}
Auto-generated by Reactpify
Component: Hello
{% endcomment %}
<div data-component-root data-section-data='{{ section | json | escape }}'>
<div data-fallback>
<div class="max-w-md mx-auto p-6">
<div class="bg-blue-500 text-white p-6 rounded-lg shadow-lg text-center">
<h1 class="text-2xl font-bold mb-4">{{ section.settings.title | default: 'Hello World' }}</h1>
{% if section.settings.show_button %}
<button class="bg-white text-blue-500 px-4 py-2 rounded font-semibold">
π Click me
</button>
{% endif %}
</div>
</div>
</div>
</div>
{{ 'main.css' | asset_url | stylesheet_tag }}
{{ 'main.js' | asset_url | script_tag }}
{% schema %}
{
"name": "Hello",
"settings": [
{
"type": "text",
"id": "title",
"label": "Title",
"default": "Hello World"
},
{
"type": "checkbox",
"id": "show_button",
"label": "Show Button",
"default": true
},
FRAGMENT.color-scheme,
FRAGMENT.section-spacing
],
"presets": [
{
"name": "Hello"
}
]
}
{% endschema %}- Register Your Component
// src/main.tsx
import { registerComponent, initRenderSystem } from './utils/helpers/renderComponents';
import { Hello } from './components/hello/Hello';
registerComponent('Hello', Hello);
initRenderSystem();- Build and Deploy
npm run build # Production build
npm run watch # Development with auto-reloadπ Advanced Features
Theme Style Analyzer
Automatically analyzes your existing Shopify theme styles and integrates them seamlessly:
# Automatically runs on first build
npm run buildWhat it does:
- π Scans
assets/*.cssfor theme styles - π― Extracts important selectors (
:root,.shopify-*,@keyframes, etc.) - π‘οΈ Scopes styles to avoid conflicts with React components
- π Searches for embedded CSS in Liquid files
- πΎ Generates
src/styles/theme-extracted.cssautomatically
Bidirectional Watch System
Monitor changes in both directions:
npm run watchFeatures:
- ποΈ Watches React component changes β Auto-updates Liquid
- π§ Detects manual Liquid file modifications
- β‘ Real-time synchronization
- π« Prevents infinite loops with smart debouncing
Fragment System
Create reusable Liquid schema fragments:
<!-- src/utils/schema-fragments/custom-colors.liquid -->
{
"type": "select",
"id": "custom_color",
"label": "Custom Color",
"options": [
{ "value": "red", "label": "Red" },
{ "value": "blue", "label": "Blue" }
]
}Use in your components:
{% schema %}
{
"settings": [
FRAGMENT.custom-colors,
FRAGMENT.color-scheme
]
}
{% endschema %}π Project Structure
your-theme/
βββ src/
β βββ components/
β β βββ hello/
β β βββ Hello.tsx # React component
β β βββ section.hello.liquid # Liquid template
β βββ styles/
β β βββ main.css # Main styles
β β βββ theme-extracted.css # Auto-generated theme styles
β βββ utils/
β β βββ schema-fragments/ # Reusable Liquid fragments
β βββ main.tsx # Entry point
βββ sections/
β βββ hello.liquid # Auto-copied from src/
βββ assets/
β βββ main.css # Built CSS
β βββ main.js # Built JS
βββ vite.config.ts # Vite configurationβοΈ Configuration
Vite Configuration
The library includes a pre-configured Vite setup optimized for Shopify:
// vite.config.ts - Already configured!
export default defineConfig(({ mode }) => ({
// β
Theme Style Analyzer
// β
Bidirectional Watch
// β
Auto Component Registry
// β
Fragment Injection
// β
Tailwind CSS v4
// β
CSS Extraction
// β
Asset Optimization
}));Tailwind Configuration
Fully configured with theme-aware settings:
// tailwind.config.js - Already configured!
export default {
content: [
'./src/**/*.{ts,tsx}',
'./src/components/**/*.liquid',
'./sections/**/*.liquid'
],
// β
Scoped to [data-component-root]
// β
Preflight disabled
// β
Custom Reactpify variables
// β
Animation safelist
};π― Best Practices
1. Component Structure
- Keep components in
src/components/[name]/ - Use consistent naming:
ComponentName.tsx+section.component-name.liquid - Always provide fallback HTML for SEO
2. Styling
- Use Tailwind classes for consistency
- Scope custom CSS with
.reactpify-*classes - Leverage CSS variables for theme integration
3. Liquid Templates
- Include
data-component-rootfor React mounting - Provide meaningful fallback content
- Use fragments for common schema patterns
4. Development Workflow
- Use
npm run watchfor development - Test both JavaScript-enabled and disabled scenarios
- Verify theme customizer compatibility
π Production Deployment
# Build for production
npm run build
# Files generated:
# β
assets/main.css - All styles combined
# β
assets/main.js - React components bundle
# β
sections/*.liquid - Updated Liquid templatesπ€ Contributing
- Fork the repository
- Create your feature branch:
git checkout -b feature/amazing-feature - Commit your changes:
git commit -m 'Add amazing feature' - Push to the branch:
git push origin feature/amazing-feature - Open a Pull Request
π License
MIT License - see LICENSE file for details.
π Support
- π Documentation
- π Issue Tracker
- π¬ Discussions
Made with β€οΈ for the Shopify community
