marcofugaro / three-projected-material

📽 Three.js Material which lets you do Texture Projection on a 3d Model
https://marcofugaro.github.io/three-projected-material/
MIT License
671 stars 57 forks source link

please don't `import * from 'three'`, it bloats the application with unused dependencies. #33

Closed trusktr closed 2 years ago

trusktr commented 2 years ago

https://github.com/marcofugaro/three-projected-material/blob/5e0ed6d0be30db43850384fb09acb7400a2d718f/src/ProjectedMaterial.js#L1

This line is a bad practice and imports the entire Three.js library, even if the consumer of three-projected-material does not need the entire set of Three.js classes. Instead, we should import only what is needed. f.e.:

import {MeshPhysicalMaterial} from 'three/src/core/materials/MeshPhysicalMaterial.js'
marcofugaro commented 2 years ago

Not gonna do that, 'three' is the recommended way of importing three.js, most of the unused classes get tree-shaken by bundlers. Also this would mean importing three.js twice for users who import it normally.

You can make three-projected-material import from three/src/ with the alias option of your favorite bundler.

trusktr commented 2 years ago

When using a bundler true (although not all of them tree shake very well if at all), but some people also don't use bundlers just native ES modules.

I think three should solve this by publishing only dist/three.module.js, or src/, instead of both.