pipe01 / esbuild-plugin-vue3

esbuild plugin for loading Vue 3 SFC files
MIT License
59 stars 13 forks source link

Html generation can insert too many <script> elements #14

Closed pgbross closed 1 year ago

pgbross commented 1 year ago

When generating an html file it can insert too many <script> elements.

Currently for each asset in the metafile outputs the code uses script.insertAfter($("body :last-child")), but this selects all elements that are the last child of their parent.

For example:

<body class="mdc-typography">
    <div id="app">                                                    <!-- match -->
      <div class="home-splash">                                       <!-- match -->
        <div class="home-splash-logo">
          <img src="/media/INIApp-logo-128.png" alt="" />             <!-- match -->
        </div>
        <div class="loader">                                          <!-- match -->
          <svg viewBox="0 0 32 32" width="32" height="32">            <!-- match -->
            <circle class="spinner" cx="16" cy="16" r="14" fill="none"></circle>   <!-- match -->
          </svg>
        </div>
      </div>
    </div>
  </body>

with the selector $("body :last-child")) it has the 6 matches marked. This results in each script asset being referenced multiple times.

Using $("body").append(script) will add the script as a last child of body.