Skip to content
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

Does dot rename JS variables in HTML files inside <script> tag #55

Open
caoshouse opened this issue Dec 1, 2020 · 1 comment
Open
Assignees
Labels
Type: Bug Something isn't working as expected.

Comments

@caoshouse
Copy link

🐞 Bug Report

Describe the bug

Exactly as mentioned in the title:

This Code:

<template>
  <img id="img" alt="">
</template>
<script type="text/javascript">
  var objectFitSupport = 'objectFit' in document.body.style;
  module.exports = function (e,subElements) {
    var ats = $.getAttributes(e);
    var img = subElements.img;
    if (ats.alt) {
      img.setAttribute('alt', ats.alt);
    }
    img.onload = function () {
      $.fastDOM.mutate(function () {
        if (objectFitSupport) {
          img.style.opacity = 1;
        } else {
          e.style.backgroundImage = 'url(' + img.src + ')';
        }
      });
      $.trigger(e, 'load');
    };
    $.extend(e, {
      src: {
        __change: function (v) {
          img.src = '';
          img.style.opacity = 0;
          img.removeAttribute('src');

          /* Solution for Handlebars */
          if ($.contains(v, '{')) {
            console.warn('invalid image url', v);
            return null;
          }

          var obs = $.onViewport(e, function () {
            img.src = v;
            obs.unobserve(e);
          });
          return v;
        }
      }
    });
  };
</script>

<style>
  MDL-IMG {
    display: inline-block;
    overflow: hidden;
    margin: auto;
    position: relative;
    vertical-align: middle;
    background-position: center center;
    background-repeat: no-repeat;
    background-size: cover
  }

  MDL-IMG[fit="contain"] {
    background-size: contain
  }

  MDL-IMG[fit="contain"] img {
    object-fit: contain
  }

  MDL-IMG img {
    border: none;
    position: absolute;
    margin: auto;
    display: block;
    width: 100%;
    height: 100%;
    opacity: 0;
    transition: opacity 0.5s;
    object-fit: cover
  }
</style>

After minifing, this is the resul:

<template><img id="img" alt=""></template><script type="text/javascript">var objectFitSupport='objectFit' in document.body.style; module.exports=function (e,subElements){ var ats=$.getAttributes(e); var img=subElements.img; if (ats.alt){ img.setAttribute('alt', ats.alt);} img.onload=function (){ $.fastDOM.mutate(function (){ if (objectFitSupport){ img.style.opacity=1;} else{ e.style.backgroundImage='url(' + img.src + ')';}}); $.trigger(e, 'load');}; $.extend(e,{ src:{ __change:function (v){ img.src=''; img.style.opacity=0; img.removeAttribute('src'); if ($.contains(v, '{')){ console.warn('invalid image url', v); return null;} var obs=$.onViewport(e, function (){ img.src=v; obs.unobserve(e);}); return v;}}});};
</script><style>MDL-IMG{ display:inline-block; overflow:hidden; margin:auto; position:relative; vertical-align:middle; background-position:center center; background-repeat:no-repeat; background-size:cover} MDL-IMG[fit="contain"]{ background-size:contain} MDL-IMG[fit="contain"] img{ object-fit:contain} MDL-IMG img{ border:none; position:absolute; margin:auto; display:block; width:100%; height:100%; opacity:0; transition:opacity 0.5s; object-fit:cover}
</style>

Your environment

  • OS: Windows 10
  • Node version: 12.19.0
@Josee9988
Copy link
Owner

This is definitely something that I would like to implement in the future (as soon as I have some free time).

I'll keep you updated, but for now, my time is extremely limited.

Thanks for the issue!

@Josee9988 Josee9988 transferred this issue from Josee9988/MinifyAll Feb 23, 2021
@Josee9988 Josee9988 added the Type: Bug Something isn't working as expected. label May 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Type: Bug Something isn't working as expected.
Projects
None yet
Development

No branches or pull requests

2 participants