jantimon / html-webpack-plugin

Simplifies creation of HTML files to serve your webpack bundles
MIT License
10.71k stars 1.31k forks source link

Webpack 5: incompatibility with compression-plugin #1525

Closed csvan closed 4 years ago

csvan commented 4 years ago

Expected behaviour

html-webpack-plugin should output an index.html file which can then be compressed by the compression-plugin

Current behaviour

In Webpack 5 (tested in rc3), the index.html file seems to be output after the compression plugin runs. Hence, it is never compressed and the app breaks. This seems to be a general change in how wp5 handles the plugin lifecycle, but I can't figure it out.

Environment

Tell us which operating system you are using, as well as which versions of Node.js, npm, webpack, and html-webpack-plugin. Run the following to get it quickly:

Node.js v14.13.0
darwin 19.6.0
webpack@5.0.0-rc.3
html-webpack-plugin@4.5.0

Config

Copy the minimal webpack.config.js to produce this issue:

{
    plugins: [
        new HtmlWebpackPlugin({
            template: path.join(__dirname, 'index.html'),
            minify: {
                removeComments: true,
                collapseWhitespace: true,
                removeRedundantAttributes: true,
                useShortDoctype: true,
                removeEmptyAttributes: true,
                removeStyleLinkTypeAttributes: true,
                keepClosingSlash: true,
                minifyJS: true,
                minifyCSS: true,
                minifyURLs: true,
            },
            inject: true
        }),
        new CompressionPlugin({
            filename: 'gzip/[path][base]',
            algorithm: 'gzip',
            test: /.*/,
            threshold: -1,
            minRatio: Number.MAX_SAFE_INTEGER,
        }),   
    ]
}

Additional context

This worked without issue under webpack 4. Analysing what gets fed to the compression-plugin, I see the following from html-webpack-plugin under webpack 5:

{
  file: '__child-HtmlWebpackPlugin_0',
  query: '',
  fragment: '',
  path: '',
  base: '__child-HtmlWebpackPlugin_0',
  name: '__child-HtmlWebpackPlugin_0',
  ext: ''
}
jantimon commented 4 years ago

Can you please see if this is fixed with html-webpack-plugin@5.0.0-alpha.3 ?
Please see also #1527

csvan commented 4 years ago

Works as expected with html-webpack-plugin@5.0.0-alpha.3