jsenv / importmap-node-module

Generate importmap for node_modules
33 stars 4 forks source link

Inline import map option #68

Closed FluorescentHallucinogen closed 10 months ago

FluorescentHallucinogen commented 10 months ago

The npx @jsenv/importmap-node-module project.importmap --entrypoint index.html --remove-unused command generates the project.importmap file. The ReadMe say I need to add the following into the index.html code by hand:

<script type="importmap" src="./project.importmap"></script>

But I get the External import maps are not yet supported. error in the latest version of Chrome.

It seems external import maps are not yet supported in Firefox and Safari too.

What about an option that injects inline import map into the index.html code automatically?

<script type="importmap">
  {
    "imports": {},
    "scopes": {}
  }
</script>
dmail commented 10 months ago

It's funny because was planning to work on that tomorrow:)

dmail commented 10 months ago

Would it make sense if the script tries to inline the importmap by default when the file ends with .html? (It would either replace the existing importmap script or inject one at the top of the html)

FluorescentHallucinogen commented 10 months ago

Here's how it's implemented in JSPM CLI: https://jspm.org/getting-started

jspm link index.html -p nodemodules -o index.html
FluorescentHallucinogen commented 10 months ago

Would it make sense if the script tries to inline the importmap by default when the file ends with .html?

Yes.

dmail commented 10 months ago

The command would look like this

npx @jsenv/importmap-node-module index.html --entrypoint=index.html --remove-unused
dmail commented 10 months ago

Version 6.0.0 just published on NPM. It is now possible to inline importmap into html.

You can try with the following command:

npx @jsenv/importmap-node-module index.html --remove-unused
FluorescentHallucinogen commented 10 months ago

@dmail Thank you very much! ❤️