Build width rollup bundle size

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 (




)
}
}

More information would be really appreciated here :slight_smile: What does your rollup configuration look like? Can you provide us with something like a Github project of your files? :slight_smile:

1 Like

also, please be sure to load the files from their right location (and not directly from @babylonjs/core), as this will load the entire framework (which is probably the reason for the large size).

You can read about it here:

1 Like

thanks. when i use ES6 tree shaking methods in the documents,the result module reduce to 1.1M,which includes some others packages。

thanks. when i use ES6 tree shaking methods in the documents,the result module reduce to 1.1M,which includes some others packages

1 Like