pcardune / handlebars-loader

A handlebars template loader for webpack
560 stars 169 forks source link

Option to process template #175

Open dev-bjoern opened 5 years ago

dev-bjoern commented 5 years ago

I would like to propose an option/feature allowing to process the returned template(string). I need it to remove white space, empty lines and tabs from the compiled template. A similar option is already present in the grunt plugin via "processContent".

I would use it e.g. like so:

  processContent: function(content) {
    return content.replace(/\n/g, '');
  }

Anything like this possible?

pizatski commented 5 years ago

I've been noodling with something like this in a local fork and would be happy to take it on.

The savings are not astronomical - especially considering how good gzip is at removing empty strings, but there are savings when loading the files for SSR and some of the boilerplate in the compiled templates is reduced.

pizatski commented 5 years ago

@chickenwing I have a PR here against the handlebars-loader: https://github.com/pcardune/handlebars-loader/pull/177

I think I may change it so that you can pass the options for html-minifier where handlebars-loader is configured in the implementor's webpack configuration so that the loader isn't dictating the kind of compression settings the project may be looking for.