Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tailwind css file very big 2.42 mib how can i reduce size this file am using laravel?

enter image description here Tailwind css file very big 2.42 mib how can i reduce size this file am using laravel ?

like image 524
Mahmoud Ayad Avatar asked Oct 17 '25 00:10

Mahmoud Ayad


2 Answers

The best strategy is to use generate a specific CSS specific to your need and deploy it on your own CDN

Below an example that explains how to configure TailwindCSS for a simple Html Project

  1. First Step: create a package.json file
yarn init
  1. Add tailwindcss postcss-cli and autoprefixer
yarn add tailwindcss postcss-cli autoprefixer -D

yarn add tailwindcss postcss-cli autoprefixer -D

  1. Create a default configuration file for TailwindCSS
npx tailwind init tailwind.js -full
  1. Create a postcss.config.js file
touch postcss.config.js
  1. Edit the postcss.config.js
const tailwindcss = require('tailwindcss');
module.exports = {
    plugins: [
        tailwindcss('./tailwind.js'),
        require('autoprefixer')
    ],
 purge: [
    './src/**/*.html',
  ],
};
  1. Create a tailwind.css as follow
@import "tailwindcss/base";

@import "tailwindcss/components";

@import "tailwindcss/utilities";
  1. Use postcss to generate the stylesheet style.css
npx postcss tailwind.css -o style.css
  1. Use the stylesheet in your project
<html>
 <head>
    <link rel="stylesheet" href="style.css"/>
    </head>
 <body>
     <h1>Hello world</h1>
</body>
</html>
  1. Deploy the style.css on a CDN

(Possible CDN : CloudFront / Netlify)

like image 179
Raphael Mansuy Avatar answered Oct 20 '25 17:10

Raphael Mansuy


Edit your tailwind.config.js and set purge.enabled = true:

const tailwindcss = require('tailwindcss');
module.exports = {
 purge: {
    enabled: true,
    content: ['./src/**/*.{vue,js,ts,jsx,tsx}']
  },
 ...
};

Tailwind CSS - Optimizing for Production

like image 23
Alexandro Martínez Avatar answered Oct 20 '25 17:10

Alexandro Martínez



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!