three.nebula.js containing a copy of all three.js code makes three.js included twice in webpack bundle
See original GitHub issueHi, I have noticed that since three-nebula package has a dependency on three.js, bundling applications that also have root dependencies to three.js causes three.js library to be included twice in the final bundle, one for the depedency on three-nebula and one for root dependencies on three.js.
Considering for example the following package.json dependencies:
"dependencies": {
"three": "^0.104.0",
"three-nebula": "^4.0.3",
},
And the following js file:
import { Scene, PerspectiveCamera, Mesh } from "three"
import System, {
Emitter,
Rate,
Span,
Position,
Mass,
Radius,
Life,
Velocity,
PointZone,
Vector3D,
Alpha,
Scale,
Color,
} from 'three-nebula'
Building this file using WebPack results in a file of 1.4 MB (threejs library packed alone is about 650 KB).
To include three.js only once in the bundle, the thing that works for me was to modify the file three-nebula/src/core/three.js to point directly to the root package ./node_modules/three/build/three.module.js (instead of ./node_modules/three-nebula/node_modules/three) and make imports from ./node_modules/three-nebula/src/index.js instead. In that case the final bundle size is around 800 KB.
Issue Analytics
- State:
- Created 4 years ago
- Comments:9
Top GitHub Comments
Great! I am using the library as stars particle system in a webgl website: https://ludik.herokuapp.com/#/
This is how it was previously but it exploded the bundle size. I want the library to work in any context with minimal setup and to have as small a size as possible. The bundle size has been reduced greatly in the latest release. If there’s a way to get it working with the much cleaner approach as before, I’d be open to it! I really hate webpack though and want as little to do with it as possible. Would be really keen to see a PR with these changes if you feel it’s simple enough.
Edit: Btw I’m going to close this issue for now, I’ll open a new one and link to your comment @bummzack