asyncLiz / minify-html-literals

Minify HTML template literal strings
MIT License
68 stars 13 forks source link

Dynamically inserted selectors loose their styles #46

Open schwers opened 2 years ago

schwers commented 2 years ago

I have a project using lit. In a design system our org makes there's code for sharing styles that when you pass in a selector to apply, returns a css template result. During minfication body's of a selector that gets injected dynamically are removed. I suspect this is might be due to the selector not existing in the template part so maybe its removed under the assumption that the selector wouldn't match anything?

e.g. I would expect

var minifyHtmlLiterals = require("minify-html-literals").minifyHTMLLiterals

minifyHtmlLiterals(`
  css\`
      foo {
        bar: baz;
      }

      \${unsafeCSS('#foo-id')} {
        bar: baz;
      }
  \`
`).code

to produce

'\n  css`foo{bar:baz}${unsafeCSS('#foo-id')}{bar: baz}`\n'

but instead i'm getting back

'\n  css`foo{bar:baz}${unsafeCSS('#foo-id')}`\n'