Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

dojocreative's avatar

Laravel 8 + Tailwind PurgeCSS

I'm trying to deploy an app. I am using mix as configured out of the box.

When I run npm run production

I expect that the app.css file to be purged of extra tailwind classes, but the resulting file is 4.5MB

My webpack.mix.js file looks like:

const mix = require('laravel-mix');

/*
 |--------------------------------------------------------------------------
 | Mix Asset Management
 |--------------------------------------------------------------------------
 |
 | Mix provides a clean, fluent API for defining some Webpack build steps
 | for your Laravel applications. By default, we are compiling the CSS
 | file for the application as well as bundling up all the JS files.
 |
 */

mix.js('resources/js/app.js', 'public/js').postCss('resources/css/app.css', 'public/css', [
    require('postcss-import'),
    require('tailwindcss'),
    require('autoprefixer'),
]);

mix.copy('resources/img', 'public/img');

My tailwind.config.js file looks like:

const defaultTheme = require('tailwindcss/defaultTheme');
const colors = require('tailwindcss/colors');

module.exports = {
    purge: {
        content: [
            './storage/framework/views/*.php',
            './resources/views/**/*.blade.php'
        ]
    },
    theme: {
        extend: {
            fontFamily: {
                sans: ['Nunito', ...defaultTheme.fontFamily.sans],
            },
            colors: {
                lime: colors.lime,
                orange: colors.orange
            }
        },
    },

    variants: {
        extend: {
            opacity: ['disabled'],
        },
    },

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

Am I missing something? The app is not very big or complex, so I know I'm not using all 4.5mb of tailwind.

0 likes
6 replies
srasch's avatar

Which versions of Tailwind and Laravel Mix do you use?

dojocreative's avatar

Here's my package.json It's pretty much what comes out of the box with laravel 8 + the vue stuff.

{
    "private": true,
    "scripts": {
        "dev": "npm run development",
        "development": "mix",
        "watch": "mix watch",
        "watch-poll": "mix watch -- --watch-options-poll=1000",
        "hot": "mix watch --hot",
        "prod": "npm run production",
        "production": "mix --production"
    },
    "devDependencies": {
        "@tailwindcss/forms": "^0.2.1",
        "alpinejs": "^2.7.3",
        "autoprefixer": "^10.1.0",
        "axios": "^0.21",
        "laravel-mix": "^6.0.6",
        "lodash": "^4.17.19",
        "postcss": "^8.2.1",
        "postcss-import": "^12.0.1",
        "tailwindcss": "^2.0.2",
        "vue": "^2.6.12",
        "vue-loader": "^15.9.6",
        "vue-template-compiler": "^2.6.12"
    }
}
lemmon's avatar
lemmon
Best Answer
Level 28

@dojocreative

module.exports = {
    purge: {
       enable: true,
        content: [
            './storage/framework/views/*.php',
            './resources/views/**/*.blade.php'
        ]
    },

try enabling manually and see what happens

1 like
lemmon's avatar

@dojocreative

Otherwise try reducing it to this:

module.exports = {
    purge: ['./storage/framework/views/*.php', './resources/views/**/*.blade.php'],

and running production. this works for me. AND of course what you have after in your file

Please or to participate in this conversation.