Laravel 10 - JS Not Working #1165
Replies: 3 comments
-
Shouldn't be too tricky to fix, few questions so that I can figure out what's going on :)
If it's available online, then feel free to drop a link and I'll take a look |
Beta Was this translation helpful? Give feedback.
-
Thank you @lrljoe for taking the time to help. This is a quick throw together side dev thing. I have to validate a bunch of emails from our main system, so I created a fresh Laravel 10 setup with Breeze. I have been coding for a long time, just haven't messed with L10 much yet, or Livewire, or Vite.. So it must be something simple because I didn't change much to break it. I forgot Alpine was included with Laravel, and I initially tried the CDN and it didn't work, noticed it was in the npm package file, so removed the CDN reference.. Vite was running with Version numbers below obtained from my package lock.
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>{{ config('app.name', 'Laravel') }}</title>
<!-- Fonts -->
<link rel="preconnect" href="https://fonts.bunny.net">
<link href="https://fonts.bunny.net/css?family=figtree:400,500,600&display=swap" rel="stylesheet" />
<!-- Scripts -->
@vite(['resources/css/app.css', 'resources/js/app.js'])
</head>
<body class="font-sans antialiased">
<div class="min-h-screen bg-gray-100 dark:bg-gray-900">
@include('layouts.navigation')
<!-- Page Heading -->
@if (isset($header))
<header class="bg-white dark:bg-gray-800 shadow">
<div class="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8">
{{ $header }}
</div>
</header>
@endif
<!-- Page Content -->
<main>
{{ $slot }}
</main>
</div>
</body>
</html> The view file is the email blade in my OP.
Tailwind Config (untouched): const defaultTheme = require('tailwindcss/defaultTheme');
/** @type {import('tailwindcss').Config} */
module.exports = {
content: [
'./vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php',
'./storage/framework/views/*.php',
'./resources/views/**/*.blade.php',
],
theme: {
extend: {
fontFamily: {
sans: ['Figtree', ...defaultTheme.fontFamily.sans],
},
},
},
plugins: [require('@tailwindcss/forms')],
};
import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
plugins: [
laravel({
input: [
'resources/css/app.css',
'resources/js/app.js',
],
refresh: true,
}),
],
});
Additionally, here is my resources/js/app.js (untouched): import './bootstrap';
import Alpine from 'alpinejs';
window.Alpine = Alpine;
Alpine.start(); Thanks again. |
Beta Was this translation helpful? Give feedback.
-
Okay, so there's a couple of things in here that aren't related to the package itself, but will stop you from progressing at all in terms of livewire: Vite is different to the classic WebPack, so there's a few caveats: Your app.js should reference your app.css when using Vite (I know, weird!) app.jsInclude your CSS via the app.js import './bootstrap';
import Alpine from 'alpinejs';
import focus from '@alpinejs/focus';
import '../css/app.css';
window.Alpine = Alpine;
window.Alpine.plugin(focus);
window.Alpine.start(); vite.config.jsNow you need to remove the reference to app.css from your vite config, as it is loaded via JS import { defineConfig } from 'vite';
import laravel from 'laravel-vite-plugin';
export default defineConfig({
plugins: [
laravel({
input: [
'resources/js/app.js',
],
refresh: true,
}),
],
}); tailwind.config.jsYou are missing:
const defaultTheme = require('tailwindcss/defaultTheme');
/** @type {import('tailwindcss').Config} */
module.exports = {
plugins: [require('@tailwindcss/forms')],
content: [
'./vendor/laravel/framework/src/Illuminate/Pagination/resources/views/*.blade.php',
'./vendor/rappasoft/laravel-livewire-tables/resources/views/**/*.blade.php',
'./storage/framework/views/*.php',
'./resources/views/**/*.blade.php',
],
darkMode: 'class',
theme: {
extend: {
fontFamily: {
sans: ['Figtree', ...defaultTheme.fontFamily.sans],
},
},
},
variants: {
extend: {
backgroundColor: ['responsive', 'dark', 'checked', 'disabled', 'hover', 'focus', 'active', 'even', 'odd'],
opacity: ['dark'],
overflow: ['hover'],
},
},
}; Remember to run your vite build/production after doing the above!! LayoutFinally, tweak your Layout, I've done the following:
<!DOCTYPE html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<meta name="csrf-token" content="{{ csrf_token() }}">
<title>{{ config('app.name', 'Laravel') }}</title>
<!-- Fonts -->
<link rel="preconnect" href="https://fonts.bunny.net">
<link href="https://fonts.bunny.net/css?family=figtree:400,500,600&display=swap" rel="stylesheet" />
<!-- Scripts -->
@vite('resources/js/app.js')
<!-- Livewire Styles -->
@livewireStyles
</head>
<body class="font-sans antialiased">
<div class="min-h-screen bg-gray-100 dark:bg-gray-900">
@include('layouts.navigation')
<!-- Page Heading -->
@if (isset($header))
<header class="bg-white dark:bg-gray-800 shadow">
<div class="max-w-7xl mx-auto py-6 px-4 sm:px-6 lg:px-8">
{{ $header }}
</div>
</header>
@endif
<!-- Page Content -->
<main>
{{ $slot }}
</main>
</div>
<!-- Livewire Scripts -->
@livewireScripts
</body>
</html> |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I have a fairly recent and basic install of Laravel 10. Vite is running, I have AlpinJS 3, and I tried to follow the docs the best I could.
My table loads, but it's like there is no javascript. Pagination doesn't work, neither does the search or column sorting. Nothing.
app/Http/Livewire/EmailTable.php
resources/views/emails/index.blade.php
app/Models/Email.php
There are no errors reported anywhere (laravel log file or debug console).
Thank you in advance :)
Beta Was this translation helpful? Give feedback.
All reactions