I use rollup to build babylonjs in a react project and the result bundle size is over 4Mb,I don’t know why,here’s my code
import React from ‘react’
import {
Engine,
Scene,
Vector3,
UniversalCamera,
HemisphericLight,
PointLight,
MeshBuilder,
} from ‘@babylonjs/core’
class Babylon3DComponent extends React.PureComponent {
constructor(props) {
super(props)
this.state = {}
}
static defaultProps = {}
componentDidMount() {
this.canvas = document.querySelector('#babylonCanvas')
this.engine = new Engine(this.canvas, true)
this.scene = new Scene(this.engine)
this.camera = new UniversalCamera(
'Camera',
new Vector3(0, 0, -10),
this.scene
)
this.camera.attachControl(this.canvas, true)
const light1 = new HemisphericLight(
'light1',
new Vector3(1, 1, 0),
this.scene
)
const light2 = new PointLight('light2', new Vector3(0, 1, -1), this.scene)
const sphere = MeshBuilder.CreateSphere(
'sphere',
{ diameter: 2 },
this.scene
)
this.engine.runRenderLoop(() => {
this.scene.render()
})
window.addEventListener('resize', () => {
this.engine.resize()
})
window.addEventListener('click', function () {
// We try to pick an object
const pickResult = this.scene.pick(
this.scene.pointerX,
this.scene.pointerY
)
if (pickResult.hit) {
console.log('hit')
}
})
}
render() {
return (
)
}
}