bigcommerce-cornerstone-tailwindcss-integration Tailwind Templates

Bigcommerce Cornerstone Tailwindcss Integration

How to Integrate TailwindCSS with BigCommerce's Cornerstone Theme

Adding TailwindCSS to your BigCommerce Cornerstone theme allows you to customize your store's design with ease. In this guide, I’ll walk you through each step to set up TailwindCSS within the Cornerstone theme using Webpack.

Why Use TailwindCSS with Cornerstone?

BigCommerce’s Cornerstone theme uses Webpack for asset management, which makes it straightforward to configure the TailwindCSS build process. TailwindCSS simplifies creating responsive designs and helps keep CSS manageable by only adding the styles you need.

Step 1: Install TailwindCSS and PostCSS

First, navigate to your Cornerstone theme directory and install the necessary dependencies for TailwindCSS and PostCSS:

npm install -D tailwindcss postcss-loader autoprefixer css-loader style-loader

This will install:

  • tailwindcss: The core TailwindCSS package.
  • postcss-loader: A loader for Webpack to process CSS files with PostCSS.
  • autoprefixer: Adds vendor prefixes for better browser compatibility.
  • css-loader and style-loader: Required by Webpack to manage CSS files.

Step 2: Configure TailwindCSS and PostCSS

Next, initialize the Tailwind configuration file to customize Tailwind settings if needed:

npx tailwindcss init

Create a postcss.config.js file in your theme’s root directory. This file will configure PostCSS to use TailwindCSS and Autoprefixer.

// postcss.config.js
module.exports = {
  plugins: {
    tailwindcss: {},
    autoprefixer: {},
  },
};

In the tailwind.config.js file, define the paths for purging unused CSS to keep your final CSS bundle as small as possible.

// tailwind.config.js
module.exports = {
  content: [
    './templates/**/*.html',
    './templates/**/*.hbs',
    './assets/js/**/*.js',
  ],
  theme: {
    extend: {},
  },
  plugins: [],
};

Step 3: Update Webpack Configuration

To enable CSS processing with TailwindCSS, modify the Webpack configuration.

In webpack.common.js, add a rule for processing .css files with PostCSS:

module: {
  rules: [
    // Existing JavaScript rule...
    {
      test: /\.css$/,
      use: [
        'style-loader', 
        'css-loader',
        'postcss-loader', // Add postcss-loader for TailwindCSS processing
      ],
    },
  ],
},

Step 4: Create and Configure a Tailwind CSS File

In the assets/css directory, create a tailwind.css file to import Tailwind’s base styles, components, and utilities:

/* assets/css/tailwind.css */
@tailwind base;
@tailwind components;
@tailwind utilities;

Then, import this tailwind.css file in your main JavaScript file (assets/js/app.js) to include Tailwind styles in the build process:

import '../css/tailwind.css';

Step 5: Start the Development Server

Finally, start your local development server to see TailwindCSS in action:

stencil start

Your Cornerstone theme should now include TailwindCSS, allowing you to easily apply utility classes and customize the look of your BigCommerce store. TailwindCSS’s utility-first approach keeps your styles consistent and maintainable, especially in large-scale projects.


This guide covers the essentials for integrating TailwindCSS into BigCommerce’s Cornerstone theme using Webpack. If you're looking to enhance the design and maintainability of your store’s front end, TailwindCSS is an excellent choice for rapid customization and responsive design. Enjoy building with Tailwind!

Top categories

Loading Svelte Themes