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

Added ImportMaps availability script #23148

Merged
merged 2 commits into from
Jan 4, 2022
Merged

Added ImportMaps availability script #23148

merged 2 commits into from
Jan 4, 2022

Conversation

mrdoob
Copy link
Owner

@mrdoob mrdoob commented Jan 4, 2022

Description

Show a message when the browser doesn't support Import Maps instead of failing silently.

@mrdoob mrdoob added this to the r137 milestone Jan 4, 2022
@mrdoob mrdoob merged commit fe276f2 into dev Jan 4, 2022
@mrdoob mrdoob deleted the importmaps branch January 4, 2022 23:11
@marcofugaro
Copy link
Contributor

marcofugaro commented Jan 6, 2022

Hello @mrdoob there is now a polyfill for importmaps, what do you think about using it to start the migration to importmaps for other examples as well? 🙂

We are using it on this cannon-es-debugger example to make it run on firefox and safari as well.

This is the usage:

https://github.com/pmndrs/cannon-es-debugger/blob/4525caef5c7066e72e131ce512eff56317f59aea/index.html#L35-L48

<!-- Import maps polyfill -->
<!-- Remove this when import maps will be widely supported -->
<script async src="https://unpkg.com/es-module-shims@1.3.6/dist/es-module-shims.js"></script>

<script type="importmap">
  {
    "imports": {
      "cannon-es": "https://unpkg.com/cannon-es@0.18.0/dist/cannon-es.js",
      "cannon-es-debugger": "./dist/cannon-es-debugger.js",
      "three": "https://unpkg.com/three@0.136.0/build/three.module.js",
      "three/examples/jsm/controls/OrbitControls": "https://unpkg.com/three@0.136.0/examples/jsm/controls/OrbitControls.js"
    }
  }
</script>

@mrdoob
Copy link
Owner Author

mrdoob commented Jan 6, 2022

Oh, that shim no longer requires doing <script type="importmap-shim">?

@marcofugaro
Copy link
Contributor

Yess, it works with native syntax now.

The tradeoff is that the error in the console is still there, because the polyfill can't disable native module loading. But the example works nonetheless.

More info in its readme.

@mrdoob
Copy link
Owner Author

mrdoob commented Jan 6, 2022

Yess, it works with native syntax now.

Interesting development... 🤩
I'll put it in the WebGPU examples for now.

/fyi @sunag

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants