How to remove unused CSS in sage 10 bootstrap theme


I want to remove unused CSS to speed up the loading time. due to unused CSS I am getting LCP issue.

Please help me how to remove unused CSS or generate critical css .


  .sass('resources/assets/styles/app.scss', 'styles')
  .sass('resources/assets/styles/editor.scss', 'styles')
     enabled: mix.inProduction(),
     paths: {
       base: 'http://example.test',
       templates: './dist/styles/'
     urls: [
       { url: '/', template: 'home' },
     options: {
       minify: true,

you can then create more critical css for templates you are using: singular, archive etc.


Thanks for your reply and help. I really appreciate it.

I added your bit, but there was a required module at top so I added this module using npm install laravel-mix-criticalcss --save-dev but that gives me the following error

Here’s my webpack.js code just to be sure I’m not doing something wrong

Waiting for your reply.
Thanks again.

The easiest way.

Hi @diomededavid

Thanks for your reply.

But I am using sage 10 and there is no file structure like this
Please help

As far as I know sage 10 only supports tailwind. Is this a new project?
Need more details and screenshots would help.
Do you have a _bootstrap.scss file? You may need to manually import.

In the same post I shared they also show how to use BS5 with Sage 10,

We started this in January
Do you have a _bootstrap.scss file? : No

You mean this one :

waiting for your reply.

If you started with a sage 10 theme from commit #33005e59 as described in , laravel-mix-purgecss should be installed and this will remove all unused css from your production css file.

You could only include the needed classes from bootstrap, as described for sage 9 in In sage 10, bootstrap gets included from resources/assets/styles/config/external.scss. But with purgecss, if you run yarn build:production, purgecss will delete all unused css, so there’s no need to cherry-pick these files.

Yup. that is what I said

Thanks, @diomededavid @tombro

I tired both way and they removed unused CSS but still facing LCP issue. and purifycss is showing 50% unused.

Did you try this link in an empty project? It might help narrow down. If you get the empty project to work you can copy the build files over to your project.

I am using sage 9 with this setup:

Hi @alkesh,

Have you tried with PurgeCSS?

Add Laravel Mix PurgeCSS to your project:

yarn add laravel-mix-purgecss purgecss-with-wordpress

and in your webpack.mix.js add:

const purgeCssWithWordPress = require('purgecss-with-wordpress');


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

Also, you need to add PurgeCSS rules to your project:

mix.sass('resources/assets/styles/app.scss', 'styles')
    whitelist: [
    whitelistPatterns: [

Here is the documentation how to whitelist your classes:


Finally able to generate critical CSS and LCP issues is solved as well.
But now CLS issue is coming and FOUC as well

Please help.

This topic was automatically closed after 42 days. New replies are no longer allowed.