dan3460's avatar

In Vite, where to put custom css

I moving an app to Laravel 10, with Laravel-Mix i have added some custom css classes inside the resource/app.css

@tailwind base;
@tailwind components;
@tailwind utilities;

@layer components {
    .line-danger {
        @apply border text-center h-4 bg-red-800 text-white;
    }

    .line-warning {
        @apply border text-center h-4 bg-red-400;
    }

    .line-attention {
        @apply border text-center h-4 bg-yellow-400;
    }

    .line-normal {
        @apply border text-center h-4;
    }

    .route-lancaster {
        @apply border text-center h-4 bg-blue-400;
    }

    .line-waiting {
        @apply border text-center h-4 bg-green-600 text-white font-bold;
    }

    .line-delivered {
        @apply border text-center h-4 bg-blue-400 text-white font-bold;
    }

    .customer-danger {
        @apply border text-center h-4 bg-red-800 text-white font-bold;
    }

    .customer-warning {
        @apply border text-center h-4 bg-red-400 font-bold;
    }

    .customer-attention {
        @apply border text-center h-4 bg-yellow-400 font-bold;
    }

    .customer-normal {
        @apply border text-center h-4 font-bold;
    }
}

This is probably obvious to everyone, but it seems that the @layer directive is not understood by Vite. Where should I put my custom classes?

0 likes
4 replies
LaryAI's avatar
Level 58

In Vite, custom CSS classes can be added to the app.css file or a separate CSS file can be created and imported into the app.js file.

To add custom CSS classes to the app.css file, simply add them below the @tailwind directives.

To create a separate CSS file, create a new file in the resources/css directory (e.g. custom.css) and add the custom classes to it. Then, import the file into the app.js file using the import statement:

import './css/custom.css';

Make sure to run npm run dev or npm run watch to compile the changes.

3 likes
bvfi-dev's avatar

@LaryAI Small correction, it would be: import '../css/custom.css'; since app.js would be in the /resources/js/ directory. One dot will throw an error.

1 like

Please or to participate in this conversation.