jspm / generator

JSPM Import Map Generator
Apache License 2.0
166 stars 21 forks source link

Import map is inserted before the last script tag, not the first #112

Closed SimonMeskens closed 2 years ago

SimonMeskens commented 2 years ago

With the HTML generation, if you have no importmap script tag and you have several other script tags, the importmap will generate just before the last script tag instead of just before the first script tag. If I add an empty importmap script where I want it, the generation is then handled correctly.

Input:

<!DOCTYPE html>

<script type="module">
    import "react";
</script>

<body>
    <script type="text/plain">
        Hello World
    </script>
</body>

Output:

<!DOCTYPE html>

<script type="module">
    import "react";
</script>

<body>
    <!-- Generated by @jspm/generator - https://github.com/jspm/generator -->
    <script async src="https://ga.jspm.io/npm:es-module-shims@1.4.7/dist/es-module-shims.js" crossorigin="anonymous"></script>
    <script type="importmap">
    {
      "imports": {
        "react": "https://ga.jspm.io/npm:react@17.0.2/index.js"
      },
      "scopes": {
        "https://ga.jspm.io/": {
          "object-assign": "https://ga.jspm.io/npm:object-assign@4.1.1/index.js"
        }
      }
    }
    </script>
    <link rel="modulepreload" href="https://ga.jspm.io/npm:object-assign@4.1.1/index.js" />
    <link rel="modulepreload" href="https://ga.jspm.io/npm:react@17.0.2/index.js" />
    <script type="text/plain">
        Hello World
    </script>
</body>

Workaround:

<!DOCTYPE html>

<script type="importmap">
    {}
</script>

<script type="module">
    import "react";
</script>

<body>
    <script type="text/plain">
        Hello World
    </script>
</body>
guybedford commented 2 years ago

Thanks for sharing these cases, fixes in https://github.com/jspm/generator/pull/114.

guybedford commented 2 years ago

Released in 1.0.0-beta.30.