Skip to content

Documentation for minimize option #81

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

Closed
JaKXz opened this issue Aug 11, 2016 · 3 comments
Closed

Documentation for minimize option #81

JaKXz opened this issue Aug 11, 2016 · 3 comments
Assignees

Comments

@JaKXz
Copy link

JaKXz commented Aug 11, 2016

Continued from #34 (comment) - I should have made a new issue in the first place, my bad.

Anyway, my question is where is the minimize option documented? Are there options I can pass to it? Is it on or off by default? I have looked up and down the docs, but I only saw the comment about --optimize-minimize which I'm not sure does anything 😕

After looking through the source a bit, I've enabled it explicitly with:

htmlLoader: {
  minimize: true
}

but I'm not really sure if there is a difference being made on the HTML I'm loading in (via other loaders in the pipeline).

@bfricka
Copy link

bfricka commented Sep 17, 2016

There is a difference, and you're doing it correctly. Although the option isn't particularly well documented, it's mainly b/c it assumes you understand well how Webpack works (I can't say I do yet). But, looking at the source it's pretty clear.

First it looks for a config query string as the key name (e.g. html?config=fooKey) which corresponds to the key in the webpack config. Defaults to htmlLoader which is what you're using.

Later it looks for the minimize boolean on the config. This sort of sucks, and you can see why later. If minimize is true, it sets its defaults from html-minifier. Then it merges the entire config with the defaults, and passes it to html-minifier.

That's the sucky part because it's a pretty messy way to invoke the minifier. If html-minifier ever did a config validation that threw errors it would break this loader.

A better solution would be to just check if (config.minimize), and accept either a boolean (to use defaults) or an object that takes html-minifier options.

@bfricka
Copy link

bfricka commented Sep 17, 2016

To be clear what I mean in the last paragraph:

Instead of (current config):

{
  module: {loaders: [{test: /\.html$/, loader: 'html'}]},
  htmlLoader: {
    minimize: true,
    collapseBooleanAttributes: true,
    collapseWhitespace: true,
    removeAttributeQuotes: true,
    removeComments: true,
    removeEmptyAttributes: true,
    removeRedundantAttributes: false,
    removeScriptTypeAttributes: true,
    removeStyleLinkTypeAttributes: true
  }
}

I think this makes more sense:

{
  module: {loaders: [{test: /\.html$/, loader: 'html'}]},
  htmlLoader: {
    minimize: {
      collapseBooleanAttributes: true,
      collapseWhitespace: true,
      removeAttributeQuotes: true,
      removeComments: true,
      removeEmptyAttributes: true,
      removeRedundantAttributes: false,
      removeScriptTypeAttributes: true,
      removeStyleLinkTypeAttributes: true
    }
  }
}

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

No branches or pull requests

5 participants