Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Contenthash name pattern not honored when optimizing CSS #56

Open
albertfdp opened this issue Jun 5, 2018 · 5 comments
Open

Contenthash name pattern not honored when optimizing CSS #56

albertfdp opened this issue Jun 5, 2018 · 5 comments

Comments

@albertfdp
Copy link

albertfdp commented Jun 5, 2018

I am experiencing an issue with webpack that turns out to be quite problematic when combined with a CDN and SRI. I am unsure if the issue is actually on optimize-css-assets-webpack-plugin or on webpack side, but here there are the reproduction steps:

You can find a minimal example in this repo https://github.com/albertfdp/optimize-css-assets-plugin-contenthash

You can see that there are 2 webpack configurations, with the only difference being the options passed to OptimizeCSSAssetsPlugin:

new OptimizeCSSAssetsPlugin({
 cssProcessorOptions: {
  discardComments: { removeAll: true }
-- reduceIdents: false,
-- safe: true,
-- zindex: false
 }
})

Also, bear in mind that I am using:

plugins: [
    new MiniCssExtractPlugin({
      filename: '[name].[contenthash].css',
      chunkFilename: '[name].[id].[contenthash].css'
    })
  ]

This results in 2 files being generated, both with the same name, but with different content (contenthash):

Therefore, if this happens in 2 consecutive builds, and the first time the assets are uploaded to a CDN, when requesting the CSS file, the SRI hash won't match and 💥.

@albertfdp
Copy link
Author

From webpack maintainers I was told that this is actually an issue on this plugin, which should indicate to webpack that content has changed and thus contenthash refreshed webpack/webpack#7483 (comment)

@NMFR
Copy link
Owner

NMFR commented Jun 8, 2018

Currently OptimizeCSSAssetsPlugin does not change the file name (it simply transforms the file's content).

You are right the content hash should be honored.

Waiting for webpack/loader-utils#112 to be solved so i can have an idea how to implement this. The problem from the plugins perspective is that the filename is already generated, we need a way to know that a content hash is present in the file name and re calculate it.

@DawidJanczak
Copy link

Just in case it went unnoticed: the feature required for this landed in loader-utils 1.2.0 so this might be unblocked now.

@DawidJanczak
Copy link

Since there's not much going on with this issue one possible workaround until it's fixed is to add postcss-loader and cssnano and use that to minify the CSS instead of this plugin.

@rightaway
Copy link

I'm not seeing this problem anymore in webpack 5 and optimize-css-assets-webpack-plugin 5. Can you see it or is it resolved for you too?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants