NPM Installation
For modern JavaScript projects using build tools, you can install Babylon.js via npm:
npm install babylonjs babylonjs-loaders --save
Import the entire library for easier development experience:
With Babylon.js 7, the modular approach has been refined to improve loading performance and reduce bundle sizes. For development environments, using the global import provides convenience with access to all APIs without needing to add imports for each component.
// Import everything - larger bundle size but simpler development
import * as BABYLON from 'babylonjs';
import 'babylonjs-loaders';
Import only the specific components you need to minimize bundle size. This approach is recommended for production as it can significantly reduce final bundle size.
// Import only required components
import { Engine, Scene, FreeCamera, Vector3, HemisphericLight, MeshBuilder } from 'babylonjs';
import { SceneLoader } from 'babylonjs/Loading/sceneLoader';