FireBlade's avatar

Ugly welcome.blade.php page in production following this guide- https://docs.docker.com/guides/frameworks/laravel/production-setup/#create-a-dockerfile-for-nginx-production

I have a single-page app using only the welcome.blade.php file:

This is the NGINX container Dockerfile:

FROM debian AS builder

# Install Node.js and build tools
RUN apt-get update && apt-get install -y --no-install-recommends \
    curl \
    nodejs \
    npm \
    && apt-get clean && rm -rf /var/lib/apt/lists/* /tmp/* /var/tmp/*

# Set working directory
WORKDIR /var/www

# Copy Laravel application code
COPY ./src/. /var/www

RUN npm install && npm run build

FROM nginx:1.21-alpine

COPY --from=builder /var/www/public /var/www/public

WORKDIR /var/www/public

EXPOSE 443
CMD ["nginx", "-g", "daemon off;"]

The problem is that once deployed in production, the page looks ugly:

  1. The custom font Epilogue is not being used. Its actually using a font that I believe I used once sometime ago.
  2. Tailwind CSS on the header element is not applied.

On my development machine, the page looks OK when running Vite development server. Any help is appreciated...

0 likes
5 replies
Tray2's avatar

You need to run npm run build and make sure you deploy those files.

FireBlade's avatar

The Dockerfile has the command:

RUN npm install && npm run build

and the output is deployed here:

COPY --from=builder /var/www/public /var/www/public

Tray2's avatar

I would start by making sure that the JS and CSS is in the /public/assets directory, because they likely aren't.

FireBlade's avatar

Looks like this line is not processed in production:

<!-- Scripts -->
        @vite(['resources/css/app.css', 'resources/js/app.js'])
FireBlade's avatar

I have also realized that this Tailwind style is not working in a Blade component in production ( this is not in welcome.blade.php as noted above) :

html class="bg-green-700">

forcing me to resort to plain css: html style="background-color:#46854f

My vite.config.js

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

export default defineConfig({
    server: {
        host: '0.0.0.0',
        port: 5173,
        strictPort: true,
        hmr: {
            host: '127.0.0.1'
        }
    },
    plugins: [
        laravel({
            input: [
                'resources/css/app.css',
                'resources/js/app.js',
            ],
            refresh: [
                ...refreshPaths,
                'app/Http/Livewire/**',
            ],
        }),
    ],
});

Am in Laravel 9.52.21

Please or to participate in this conversation.