raloseq's avatar

TailwindsCSS dont load

Hello, i have a problem, tailwind css dont load. I can see that styles work only in welcome.blade.php where i have inline styles. Rest of app is without loaded styles even auth views generated by laravel.

0 likes
22 replies
Sinnbeck's avatar

Can you give some more context ? Are you compiling it with vite or mix ? Did you run npm run build? Did you add it to app.css ?

raloseq's avatar

@Sinnbeck Im using docker, running npm run dev only in container and im using vite

app.css
@tailwind base;
@tailwind components;
@tailwind utilities;
Sinnbeck's avatar

@raloseq Did you open the port in the container? Check the browser console for errors

raloseq's avatar

@Sinnbeck In console i can see

Failed to load resource: net::ERR_CONNECTION_REFUSED app.js:1
Failed to load resource: net::ERR_CONNECTION_REFUSED app.css:1
Failed to load resource: net::ERR_CONNECTION_REFUSED client:1
raloseq's avatar

@Sinnbeck

version: "3.8"

networks:
  laravel:

services:
  nginx:
    image: nginx:stable-alpine
    ports:
      - "80:80"
    volumes:
      - .:/var/www/html
      - ./default.conf:/etc/nginx/conf.d/default.conf
    depends_on:
      - php
      - mysql
    networks:
      - laravel

  mysql:
    image: mariadb:latest
    restart: unless-stopped
    tty: true
    ports:
      - "${DB_PORT}:3306"
    environment:
      - MYSQL_DATABASE=${DB_DATABASE}
      - MYSQL_USERNAME=${DB_USERNAME}
      - MYSQL_PASSWORD=${DB_PASSWORD}
      - MYSQL_ROOT_PASSWORD=${DB_PASSWORD}
    networks:
      - laravel

  php:
    build:
      context: .
      dockerfile: Dockerfile
    volumes:
      - .:/var/www/html
    ports:
      - "8000:8000"
    networks:
      - laravel
Sinnbeck's avatar

@raloseq which container is running npm run dev? You need to open the port in that container

Sinnbeck's avatar

@raloseq ok if I recall correctly, it is running on port 5173 by default. It should tell you in the error in the console

    ports:
      - "8000:8000"
      - "5173:5173"
raloseq's avatar

@Sinnbeck ye i did dcker-compose build --no-cache then docker-compose up and run command npm run dev etc..

raloseq's avatar

@Sinnbeck php container, btw im using nginx container to host app

 0.0.0.0:5173->5173/tcp, 0.0.0.0:8000->8000/tcp, 9000/tcp
raloseq's avatar

@Sinnbeck I mean

3a84b8772af3   nginx:stable-alpine     0.0.0.0:80->80/tcp 
                                        
6aac0b4ec028   mariadb:latest         0.0.0.0:3306->3306/tcp

50670f470ee4   php   0.0.0.0:5173->5173/tcp, 0.0.0.0:8000->8000/tcp, 9000/tcp  

it is in php container or i misunderstood. I have installed npm in container so i need to change vite config i guess.

Sinnbeck's avatar

@raloseq as long as it's the same container it should work. If not I will need more information

raloseq's avatar

@Sinnbeck Hmm what information do u need? Im doing composer install, npm install etc. in php dockerfile but im opening localhost:80 (nginx). Im not using php artisan serve.

raloseq's avatar

@MohamedTammam vite.config.js

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

export default defineConfig({
    server: {
        host: '127.0.0.1'
      },
    plugins: [
        laravel({
            input: [
                'resources/css/app.css',
                'resources/js/app.js',
            ],
            refresh: true,
        }),
    ],
});

tailwind.config.js

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: ['Nunito', ...defaultTheme.fontFamily.sans],
            },
            backgroundImage: {
                'hero-pattern': "url('./storage/app/images/front-page.jpg')",
            },
        },
    },

    plugins: [require('@tailwindcss/forms')],
};

raloseq's avatar

@MohamedTammam Bump i added vite.config.js

export default defineConfig({
    server: {
        host: 'localhost'
      },
    plugins: [
        laravel({
            input: [
                'resources/css/app.css',
                'resources/js/app.js',
            ],
            refresh: true,
        }),
    ],
});

dev: "vite --host", and still nothing docker exec -it -u www php-container npm run dev gives me:

VITE V3.1.3
Local: localhost:5173
Network 172.23.0.3:5173
Laravel v9
APP_URL localhost
Jessie's avatar

Hi, this seems to be an old question, but just for those who will also be looking for an answer, I'm not really sure about the specifics, but it seems to be an issue with laravel blocking access to non-public files, so running 'npm run build' will build the css files to the public directory, it will generate a 'app-{hash}.css' in the '/public/build/assets/' directory and you can import this public css to the blade using ''

Please or to participate in this conversation.