A modern starter template combining BabylonJS for 3D rendering with Svelte for reactive UI components.
This starter demonstrates:
Use this template to create a new repository (or clone it):
git clone https://github.com/axeljaeger/babylonjs-svelte-github-starter.git
cd babylonjs-svelte-github-starter
Install dependencies:
npm install
Start the development server:
npm run dev
Open your browser and navigate to http://localhost:5173
npm run dev - Start the development server with hot reloadnpm run build - Build for productionnpm run build:analyze - Build with detailed bundle size analysisnpm run preview - Preview the production build locallynpm run check - Run Svelte type checkingnpm run lint - Run Biome linternpm run format - Format code with Biomebabylonjs-svelte-github-starter/
āāā .github/
ā āāā workflows/
ā āāā deploy.yml # GitHub Pages deployment workflow
āāā .devcontainer/
ā āāā devcontainer.json # Dev container configuration
āāā .vscode/
ā āāā extensions.json # Recommended VS Code extensions
āāā src/
ā āāā lib/
ā ā āāā UiPanel.svelte # Main control panel component
ā āāā App.svelte # Root Svelte component
ā āāā main.ts # Entry point - BabylonJS initialization
ā āāā app.css # Global styles
ā āāā vite-env.d.ts # Vite type definitions
āāā index.html # HTML entry point
āāā package.json # Dependencies and scripts
āāā tsconfig.json # TypeScript configuration
āāā vite.config.ts # Vite configuration
āāā svelte.config.js # Svelte configuration
āāā biome.json # Biome configuration
āāā README.md # Documentation
The 3D scene is initialized in src/main.ts and includes:
UI components are built with Svelte 5 and include:
onMount$effect for rotationThe integration between BabylonJS and Svelte works as follows:
// In main.ts - mount Svelte app with props
import { mount } from 'svelte'
import App from './App.svelte'
mount(App, {
target: appElement,
props: {
scene,
camera,
sphere,
initialCameraPosition,
initialCameraTarget,
},
})
The Svelte components receive references to the BabylonJS scene objects as props, allowing them to directly manipulate the 3D scene using Svelte's reactive system.
$state, $props, and $effectonMount for initialization, onDestroy for cleanupThe repository includes a GitHub Actions workflow that automatically builds and deploys your project to GitHub Pages on every push.
The workflow file is located at .github/workflows/deploy.yml
If you plan to publish to npm or customize further:
name field in package.jsonpackage.jsonindex.htmlCreate new Svelte components in src/lib/:
<script lang="ts">
let { name = 'World' }: { name?: string } = $props()
</script>
<div>Hello, {name}!</div>
<style>
div {
color: white;
}
</style>
Edit src/main.ts to add more objects, lights, or change the scene setup. BabylonJS has extensive documentation and examples at babylonjs.com.
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Feel free to submit issues or pull requests.