A simple demo that you can use as a template for your own WebXR projects. It uses Vite to bundle the application files and GitHub Pages to host them. Whenever you push changes to GitHub it will deploy them automatically with a GitHub Action. To use it you will need to sign up to GitHub, but it's free and the defacto standard for source code hosting.
Live demo: https://learnhub.github.io/DeployWebXR/
If you are using AI-assisted development you can just point it at this project and tell it to:
update this project to use the build and deploy approach described here: https://github.com/LearnHub/DeployWebXR
The easiest way to share the published application is to scan the URL as a QR code from your ClassVR headset:
You can also add the URL to a shared playlist from the management pages:
- Select the playlist you want to add to and then click the Add New Website action button
- Enter the deployment URL and click [Add Website
- This creates a track in this playlist that can be managed from within the ClassVR Portal and sent to headsets
- Fork or clone this repository
- Update
baseinvite.config.jsto match your repository name - Push to GitHub
- Enable GitHub Pages (see Enabling GitHub Pages)
├── .github/workflows/deploy.yml # Automated deployment
├── index.html # Entry HTML file
├── main.js # Three.js WebXR scene
├── package.json # Dependencies and scripts
└── vite.config.js # Build configuration
Vite bundles your JavaScript and assets into optimized static files. Key benefits:
- Hot module reload during development
- Automatic dependency bundling (Three.js, etc.)
- ES module support out of the box
The vite.config.js file configures the build:
import { defineConfig } from 'vite';
export default defineConfig({
base: '/your-repo-name/', // ← Change this to your repository name
build: {
outDir: 'dist',
},
});The base path is critical—it tells Vite where your site will be hosted so asset URLs resolve correctly.
The .github/workflows/deploy.yml file automates deployment. When you push to main:
- Checkout - Gets your code
- Setup Node - Installs Node.js
- Install dependencies - Runs
npm ci - Build - Runs
npm run build, creating thedist/folder - Deploy - Uploads
dist/to GitHub Pages
See GitHub Actions documentation for more details.
GitHub Pages serves static files from your repository. With the Actions workflow, it serves the built dist/ folder at:
https://<username>.github.io/<repository>/
See GitHub Pages documentation for more details.
- Go to your repository on GitHub
- Click Settings → Pages
- Under "Build and deployment", set Source to GitHub Actions
The next push to main will trigger deployment.
# Install dependencies
npm install
# Start development server with hot reload
npm run dev
# Build for production
npm run build
# Preview production build locally
npm run preview- Replace
main.jswith your WebXR code - Update
baseinvite.config.jsto your repository name - Update
nameanddescriptioninpackage.json
npm install <package-name>Common WebXR packages:
three- 3D rendering (Three.js docs)@react-three/fiber- React renderer for Three.jsaframe- Declarative WebXR framework (A-Frame docs)
WebXR requires a secure context:
- HTTPS (GitHub Pages provides this automatically)
- localhost (works for local development)
See the WebXR Device API documentation for browser support and features.
Ensure package-lock.json is committed:
npm install
git add package-lock.json
git commit -m "Add package-lock.json"
git pushCheck that base in vite.config.js matches your repository name exactly, including case.
- Ensure you're accessing via HTTPS (not HTTP)
- Check browser support at caniuse.com/webxr
- On desktop, install a WebXR emulator extension for testing
This demo uses the Node Package Manager (npm) to manage scripts and libraries like vite. This is a common way of managing projects even if they don't use NodeJS because npm is has a rich set of tools and is well documented. It is not a requirement and you there are many other ways to deploy code to GitHub.