Skip to content

Examples: use import maps + polyfill #23255

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

Merged
merged 6 commits into from
Jan 19, 2022
Merged

Conversation

marcofugaro
Copy link
Contributor

@marcofugaro marcofugaro commented Jan 17, 2022

Related issue: #23175 (comment)

Description
Let's start using import maps in the examples!
In this PR I made all the examples/jsm files import from 'three' and added the import map + polyfill in the relative html file.

I also updated the import in the file like this:

- import * as THREE from '../build/three.module.js';
+ import * as THREE from 'three';

@marcofugaro
Copy link
Contributor Author

@Mugen87 Mugen87 modified the milestones: r137, r??? Jan 17, 2022
@looeee
Copy link
Collaborator

looeee commented Jan 18, 2022

To test, open any example in Firefox / Safari

I just tested in latest Chrome on Windows, it seems to work fine.
In Firefox get the following error, however the examples still load correctly.

Uncaught TypeError: Error resolving module specifier “three”. Relative module specifiers must start with “./”, “../” or “/”.

@marcofugaro
Copy link
Contributor Author

@looeee thanks for testing, that's expected behaviour since the polyfill can't disable native module loading.

However as you can see, the example loads just fine 🙂

@Mugen87
Copy link
Collaborator

Mugen87 commented Jan 18, 2022

TBH, this change is premature.

The support for import maps is not good enough that a wide usage in the repo is appropriate. I suggest to wait until all major browser support import maps with their latest version. And then use the polyfill to support older browsers.

@mrdoob
Copy link
Owner

mrdoob commented Jan 19, 2022

@Mugen87

Judging by the https://threejs-journey.com/ course, seems like a a lot of people these days develop using bundlers and they are already doing import * as THREE from 'three'.

This change is also one step forward on the examples/js to examples/jsm transition. It would allow us to remove the hard coded import paths in the jsm files and would unify the npm/bundlers/web code import style. Then we'll be able to remove the examples/js folder altogether.

Waiting for Firefox and Safari until we do the transition will probably delay it until 2023 at least...

What are your main concerns about the change?

@Mugen87
Copy link
Collaborator

Mugen87 commented Jan 19, 2022

Waiting for Firefox and Safari until we do the transition will probably delay it until 2023 at least...

That's indeed a long time...

I'm just feeling a bit insecure to use an API which is not supported by two major browsers. On the other hand unifying the code import style is of course an important topic.

Okay, it's probably best then to merge and see how the changes behave in production 👍 .

Then we'll be able to remove the examples/js folder altogether.

That sounds of course good, too! However, we should reopen #20455 or at least inform users like @Bug-Reaper and @gigablox when we are going to make this change. It seems there is still an unknown number of devs relying on ES5/UMD workflows and I think it's important to announce the removal in some way (similar when we removed THREE.Geometry).

@mrdoob
Copy link
Owner

mrdoob commented Jan 19, 2022

I'm just feeling a bit insecure to use an API which is not supported by two major browsers.

Definitely. I would also be worried if Firefox hadn't expressed interest.

That sounds of course good, too! However, we should reopen #20455 or at least inform users like @Bug-Reaper and @gigablox when we are going to make this change.

Agreed. I think we can continue generating the examples/js folder for a year or so.

@mrdoob mrdoob modified the milestones: r???, r137 Jan 19, 2022
@mrdoob mrdoob merged commit eadd35e into mrdoob:dev Jan 19, 2022
@mrdoob
Copy link
Owner

mrdoob commented Jan 19, 2022

Thanks!

@DefinitelyMaybe
Copy link
Contributor

This change is also one step forward on the examples/js to examples/jsm transition.

woohoo! full steam ahead!

great stuff @marcofugaro

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

5 participants