Skip to content

A starting point for Shopify Online Store 2.0 theme development using Tailwind CSS and Webpack.

License

Notifications You must be signed in to change notification settings

burovoordeboeg/shopify-theme-tailwind

 
 

Repository files navigation

Shopify Theme Tailwind CSS

This repository contains a starting point for Shopify Online Store 2.0 Theme development using Tailwind CSS and the default Dawn theme.

💡 On june 29, 2021, Shopify introduced a git-based workflow. To learn more, visit the create a theme guide or visit shopify.dev.

⚠️ When you want to use React, Hydrogen might be more useful for you than this starter.

Workflow

A short description of this workflow:

  • Edit theme locally using the Shopify CLI, Tailwind and Webpack
  • Commit changes to feature branch
  • Merge feature branch with main branch once feature is implemented
  • Automatically publish the production build to the dist branch using Github Actions
  • Shopify automatically syncs with the dist branch.

Technologies used

  • Tailwind CSS
    • The main css file is located in src/index.css
    • This file will be built to shopify/assets/index.css
  • Webpack
    • All src/entries/**/*.{js,jsx,ts,tsx} files will be sourced as webpack entry and the output file can be found in the assets directory. All build bundles get the extension .bundle.js instead of .{js,jsx,ts,tsx}.
  • Shopify CLI
  • Github Actions to deploy the theme to the dist branch on push to the main branch
  • Github Actions to test for build errors on every Pull Request

You can copy the Lighthouse Github Action from the original Dawn theme repository to track the performance of your theme on every push.

Disadvantages

  • Because an extra build step is involved, you need to manually copy changes made in the Shopify theme editor. Those changes will be committed to the dist branch.
  • The tailwind normalize.css breaks some default styling of the Dawn theme.

Getting started

Prerequisites

Installation

Run the following commands:

git clone git@github.com:wesselvanree/shopify-theme-tailwind.git
cd shopify-theme-tailwind
rm -rf .git
git init
npm install

Make sure the shopify/assets/index.css output file is included in the shopify/layout/theme.liquid file. Add this line of code under the base.css stylesheet tag.

<!-- line 113 -->
{{ 'index.css' | asset_url | stylesheet_tag }}

The same holds for all .bundle.js files created by Webpack. You need to insert the script tags on the places where you want to use the Webpack bundle.

Once you've made your first commit, a dist branch will be created on Github. Use the Shopify Github integration to sync your theme with the dist branch by going to your admin dashboard > Online Store > Themes > Add Theme > Connect from Github.

Using React

To use React, install the following packages:

npm install react react-dom

Now you can use React in your javascript files.

Usage

Development

You will need 2 terminal windows:

  1. Serve your Shopify theme

    • First, log in to your store if you was not logged in already.
      shopify login --store your-store-name.myshopify.com
    • Serve your theme to your development store
      npm run shopify
  2. Compile your code: in a separate terminal window, run npm start to start watch for file changes and build development bundles.

If you prefer to use one single terminal window, you can customize the scripts in package.json.

Production

This repository contains a Github Action that uses JamesIves/github-pages-deploy-action@4.1.4. This action does not activate Github Pages in your repository but just commits the build to another branch. Currently, the action is configured to deploy the build to the dist branch. You can easily customize this by editing .github/workflows/deploy.yml.

Alternatively, you can create the build manually. Run npm run build to build for production. You can use the Shopify Github integration to track a branch in your Github repository.

Final notes

Further reading

Suggestions

If you have any suggestions to improve this repository, please open an issue. I would be happy to hear from you.

About

A starting point for Shopify Online Store 2.0 theme development using Tailwind CSS and Webpack.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Liquid 67.2%
  • CSS 25.2%
  • JavaScript 7.6%