lucleray / next-purgecss

nextjs + purgecss for smaller css bundles
https://www.npmjs.com/package/next-purgecss
134 stars 8 forks source link

Invalid hashes of commons chunks because hash is not generated from purgecss result #40

Open StarpTech opened 5 years ago

StarpTech commented 5 years ago

@lucleray I don't know if it's related to next-compose-plugins but when I use this plugin the hash of the generated common chunks is wrong.

module.exports = withPlugins(
  [
    withCSS,
    [
      withSass,
      {
        sassLoaderOptions: {
          includePaths: ['../../node_modules', 'node_modules', 'styles']
        }
      }
    ],
    [
      optional(() => withPurgeCss),
      {
        purgeCssPaths: ['pages/**/*', 'components/**/*', 'layouts/**/*'],
        purgeCss: {
          whitelist: ['__next']
        }
      },
      [PHASE_PRODUCTION_BUILD]
    ]
  ]
)

Reproduce

  1. Use a class like pt-xl-4 in exact one component. PurgeCss will include it because it's used. The hash of the file is something like .next/static/chunks/commons.d4d0b807.chunk.css.
  2. Remove the class pt-xl-4 in the component and rebuild. You will see the hash hasn't changed but the class was removed by PurgeCss.

That's an indication that hash was generated on the content before purgecss proceed it.

We removed it completely from the build because it was the cause of several production cache issues.

lucleray commented 5 years ago

Hi!

Thanks for reporting. This seems to be an upstream issue with purgecss-webpack-plugin: https://github.com/FullHuman/purgecss-webpack-plugin/issues/65

I'll leave this issue open so we can track the progress there and update this plugin when it's solved.