trullock / NUglify

NUglify is a HTML, JavaScript and CSS minification Library for .NET (fork of AjaxMin + new features)
Other
398 stars 79 forks source link

Minify HTML Template Literals #262

Open rochapablo opened 3 years ago

rochapablo commented 3 years ago

Is it possible to minify javascript strings like the following example:

return`
        <div class="">
            <div class="audio">
                <div class="ad hidden"><div><div><span class="ad-label">aaa</span><span class="ad-countdown"></span></div><a class="ad-link" target="_blank" rel="noopener">aaa</a></div></div>
                `;
const style=`
  .aaa {
    display: flex;
    flex-direction: column;
    align-items: center;
    position: relative;
  }

  .vvv {
    width: 400px;
`;
Uglify.Js(js).Code
NUglify 1.13.12
trullock commented 3 years ago

It should be, is this a question or a bug report? If the latter what's the issue?

rochapablo commented 3 years ago

It's not working, the entire file it's minified expect that code.

trullock commented 3 years ago

Can you provide your expected and actual outputs?

rochapablo commented 3 years ago

What I expect (no extra space or lines break)

return`<div class=""><div class="audio"><div class="ad hidden"><div><div><span class="ad-label">aaa</span><span class="ad-countdown"</span></div><a class="ad-link" target="_blank" rel="noopener">aaa</a></div></div>`;

What I'm getting (extra space and lines break)

return`
        <div class="">
            <div class="audio">
                <div class="ad hidden"><div><div><span class="ad-label">aaa</span><span class="ad-countdown"></span></div><a class="ad-link" target="_blank" rel="noopener">aaa</a></div></div>
                `;
trullock commented 3 years ago

Right sorry, now I understand.

Erm, well, this doesn't currently "work" - because its a template literal, the clues in the name, its literally whatevers between the backticks.

I do understand your usecase, however theres no real practical way for NUglify to know that a particular template should be treated as HTML and minified and not another, without adding some minification annotation to the javascript itself.

You might be better off having the template in a separate file and @importing it.

I'll leave this open as a curiosity, suggestions and PRs welcome