Navigation Menu

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

doesn't seem to compress HTML from html-webpack-plugin #30

Closed
graingert opened this issue May 5, 2016 · 16 comments · Fixed by #71
Closed

doesn't seem to compress HTML from html-webpack-plugin #30

graingert opened this issue May 5, 2016 · 16 comments · Fixed by #71

Comments

@graingert
Copy link
Contributor

No description provided.

@richtier
Copy link

richtier commented May 6, 2016

worth checking if changing minThreshold to a lower value will solve this, and ensure test includes html, e.g.,:

    test: /\.js$|\.html$/,
    minRatio: 0,

@richtier
Copy link

richtier commented May 6, 2016

hmm actually I am getting this problem too now - intermittently.

@graingert
Copy link
Contributor Author

is this a plugin ordering issue? Is there a race between the HTML plugin and the compression plugin?

@ljfranklin
Copy link

Ran into a similar problem here: markdalgleish/static-site-generator-webpack-plugin#44. There's also a related discussion going on here: jantimon/html-webpack-plugin#142.

@jantimon
Copy link

This issue could be solved on the level of the compression-webpack-plugin - who is maintaining this plugin right now?

@TomDeBacker
Copy link

TomDeBacker commented Dec 7, 2016

If it helps, I had the same issue and created a plugin that does this.
https://github.com/TomDeBacker/html-compression-webpack-plugin

Edit: Seems like this is now going to be implemented in compression-webpack-plugin. Deleted previously mentioned repository.

@michael-ciniawsky
Copy link
Member

@jantimon Can you explain how compression-webpack-plugin could solve the issue ?

@ijpiantanida
Copy link
Contributor

@michael-ciniawsky if I understand correctly, this would also be solved by #45. It's the same problem.

@jantimon
Copy link

@michael-ciniawsky there is an event fired by the html-webpack-plugin which could be used

@michael-ciniawsky
Copy link
Member

@jantimon Mind to give 'this event' a name 😛 , in case #45 isn't resolving the problem?

@r3dDoX
Copy link

r3dDoX commented Apr 7, 2017

I'm not exactly sure, but I have an issue that's maybe caused by the same root.

In my app I use CommonChunksPlugin to generate various bundle files including a manifest file like mentioned in the docs.

For the bundle files the compression works just fine. But the manifest file isn't compressed. Might that be the same root cause?

@michael-ciniawsky
Copy link
Member

@r3dDoX Please provide more info on this + show some code 😛

@r3dDoX
Copy link

r3dDoX commented Apr 14, 2017

@michael-ciniawsky Sorry, didn't see the notification. Yeah so my webpack config basically looks like this:

const path = require('path');
const webpack = require('webpack');
const HtmlWebpackPlugin = require('html-webpack-plugin');
const CopyWebpackPlugin = require('copy-webpack-plugin');
const CompressionPlugin = require("compression-webpack-plugin");

module.exports = {
  entry: './src/client/index.jsx',

  output: {
    path: path.join(__dirname, 'dist/'),
    filename: '[name].[chunkhash].js',
  },

  module: {
    rules: [
      {
        test: /\.(js|jsx)$/,
        exclude: /node_modules/,
        loader: 'babel-loader',
      },
      {
        test: /\.svg$/,
        exclude: /node_modules/,
        loader: 'react-svg-inline-loader',
      },
    ],
  },

  plugins: [
    new HtmlWebpackPlugin({
      template: 'src/client/index.html',
    }),
    new CopyWebpackPlugin([
      {
        from: 'src/client/assets/',
        to: 'assets/',
      }
    ]),
    new webpack.optimize.CommonsChunkPlugin({
      name: 'vendor',
      minChunks: function(module) {
        return module.context && module.context.indexOf("node_modules") !== -1;
      },
    }),
    new webpack.optimize.CommonsChunkPlugin({
      name: 'manifest',
      minChunks: Infinity
    }),
    new CompressionPlugin({
       asset: "[path].gz[query]",
       algorithm: "gzip",
       test: /\.js$/,
       threshold: 10240,
       minRatio: 0.8
     })
  ],
};

This results in a vendor.[hash].js.gz and a main.[hash].js.gz, but only a manifest.[hash].js and no manifest.[hash].js.gz.

@NeaSTDL
Copy link

NeaSTDL commented Jun 28, 2017

As just @r3dDoX comments, the same situation happened to me while I was setting up my bundling configuration.

yarn build v0.24.6
$ webpack --config webpack-production.config.js --colors 
Hash: ce188de31b921a80fb52
Version: webpack 3.0.0

                         Assets             Size      Chunks                                  Chunk Names
manifest.json                           81 bytes                   [emitted]         
runtime.ce188de31b921a80fb52.js         8.41 kB       runtime      [emitted]                  runtime
vendor.66486fe933c2e8c9d06e.js          2.26 MB       vendor       [emitted]       [big]      vendor
main.79885a5e2710a6f17094.js.gz         1.03 MB                    [emitted]       [big]  
vendor.66486fe933c2e8c9d06e.js.gz       534 kB                     [emitted]       [big]  
main.79885a5e2710a6f17094.js            2.53 MB       main         [emitted]       [big]      main    
index.html                              1.93 kB                    [emitted] 

As can be seen in the extract of my bundle output, only main and vendor files got a gzipped version through compression-webpack-plugin.

Is there a way to tell compression-webpack-plugin to also create this file, or is it not relevant enough?

In that case, I'll have to make some exceptions in my server application just for this file to be served without gzip encoding though.

@r3dDoX
Copy link

r3dDoX commented Jun 30, 2017

@NeaSTDL That's exactly the workaround that I've been using since then...

@michael-ciniawsky
Copy link
Member

#71

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
No open projects
Development

Successfully merging a pull request may close this issue.

9 participants