cfware / babel-plugin-template-html-minifier

Minify HTML in tagged template strings using html-minifier
MIT License
63 stars 4 forks source link

Minify all templates tagged with a certain tag #17

Open LarsDenBakker opened 5 years ago

LarsDenBakker commented 5 years ago

Instead of specifying the module it should be exported from, I'd like to be able to just minify all templates prefixed with html and all templates prefixed with css.

coreyfarrell commented 5 years ago

Currently the matching logic is based on bindings, so when the plugin encounters import {html} from 'lit-html';, this creates a binding on html. Then when a template is tagged with html it's not matched by name it's matched by comparing the binding.

I'll try to take a look at this as soon as I have a chance. I would like to maintain the current stricter functionality but I'm open to supporting this request.

IssueHuntBot commented 5 years ago

@coreyfarrell has funded $38.00 to this issue.


LarsDenBakker commented 4 years ago

@coreyfarrell just ran into a situation where I need this, since I have modules reexporting html from lit-html.

We could introduce a special case for * in the module key:

{
  "plugins": [
    ["template-html-minifier", {
      "modules": {
        "*": ["html"],
      },
      "strictCSS": true,
      "htmlMinifier": {
        "collapseWhitespace": true,
        "conservativeCollapse": true,
        "removeComments": true,
        "caseSensitive": true,
        "minifyCSS": true
      },
    }]
  ]
}

What do you think? I can work on this.

coreyfarrell commented 4 years ago

If that can work I have no objection, I suspect this can be done in a semver-minor.

Juribiyan commented 1 year ago

I was looking for a replacement for the deprecated babel-plugin-html-template, a plugin that simply strips away html tags and minifies what is inside. Could it be done?