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

use bare "three" imports #29

Merged
merged 1 commit into from
Jan 7, 2023
Merged

use bare "three" imports #29

merged 1 commit into from
Jan 7, 2023

Conversation

ChristopherChudzicki
Copy link
Collaborator

I was working on unconed/mathbox#49 and realized we should do the same for this library

What does this do

Previously we were importing from specific three/src files. Now we just import from "three".

Why change? Because:
1. we can still tree shake
2. we were actually (indirectly) using bare imports before, too. E.g., ThreeStrap imports from "three/examples/jsm/controls/OrbitControls", and OrbitControls imports bare "three"
3. "three" seems like the more official import pattern; it's what is documented at https://threejs.org/docs/#manual/en/introduction/Installation

Related

See also unconed/mathbox#49

Some numbers

I was not expecting this to affect bundle sizes very significantly, but it actually did reduce the bundle size pretty significantly, at least for webpack, I think because of (2) above: previously we were including three/src directly, and three/build indirectly (via imports like three/examples/jsm/controls/OrbitControls).

I published a version of threestrap on npm that includes this change, v0.5.1-rc1 and testing with https://github.com/ChristopherChudzicki/bundling-tests:

            0.5.0   0.5.1-rc
webpack     859K    439K
vite        441K    419K

So, that's cool.

Previously we were importing from specific three/src files. Why change? Because:
    - we can still tree shake
    - we were actually (indeirectly) using bare imports before, too. E.g., ThreeStrap imports from "three/examples/jsm/controls/OrbitControls", and OrbitControls imports bare "three"
    - "three" seems like the more official import pattern; it's what is documented at https://threejs.org/docs/#manual/en/introduction/Installation

See also unconed/mathbox#49
@ChristopherChudzicki
Copy link
Collaborator Author

@sritchie I'm working on PRs for unconed/mathbox#49, but realized we should do this also, and would like do update to 0.5.1 as part of the PRs toward unconed/mathbox#49.

@ChristopherChudzicki ChristopherChudzicki mentioned this pull request Jan 7, 2023
@sritchie
Copy link
Collaborator

sritchie commented Jan 7, 2023

The smaller bundle size is the absolute clincher. Thanks for going the extra mile and doing those bundle size tests...

@sritchie sritchie merged commit 3405ddb into master Jan 7, 2023
@sritchie sritchie deleted the cc/use-three-directly branch January 7, 2023 17:10
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