michtio / laravel-mix-criticalcss

mix.criticalcss()
35 stars 13 forks source link

Critical css files don't go into mix-manifest.json #19

Open samjonesigd opened 1 year ago

samjonesigd commented 1 year ago

Critical css files don't go into mix-manifest.json so not able to version them and use mix() inside blade template.

This means users with cached versions of the critical css won't get an updated version.

charlesteh commented 1 year ago

@samjonesigd I found a workaround on this.

Have criticalCSS to generate to a temporary folder first, e.g.

  .criticalCss({
    enabled: mix.inProduction(),
    paths: {
      .....
      templates: "./critical/css/", // Write this file to a custom root project directory
     ....
    },
    ....
  });

Then execute copyDirectory to public/css to have it added into mix-manifest.json:

mix.copyDirectory("critical", "public");

Mix does not handle directory deletion, so just add the temporary folder to .gitignore before commiting to your repo: .gitignore contents:

...
/critical
...