compile multiple tailwind.config.js with laravel-vite plugin

Overview

Compile multiple tailwind css from different tailwind.config.js files using laravel-vite

If do you want to compile two or more tailwind css from different tailwind.config.js files, then you have to follow this guide.

SCENARIO:

I want to create two tailwind.config.js files one config for FRONTEND and second for BACKEND.

How can I do it with laravel-vite, because laravel is new tool for asset compilation but I am familiar with laravel webpack.mix package?

Yes, it is possible to compile separate tailwind.config.js files for each tailwind css assets.

just follow these steps with me to implement this in laravel project.

I have also created a detail youtube video tutorial for it.

watch now

Alt text

let's start!!!

STEP 1:

Create two files of vite.config.js. One for frontend and second for backend

file 1: vite.frontend.config.js

import { defineConfig } from 'vite';
import laravel, { refreshPaths } from 'laravel-vite-plugin';

export default defineConfig({
    plugins: [
        laravel({
            input: [
                'resources/frontend/frontend-tailwind.css',
            ],
            refresh: [
                ...refreshPaths,
            ],
            buildDirectory: '/frontendAssets',
        }),
    ],
    css: {
        postcss: {
            plugins: [
                require("tailwindcss/nesting"),
                require("tailwindcss")({
                    config: "./frontend-tailwind.config.js",
                }),
                require("autoprefixer"),
            ],
        },
    },
});

file 2: vite.backend.config.js

import { defineConfig } from 'vite';
import laravel, { refreshPaths } from 'laravel-vite-plugin';

export default defineConfig({
    plugins: [
        laravel({
            input: [
                'resources/backend/dashboard/backend-tailwind.css',
            ],
            refresh: [
                ...refreshPaths,
            ],
            buildDirectory: '/backendAssets/dashboard',
        }),
    ],
    css: {
        postcss: {
            plugins: [
                require("tailwindcss/nesting"),
                require("tailwindcss")({
                    config: "./backend-tailwind.config.js",
                }),
                require("autoprefixer"),
            ],
        },
    },
});

STEP 2:

Create two tailwind.config.js files for frontend and backend.

file 1: frontend-tailwind.config.js

/** @type {import('tailwindcss').Config} */
module.exports = {
    content: [
      "./resources/**/*.blade.php",
      "./resources/**/*.js",
      "./resources/**/*.vue",
    ],
    theme: {
      extend: {},
    },
    plugins: [],
  }

file 2: backend-tailwind.config.js

/** @type {import('tailwindcss').Config} */
module.exports = {
    content: [
      "./resources/**/*.blade.php",
      "./resources/**/*.js",
      "./resources/**/*.vue",
    ],
    theme: {
      extend: {},
    },
    plugins: [],
  }

STEP 3:

Now open package.json and add follwoing two scripts

"scripts": {
    "dev": "vite",
    "build": "vite build",
    "build:backend": "vite build --config vite.backend.config.js",
    "build:frontend": "vite build --config vite.frontend.config.js"
},

STEP 4:

Open /routes/web.php file and create follwoing two routes

Route::get('/dashboard', function(){
    return view('backend-dashboard');
});
Route::get('/frontend', function(){
    return view('frontend-interface');
});

STEP 5:

Create tow blade.php views template in /resources/views

file 1: frontend-interface.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
    {{
        Vite::useBuildDirectory('/frontendAssets')
    }}
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    @vite('resources/frontend/frontend-tailwind.css')

</head>
<body>
    <div style="width:50%; margin:100px auto">
        <h1>FrontEnd Interface</h1>
        <button class="backend" style="padding: 10px; font-size:30px">
            red button for frontend
        </button>
    </div>
</body>
</html>

file 2: backend-dashboard.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
    {{
        Vite::useBuildDirectory('/backendAssets/dashboard')
    }}
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    @vite('resources/backend/dashboard/backend-tailwind.css')

</head>
<body>
    <div style="width:50%; margin:100px auto">
        <h1>backend dashboard</h1>
        <button class="backend" style="padding: 10px;font-size:30px">
            blue button for backend
        </button>
    </div>
</body>
</html>

STEP 6:

Now crate a /resources/backend/dashboard/backend-tailwind.css file and paste follwoing code.

@tailwind base;
@tailwind components;
@tailwind utilities;

.backend{
    @apply bg-blue-500;
}

Crate one more /resources/frontend/frontend-tailwind.css file and paste follwoing code.

@tailwind base;
@tailwind components;
@tailwind utilities;

.frontend{
    @apply bg-red-500;
}

STEP 7:

so we have setup a demo laravel app, just run follwoing command in terminal and run you project.

npm run build:backend
npm run build:frontend

License

The software licensed under the MIT license.

You might also like...
A Laravel 8 and Vue 3 SPA boilerplate using tailwind styling and sanctum for authentication :ghost:
A Laravel 8 and Vue 3 SPA boilerplate using tailwind styling and sanctum for authentication :ghost:

Laravel Vue Sanctum SPA Laravel and vue spa using tailwind (laravel/ui looks) for styling and sanctum for authentification Features Laravel 8 Vue + Vu

Initial template to start your awesome Laravel, Tailwind and Vue projects
Initial template to start your awesome Laravel, Tailwind and Vue projects

Features Laravel 8.* Tailwind 2.1 Ready and Loaded @tailwindcss/typography @tailwindcss/forms Dark mode ready All variants enabled by default Vue 2, V

Clone do instagram utilizando Laravel, Vue, Inertia, Tailwind

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

A Laravel dashboard front-end scaffolding preset for Tailwind CSS - Support RTL out of the box.
A Laravel dashboard front-end scaffolding preset for Tailwind CSS - Support RTL out of the box.

🔥 Laravel tailwind css dashboard preset A Laravel dashboard front-end scaffolding preset for Tailwind CSS - Support RTL out of the box. Usage Fresh i

A Laravel-Vue-Tailwind SAAS Starter Kit.

Super SAAS Template My name is Julien Nahum, I've founded multiple Software-As-A-Service companies. This repo is the base I'm using to create a new SA

An account management Panel based on Laravel7 framework. Include multiple payment, account management, system caching, admin notification, products models, and more.

ProxyPanel 简体中文 Support but not limited to: Shadowsocks,ShadowsocksR,ShadowsocksRR,V2Ray,Trojan,VNET Demo Demo will always on dev/latest code, rather

A plugin to purge your unused assets, disabled products, and more.

Purge Assets for Craft CMS Purge Assets is a Craft plugin for super-simple purge of assets and products, either via the control panel or with console

WP React Plugin Boilerplate - WordPress Setting via React and Rest API
WP React Plugin Boilerplate - WordPress Setting via React and Rest API

WP React Plugin Boilerplate is a starter WordPress plugin to develop WordPress Plugin via React and Rest API. WP React Plugin Boilerplate WP React Plu

Wordpress, ReactJS, GUTENBERG, plugin
Wordpress, ReactJS, GUTENBERG, plugin

Плагін для Wordpress, який розширює функціонал редактора Gutenderg, реалізуючи можливість створювати клієнтську частину використовуючи потужні можливо

Owner
Muhammad Amir
I am a software engineer graduated from virtual university of Pakistan.
Muhammad Amir
React laravel starter kit with tailwind css and vite js(laravel 9)

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Jerald Tonmoy Dias 2 Dec 23, 2022
Starter - Laravel, Vue, Inertia, Tailwind, Vite

Starter - Laravel, Vue, Inertia, Tailwind, Vite Laravel-vite preset Laravel 9 Vue 3 Inertia Tailwind Vite Including Sail (Docker). php 8.1 mysql 8.0 p

Anatoliy 6 Dec 28, 2022
Laravel Starter With Laravel, Vite, Vue 2, Inertia.js, Ziggy

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Oskars Germovs 1 Oct 29, 2021
Laravel Starter With Laravel, Vite, Vue 2, Inertia.js, Ziggy, Typescript

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Oskars Germovs 1 Oct 29, 2021
A starter template from which to build Laravel + Vite apps

Stack The Laravel framework is fast, clean, and filled with best practices. In this stack, it will handle the backend as an API. The Laravel Vite pack

null 7 Nov 14, 2022
Repositorio del tutorial CRUD Laravel 9 y Vue 3 usando Vite

About Laravel Laravel is a web application framework with expressive, elegant syntax. We believe development must be an enjoyable and creative experie

Alfredo Morales 2 Sep 29, 2022
CodeIgniter 3 + Vue.js 3 + Vite with supported Hot Module Replacement (HMR)

CodeIgniter 3 + Vue.js 3 + Vite Looking for Vue 2? Please check branch vue2 Just a basic example how to integrating CodeIgniter 3 + Vue.js 3 + Vite wi

Nur Muhammad 44 Dec 15, 2022
A helper method to generate absolute asset URL's to Vite assets

Laravel vite() helper method A super simple Laravel helper to fill the void that Laravel Mix left. Mix had a helper, aptly named mix() that would retu

 MotoMediaLab 17 Dec 2, 2022
Hydra is a zero-config API boilerplate with Laravel Sanctum that comes with excellent user and role management API out of the box

Hydra - Zero Config API Boilerplate with Laravel Sanctum Hydra is a zero-config API boilerplate with Laravel Sanctum and comes with excellent user and

Hasin Hayder 858 Dec 24, 2022
Basic Crud Generator (With Code Files, like GII (YII2)) Using Laravel, Livewire and Tailwind CSS

LiveCrud Live Crud Generator. This package generates Basic Crud with Livewire. Features Generate Complete Crud With Livewire Component and Blade Files

Ritesh Singh 28 Oct 12, 2022