Installing Laravel, Alpine.js + Tailwind CSS + Livewire
Installing Alpine.js and Tailwind CSS Write the Laravel Mix configuration resources/js/app.js resurces/sass/app/scss Run the tailwindcss command Edit tailwind.c

Installing Alpine.js and Tailwind CSS Write the Laravel Mix configuration resources/js/app.js resurces/sass/app/scss Run the tailwindcss command Edit tailwind.c

yarn add alpinejs -D
yarn add tailwindcss -Dyarn add @ryangjchandler/spruce -D
yarn add @tailwindcss/ui -D
yarn add @tailwindcss/custom-forms -DWrite the Laravel Mix configuration
const mix = require('laravel-mix');
const tailwindcss = require('tailwindcss');
mix.js("resources/js/app.js", "public/js/app.js")
.sass("resources/sass/app.scss", "public/css/app.css")
.options({
processCssUrls: false,
postCss: [
tailwindcss('./tailwind.config.js')
],
})
.sourceMaps();
if (mix.inProduction()) {
mix.version();
}resources/js/app.js
require('./bootstrap');
import 'alpinejs'resurces/sass/app/scss
/**
* This injects Tailwind's base styles, which is a combination of
* Normalize.css and some additional base styles.
*
* You can see the styles here:
* https://unpkg.com/tailwindcss/dist/base.css
*/
@tailwind base;
/**
* Remove the default box-shadow for invalid elements to prevent
* inputs in Livewire components showing with a
* red border by default in Firefox.
*
* See: https://github.com/laravel-frontend-presets/tall/issues/7
*/
input:invalid, textarea:invalid, select:invalid {
box-shadow: none;
}
/**
* This injects any component classes registered by plugins.
*/
@tailwind components;
/**
* Here you would add any of your custom component classes; stuff that you'd
* want loaded *before* the utilities so that the utilities could still
* override them.
*
* Example:
*
* .btn { ... }
* .form-input { ... }
*/
/**
* This injects all of Tailwind's utility classes, generated based on your
* config file.
*/
@tailwind utilities;
/**
* Here you would add any custom utilities you need that don't come out of the
* box with Tailwind.
*
* Example :
*
* .bg-pattern-graph-paper { ... }
* .skew-45 { ... }
*/Run the tailwindcss command
npx tailwindcss initEdit tailwind.config.js
const defaultTheme = require('tailwindcss/defaultTheme');
module.exports = {
theme: {
extend: {
fontFamily: {
sans: ['Inter var', ...defaultTheme.fontFamily.sans],
},
},
},
variants: {},
purge: {
content: [
'./app/**/*.php',
'./resources/**/*.html',
'./resources/**/*.js',
'./resources/**/*.jsx',
'./resources/**/*.ts',
'./resources/**/*.tsx',
'./resources/**/*.php',
'./resources/**/*.vue',
'./resources/**/*.twig',
],
options: {
defaultExtractor: (content) => content.match(/[\w-/.:]+(?<!:)/g) || [],
whitelistPatterns: [/-active$/, /-enter$/, /-leave-to$/, /show$/],
},
},
plugins: [
require('@tailwindcss/custom-forms'),
require('@tailwindcss/ui'),
],
};Run the command
yarn dev
And... it works... Success...
composer require livewire/livewireEdit the Blade file
...
@livewireStyles
</head>
<body>
...
@livewireScripts
</body>
</html>yarn add turbolinks -DEdit resources/js/app.js
require('./bootstrap');
import 'alpinejs'
var Turbolinks = require("turbolinks")
Turbolinks.start()There is an x-show issue in Alpine.js... You can fix it with
https://github.com/alpinejs/alpine#x-cloak
x-cloak.
https://dev.to/hus_hmd/alpine-js-responsive-x-cloak-3blp
However, when using Alpine.js + Turbolinks, an x-show caching issue also occurs... I'll write about this later.
https://github.com/alpinejs/alpine-turbolinks-adapter
An Alpine Turbolinks adapter like this is also in the works.... Just for reference, just for reference...
I wonder when Vue 3 and Nuxt 3 will be released... Time has already flown by, and apparently Laravel 8 is going to be released... Good grief... (I haven't developed a single thing ' _')