juu073's avatar

Simple guide on how to get started with Laravel, Tailwind, HeadlessUI without going all-out Vue?

I'm stuck and going around in circles, trying to get started. Each time I've found a guide to help, there's always something different that's significantly changed, e.g., Vite has replaced Laravel Mix.

I want to start a new project in Laravel. I don't want to build a SPA. The only thing I want to use Vue for is to load components of Headless UI. So I don't need/want to use Inertia. Just looking to get started with want to use TailwindCSS (and I have HeadlessUI to use the compoents provided by TailwindUI through Vue).

I've installed everything: composer create-project laravel/laravel testproject cd testproject composer require laravel/breeze --dev php artisan breeze:install npm install -D tailwindcss autoprefixer postcss npm install vue npm install @headlessui/vue@latest npm install @heroicons/vue

I edited tailwind.config.is to include PHP and JS files in resources, etc.

I'm playing "whack-a-mole" to fix things with what I'm guessing based upon them not being what I would traditionally do outside of Laravel to use Tailwind and whatnot are workarounds that probably aren't best practice.

So can someone sort of give me the steps as to what goes where in terms of Javascript imports, etc., go get this going (and offer any corrections to what I've installed above, if needed)?

Thank you in advance for any assistance you can profide.

0 likes
4 replies
LaryAI's avatar
Level 58

To get started with Laravel, Tailwind, and HeadlessUI without using Vue for anything other than loading HeadlessUI components, follow these steps:

  1. Install Laravel using the command composer create-project laravel/laravel project-name.
  2. Install Laravel Breeze for authentication using the command composer require laravel/breeze --dev and run php artisan breeze:install to install it.
  3. Install TailwindCSS, Autoprefixer, and PostCSS using the command npm install -D tailwindcss autoprefixer postcss.
  4. Create a tailwind.config.js file in the root directory of your project and add the following code:
module.exports = {
  purge: [
    './resources/**/*.blade.php',
    './resources/**/*.js',
    './resources/**/*.vue',
  ],
  darkMode: false,
  theme: {
    extend: {},
  },
  variants: {},
  plugins: [],
}
  1. Install HeadlessUI and Heroicons using the commands npm install @headlessui/vue@latest and npm install @heroicons/vue.
  2. In your app.blade.php file, add the following code to the head section:
<head>
  <!-- Other head tags -->
  <link rel="stylesheet" href="{{ mix('css/app.css') }}">
  @yield('head')
</head>
  1. In your app.scss file, add the following code:
@import 'tailwindcss/base';
@import 'tailwindcss/components';
@import 'tailwindcss/utilities';
  1. In your app.js file, add the following code:
import { createApp } from 'vue';
import { Headlessui } from '@headlessui/vue';
import { HeroIcon } from '@heroicons/vue';

const app = createApp({});

app.component('Headlessui', Headlessui);
app.component('HeroIcon', HeroIcon);

app.mount('#app');
  1. In your webpack.mix.js file, add the following code:
const mix = require('laravel-mix');

mix.js('resources/js/app.js', 'public/js')
   .sass('resources/sass/app.scss', 'public/css')
   .vue()
   .postCss('resources/css/app.css', 'public/css', [
      require('tailwindcss'),
   ]);
  1. Run the command npm run dev to compile your assets.

With these steps, you should be able to use TailwindCSS and HeadlessUI components in your Laravel project without using Vue for anything other than loading the components.

CamKem's avatar

There is no simple answer really, you are wanting to use Laravel / Blade / Tailwind / Vue(Headless UI), This is at least 5 & half frameworks you need a basic understanding of to pull it all together. You really have to put in the time & learn the frameworks (all of them!) you want to use. So if you want to utilise headless UI, you will need to understand Vue. I suggest try these series / videos out.

1 like
juu073's avatar

@CamKem I've got a more than basic understanding of all but Vite, I would say. I think where I'm stuck is how Vite is pulling them all together. I've used Tailwind on more projects than I can count, Vue and Headless UI on several, Laravel and Blade (and Tailwind) on at least a dozen. Haven't worked with Laravel 10 yet, though.

Anyway, I started over and did a fresh install of everything, and I'm guessing a large chunk of my issue was I had something that I tried installing hanging around that was interfering, because I've got it working except mounting to an id element wipes out everything in the DOM. I've picked apart the JS and CSS files that Vite is generating and they're correct.

CamKem's avatar

@jwagner - well thats good then, if you have the knowledge on using all of the frameworks in seperate instances, now you just need to get it all working together. Can i ask though, if you have this knowledge then why not just use Inertia and Vue for your main Views, instead of blade? I mean you can use both blade component & Vue easily. You can achieve this by mounting your Vue portion of the app to specifc Div's. If you are certain you want to stick mainly with blade & a little bit of Vue to utilise HeadleasUI, then you might want to try Splade, which utilises Renderless Vue Components for SPA functionality, so you can work purely in blade. This gives a pretty good explanation of the differences between Splade & Inertia (https://splade.dev/docs/splade-vs-inertia) - and clearly states that you can utilise Vue libraries within your Blade components & is configured so, if you install a Splade & I recommend a starter pack.

Also, Splade has many component, that might be fine for your use case, such as Form Elements, Errors, Modal, Toggle, Flash Message & most importantly for HeadlessUI Custom Components

Anyway, I hope that might help. If you have a more specific question, I am happy to help out where I can. But without knowing the specific problem & seeing your code, it's next to impossible to make a recommendation.

Please or to participate in this conversation.